mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Reduce and comment exports
This commit is contained in:
parent
7beac7a9af
commit
bca90f4866
@ -40,7 +40,7 @@ type HealthChecker interface {
|
|||||||
|
|
||||||
// NewHealthChecker creates a new HealthChecker which supports multiple types of liveness probes.
|
// NewHealthChecker creates a new HealthChecker which supports multiple types of liveness probes.
|
||||||
func NewHealthChecker() HealthChecker {
|
func NewHealthChecker() HealthChecker {
|
||||||
return &MuxHealthChecker{
|
return &muxHealthChecker{
|
||||||
checkers: map[string]HealthChecker{
|
checkers: map[string]HealthChecker{
|
||||||
"http": &HTTPHealthChecker{
|
"http": &HTTPHealthChecker{
|
||||||
client: &http.Client{},
|
client: &http.Client{},
|
||||||
@ -50,15 +50,15 @@ func NewHealthChecker() HealthChecker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MuxHealthChecker bundles multiple implementations of HealthChecker of different types.
|
// muxHealthChecker bundles multiple implementations of HealthChecker of different types.
|
||||||
type MuxHealthChecker struct {
|
type muxHealthChecker struct {
|
||||||
checkers map[string]HealthChecker
|
checkers map[string]HealthChecker
|
||||||
}
|
}
|
||||||
|
|
||||||
// HealthCheck delegates the health-checking of the container to one of the bundled implementations.
|
// HealthCheck delegates the health-checking of the container to one of the bundled implementations.
|
||||||
// It chooses an implementation according to container.LivenessProbe.Type.
|
// It chooses an implementation according to container.LivenessProbe.Type.
|
||||||
// If there is no matching health checker it returns Unknown, nil.
|
// If there is no matching health checker it returns Unknown, nil.
|
||||||
func (m *MuxHealthChecker) HealthCheck(currentState api.PodState, container api.Container) (Status, error) {
|
func (m *muxHealthChecker) HealthCheck(currentState api.PodState, container api.Container) (Status, error) {
|
||||||
checker, ok := m.checkers[container.LivenessProbe.Type]
|
checker, ok := m.checkers[container.LivenessProbe.Type]
|
||||||
if !ok || checker == nil {
|
if !ok || checker == nil {
|
||||||
glog.Warningf("Failed to find health checker for %s %s", container.Name, container.LivenessProbe.Type)
|
glog.Warningf("Failed to find health checker for %s %s", container.Name, container.LivenessProbe.Type)
|
||||||
|
@ -105,7 +105,7 @@ func TestMuxHealthChecker(t *testing.T) {
|
|||||||
{Healthy, "http"},
|
{Healthy, "http"},
|
||||||
{Unknown, "ftp"},
|
{Unknown, "ftp"},
|
||||||
}
|
}
|
||||||
mc := &MuxHealthChecker{
|
mc := &muxHealthChecker{
|
||||||
checkers: make(map[string]HealthChecker),
|
checkers: make(map[string]HealthChecker),
|
||||||
}
|
}
|
||||||
hc := &HTTPHealthChecker{
|
hc := &HTTPHealthChecker{
|
||||||
|
@ -27,6 +27,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// HTTPGetInterface is an abstract interface for testability. It abstracts the interface of http.Client.Get.
|
// HTTPGetInterface is an abstract interface for testability. It abstracts the interface of http.Client.Get.
|
||||||
|
// This is exported because some other packages may want to do direct HTTP checks.
|
||||||
type HTTPGetInterface interface {
|
type HTTPGetInterface interface {
|
||||||
Get(url string) (*http.Response, error)
|
Get(url string) (*http.Response, error)
|
||||||
}
|
}
|
||||||
@ -78,6 +79,7 @@ func formatURL(host string, port int, path string) string {
|
|||||||
// If the HTTP response code is successful (i.e. 400 > code >= 200), it returns Healthy.
|
// If the HTTP response code is successful (i.e. 400 > code >= 200), it returns Healthy.
|
||||||
// If the HTTP response code is unsuccessful, it returns Unhealthy.
|
// If the HTTP response code is unsuccessful, it returns Unhealthy.
|
||||||
// It returns Unknown and err if the HTTP communication itself fails.
|
// It returns Unknown and err if the HTTP communication itself fails.
|
||||||
|
// This is exported because some other packages may want to do direct HTTP checks.
|
||||||
func DoHTTPCheck(url string, client HTTPGetInterface) (Status, error) {
|
func DoHTTPCheck(url string, client HTTPGetInterface) (Status, error) {
|
||||||
res, err := client.Get(url)
|
res, err := client.Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -61,6 +61,7 @@ func getTCPAddrParts(currentState api.PodState, container api.Container) (string
|
|||||||
// DoTCPCheck checks that a TCP socket to the address can be opened.
|
// DoTCPCheck checks that a TCP socket to the address can be opened.
|
||||||
// If the socket can be opened, it returns Healthy.
|
// If the socket can be opened, it returns Healthy.
|
||||||
// If the socket fails to open, it returns Unhealthy.
|
// If the socket fails to open, it returns Unhealthy.
|
||||||
|
// This is exported because some other packages may want to do direct TCP checks.
|
||||||
func DoTCPCheck(addr string) (Status, error) {
|
func DoTCPCheck(addr string) (Status, error) {
|
||||||
conn, err := net.Dial("tcp", addr)
|
conn, err := net.Dial("tcp", addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user