mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 18:43:34 +00:00
vendor files
This commit is contained in:
38
vendor/k8s.io/kubernetes/pkg/probe/tcp/BUILD
generated
vendored
Normal file
38
vendor/k8s.io/kubernetes/pkg/probe/tcp/BUILD
generated
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
"go_test",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["tcp.go"],
|
||||
importpath = "k8s.io/kubernetes/pkg/probe/tcp",
|
||||
deps = [
|
||||
"//pkg/probe:go_default_library",
|
||||
"//vendor/github.com/golang/glog:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["tcp_test.go"],
|
||||
importpath = "k8s.io/kubernetes/pkg/probe/tcp",
|
||||
library = ":go_default_library",
|
||||
deps = ["//pkg/probe:go_default_library"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
58
vendor/k8s.io/kubernetes/pkg/probe/tcp/tcp.go
generated
vendored
Normal file
58
vendor/k8s.io/kubernetes/pkg/probe/tcp/tcp.go
generated
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package tcp
|
||||
|
||||
import (
|
||||
"net"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"k8s.io/kubernetes/pkg/probe"
|
||||
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
func New() TCPProber {
|
||||
return tcpProber{}
|
||||
}
|
||||
|
||||
type TCPProber interface {
|
||||
Probe(host string, port int, timeout time.Duration) (probe.Result, string, error)
|
||||
}
|
||||
|
||||
type tcpProber struct{}
|
||||
|
||||
func (pr tcpProber) Probe(host string, port int, timeout time.Duration) (probe.Result, string, error) {
|
||||
return DoTCPProbe(net.JoinHostPort(host, strconv.Itoa(port)), timeout)
|
||||
}
|
||||
|
||||
// DoTCPProbe checks that a TCP socket to the address can be opened.
|
||||
// If the socket can be opened, it returns Success
|
||||
// If the socket fails to open, it returns Failure.
|
||||
// This is exported because some other packages may want to do direct TCP probes.
|
||||
func DoTCPProbe(addr string, timeout time.Duration) (probe.Result, string, error) {
|
||||
conn, err := net.DialTimeout("tcp", addr, timeout)
|
||||
if err != nil {
|
||||
// Convert errors to failures to handle timeouts.
|
||||
return probe.Failure, err.Error(), nil
|
||||
}
|
||||
err = conn.Close()
|
||||
if err != nil {
|
||||
glog.Errorf("Unexpected error closing TCP probe socket: %v (%#v)", err, err)
|
||||
}
|
||||
return probe.Success, "", nil
|
||||
}
|
68
vendor/k8s.io/kubernetes/pkg/probe/tcp/tcp_test.go
generated
vendored
Normal file
68
vendor/k8s.io/kubernetes/pkg/probe/tcp/tcp_test.go
generated
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package tcp
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"k8s.io/kubernetes/pkg/probe"
|
||||
)
|
||||
|
||||
func TestTcpHealthChecker(t *testing.T) {
|
||||
// Setup a test server that responds to probing correctly
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}))
|
||||
defer server.Close()
|
||||
tHost, tPortStr, err := net.SplitHostPort(server.Listener.Addr().String())
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
tPort, err := strconv.Atoi(tPortStr)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
host string
|
||||
port int
|
||||
|
||||
expectedStatus probe.Result
|
||||
expectedError error
|
||||
}{
|
||||
// A connection is made and probing would succeed
|
||||
{tHost, tPort, probe.Success, nil},
|
||||
// No connection can be made and probing would fail
|
||||
{tHost, -1, probe.Failure, nil},
|
||||
}
|
||||
|
||||
prober := New()
|
||||
for i, tt := range tests {
|
||||
status, _, err := prober.Probe(tt.host, tt.port, 1*time.Second)
|
||||
if status != tt.expectedStatus {
|
||||
t.Errorf("#%d: expected status=%v, get=%v", i, tt.expectedStatus, status)
|
||||
}
|
||||
if err != tt.expectedError {
|
||||
t.Errorf("#%d: expected error=%v, get=%v", i, tt.expectedError, err)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user