rename healthz methodNames to be more consistent w/ present day usages

Kubernetes-commit: 2e23788fda86c68e7f17cf0b66ee1017594c1055
This commit is contained in:
Han Kang 2019-08-13 12:42:13 -07:00 committed by Kubernetes Publisher
parent 9d958e72a1
commit 2b0c93afef
7 changed files with 44 additions and 44 deletions

View File

@ -137,10 +137,10 @@ type Config struct {
// DiscoveryAddresses is used to build the IPs pass to discovery. If nil, the ExternalAddress is
// always reported
DiscoveryAddresses discovery.Addresses
// The default set of healthz checks. There might be more added via AddHealthzChecks dynamically.
HealthzChecks []healthz.HealthzChecker
// The default set of healthz checks. There might be more added via AddHealthChecks dynamically.
HealthzChecks []healthz.HealthChecker
// The default set of readyz-only checks. There might be more added via AddReadyzChecks dynamically.
ReadyzChecks []healthz.HealthzChecker
ReadyzChecks []healthz.HealthChecker
// LegacyAPIGroupPrefixes is used to set up URL parsing for authorization and for validating requests
// to InstallLegacyAPIGroup. New API servers don't generally have legacy groups at all.
LegacyAPIGroupPrefixes sets.String
@ -269,15 +269,15 @@ type AuthorizationInfo struct {
// NewConfig returns a Config struct with the default values
func NewConfig(codecs serializer.CodecFactory) *Config {
defaultHealthChecks := []healthz.HealthzChecker{healthz.PingHealthz, healthz.LogHealthz}
defaultHealthChecks := []healthz.HealthChecker{healthz.PingHealthz, healthz.LogHealthz}
return &Config{
Serializer: codecs,
BuildHandlerChainFunc: DefaultBuildHandlerChain,
HandlerChainWaitGroup: new(utilwaitgroup.SafeWaitGroup),
LegacyAPIGroupPrefixes: sets.NewString(DefaultLegacyAPIPrefix),
DisabledPostStartHooks: sets.NewString(),
HealthzChecks: append([]healthz.HealthzChecker{}, defaultHealthChecks...),
ReadyzChecks: append([]healthz.HealthzChecker{}, defaultHealthChecks...),
HealthzChecks: append([]healthz.HealthChecker{}, defaultHealthChecks...),
ReadyzChecks: append([]healthz.HealthChecker{}, defaultHealthChecks...),
EnableIndex: true,
EnableDiscovery: true,
EnableProfiling: true,

View File

@ -147,10 +147,10 @@ type GenericAPIServer struct {
// healthz checks
healthzLock sync.Mutex
healthzChecks []healthz.HealthzChecker
healthzChecks []healthz.HealthChecker
healthzChecksInstalled bool
readyzLock sync.Mutex
readyzChecks []healthz.HealthzChecker
readyzChecks []healthz.HealthChecker
readyzChecksInstalled bool
maxStartupSequenceDuration time.Duration
healthzClock clock.Clock
@ -203,7 +203,7 @@ type DelegationTarget interface {
PreShutdownHooks() map[string]preShutdownHookEntry
// HealthzChecks returns the healthz checks that need to be combined
HealthzChecks() []healthz.HealthzChecker
HealthzChecks() []healthz.HealthChecker
// ListedPaths returns the paths for supporting an index
ListedPaths() []string
@ -225,7 +225,7 @@ func (s *GenericAPIServer) PostStartHooks() map[string]postStartHookEntry {
func (s *GenericAPIServer) PreShutdownHooks() map[string]preShutdownHookEntry {
return s.preShutdownHooks
}
func (s *GenericAPIServer) HealthzChecks() []healthz.HealthzChecker {
func (s *GenericAPIServer) HealthzChecks() []healthz.HealthChecker {
return s.healthzChecks
}
func (s *GenericAPIServer) ListedPaths() []string {
@ -252,8 +252,8 @@ func (s emptyDelegate) PostStartHooks() map[string]postStartHookEntry {
func (s emptyDelegate) PreShutdownHooks() map[string]preShutdownHookEntry {
return map[string]preShutdownHookEntry{}
}
func (s emptyDelegate) HealthzChecks() []healthz.HealthzChecker {
return []healthz.HealthzChecker{}
func (s emptyDelegate) HealthzChecks() []healthz.HealthChecker {
return []healthz.HealthChecker{}
}
func (s emptyDelegate) ListedPaths() []string {
return []string{}

View File

@ -25,15 +25,15 @@ import (
"k8s.io/apiserver/pkg/server/healthz"
)
// AddHealthzCheck adds HealthzCheck(s) to both healthz and readyz. All healthz checks
// AddHealthChecks adds HealthzCheck(s) to both healthz and readyz. All healthz checks
// are automatically added to readyz, since we want to avoid the situation where the
// apiserver is ready but not live.
func (s *GenericAPIServer) AddHealthzChecks(checks ...healthz.HealthzChecker) error {
func (s *GenericAPIServer) AddHealthChecks(checks ...healthz.HealthChecker) error {
return s.AddDelayedHealthzChecks(0, checks...)
}
// AddReadyzChecks allows you to add a HealthzCheck to readyz.
func (s *GenericAPIServer) AddReadyzChecks(checks ...healthz.HealthzChecker) error {
func (s *GenericAPIServer) AddReadyzChecks(checks ...healthz.HealthChecker) error {
s.readyzLock.Lock()
defer s.readyzLock.Unlock()
return s.addReadyzChecks(checks...)
@ -41,7 +41,7 @@ func (s *GenericAPIServer) AddReadyzChecks(checks ...healthz.HealthzChecker) err
// addReadyzChecks allows you to add a HealthzCheck to readyz.
// premise: readyzLock has been obtained
func (s *GenericAPIServer) addReadyzChecks(checks ...healthz.HealthzChecker) error {
func (s *GenericAPIServer) addReadyzChecks(checks ...healthz.HealthChecker) error {
if s.readyzChecksInstalled {
return fmt.Errorf("unable to add because the readyz endpoint has already been created")
}
@ -94,7 +94,7 @@ func (c shutdownCheck) Check(req *http.Request) error {
// grace period has not yet elapsed. One may want to set a grace period in order to prevent
// the kubelet from restarting the kube-apiserver due to long-ish boot sequences. Readyz health
// checks have no grace period, since we want readyz to fail while boot has not completed.
func (s *GenericAPIServer) AddDelayedHealthzChecks(delay time.Duration, checks ...healthz.HealthzChecker) error {
func (s *GenericAPIServer) AddDelayedHealthzChecks(delay time.Duration, checks ...healthz.HealthChecker) error {
s.healthzLock.Lock()
defer s.healthzLock.Unlock()
if s.healthzChecksInstalled {
@ -110,7 +110,7 @@ func (s *GenericAPIServer) AddDelayedHealthzChecks(delay time.Duration, checks .
}
// delayedHealthCheck wraps a health check which will not fail until the explicitly defined delay has elapsed.
func delayedHealthCheck(check healthz.HealthzChecker, clock clock.Clock, delay time.Duration) healthz.HealthzChecker {
func delayedHealthCheck(check healthz.HealthChecker, clock clock.Clock, delay time.Duration) healthz.HealthChecker {
return delayedHealthzCheck{
check,
clock.Now().Add(delay),
@ -119,7 +119,7 @@ func delayedHealthCheck(check healthz.HealthzChecker, clock clock.Clock, delay t
}
type delayedHealthzCheck struct {
check healthz.HealthzChecker
check healthz.HealthChecker
startCheck time.Time
clock clock.Clock
}

View File

@ -31,14 +31,14 @@ import (
"k8s.io/klog"
)
// HealthzChecker is a named healthz checker.
type HealthzChecker interface {
// HealthChecker is a named healthz checker.
type HealthChecker interface {
Name() string
Check(req *http.Request) error
}
// PingHealthz returns true automatically when checked
var PingHealthz HealthzChecker = ping{}
var PingHealthz HealthChecker = ping{}
// ping implements the simplest possible healthz checker.
type ping struct{}
@ -53,7 +53,7 @@ func (ping) Check(_ *http.Request) error {
}
// LogHealthz returns true if logging is not blocked
var LogHealthz HealthzChecker = &log{}
var LogHealthz HealthChecker = &log{}
type log struct {
startOnce sync.Once
@ -81,7 +81,7 @@ func (l *log) Check(_ *http.Request) error {
}
// NamedCheck returns a healthz checker for the given name and function.
func NamedCheck(name string, check func(r *http.Request) error) HealthzChecker {
func NamedCheck(name string, check func(r *http.Request) error) HealthChecker {
return &healthzCheck{name, check}
}
@ -89,7 +89,7 @@ func NamedCheck(name string, check func(r *http.Request) error) HealthzChecker {
// "/healthz" to mux. *All handlers* for mux must be specified in
// exactly one call to InstallHandler. Calling InstallHandler more
// than once for the same mux will result in a panic.
func InstallHandler(mux mux, checks ...HealthzChecker) {
func InstallHandler(mux mux, checks ...HealthChecker) {
InstallPathHandler(mux, "/healthz", checks...)
}
@ -97,7 +97,7 @@ func InstallHandler(mux mux, checks ...HealthzChecker) {
// "/readyz" to mux. *All handlers* for mux must be specified in
// exactly one call to InstallHandler. Calling InstallHandler more
// than once for the same mux will result in a panic.
func InstallReadyzHandler(mux mux, checks ...HealthzChecker) {
func InstallReadyzHandler(mux mux, checks ...HealthChecker) {
InstallPathHandler(mux, "/readyz", checks...)
}
@ -106,13 +106,13 @@ func InstallReadyzHandler(mux mux, checks ...HealthzChecker) {
// specified in exactly one call to InstallPathHandler. Calling
// InstallPathHandler more than once for the same path and mux will
// result in a panic.
func InstallPathHandler(mux mux, path string, checks ...HealthzChecker) {
func InstallPathHandler(mux mux, path string, checks ...HealthChecker) {
if len(checks) == 0 {
klog.V(5).Info("No default health checks specified. Installing the ping handler.")
checks = []HealthzChecker{PingHealthz}
checks = []HealthChecker{PingHealthz}
}
klog.V(5).Info("Installing healthz checkers:", formatQuoted(checkerNames(checks...)...))
klog.V(5).Infof("Installing health checkers for (%v): %v", path, formatQuoted(checkerNames(checks...)...))
mux.Handle(path, handleRootHealthz(checks...))
for _, check := range checks {
@ -125,13 +125,13 @@ type mux interface {
Handle(pattern string, handler http.Handler)
}
// healthzCheck implements HealthzChecker on an arbitrary name and check function.
// healthzCheck implements HealthChecker on an arbitrary name and check function.
type healthzCheck struct {
name string
check func(r *http.Request) error
}
var _ HealthzChecker = &healthzCheck{}
var _ HealthChecker = &healthzCheck{}
func (c *healthzCheck) Name() string {
return c.name
@ -151,7 +151,7 @@ func getExcludedChecks(r *http.Request) sets.String {
}
// handleRootHealthz returns an http.HandlerFunc that serves the provided checks.
func handleRootHealthz(checks ...HealthzChecker) http.HandlerFunc {
func handleRootHealthz(checks ...HealthChecker) http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
failed := false
excluded := getExcludedChecks(r)
@ -210,7 +210,7 @@ func adaptCheckToHandler(c func(r *http.Request) error) http.HandlerFunc {
}
// checkerNames returns the names of the checks in the same order as passed in.
func checkerNames(checks ...HealthzChecker) []string {
func checkerNames(checks ...HealthChecker) []string {
// accumulate the names of checks for printing them out.
checkerNames := make([]string, 0, len(checks))
for _, check := range checks {

View File

@ -111,7 +111,7 @@ func testMultipleChecks(path string, t *testing.T) {
for i, test := range tests {
mux := http.NewServeMux()
checks := []HealthzChecker{PingHealthz}
checks := []HealthChecker{PingHealthz}
if test.addBadCheck {
checks = append(checks, NamedCheck("bad", func(_ *http.Request) error {
return errors.New("this will fail")
@ -158,14 +158,14 @@ func TestCheckerNames(t *testing.T) {
testCases := []struct {
desc string
have []HealthzChecker
have []HealthChecker
want []string
}{
{"no checker", []HealthzChecker{}, []string{}},
{"one checker", []HealthzChecker{c1}, []string{n1}},
{"other checker", []HealthzChecker{c2}, []string{n2}},
{"checker order", []HealthzChecker{c1, c2}, []string{n1, n2}},
{"different checker order", []HealthzChecker{c2, c1}, []string{n2, n1}},
{"no checker", []HealthChecker{}, []string{}},
{"one checker", []HealthChecker{c1}, []string{n1}},
{"other checker", []HealthChecker{c2}, []string{n2}},
{"checker order", []HealthChecker{c1, c2}, []string{n1, n2}},
{"different checker order", []HealthChecker{c2, c1}, []string{n2, n1}},
}
for _, tc := range testCases {

View File

@ -219,7 +219,7 @@ type postStartHookHealthz struct {
done chan struct{}
}
var _ healthz.HealthzChecker = postStartHookHealthz{}
var _ healthz.HealthChecker = postStartHookHealthz{}
func (h postStartHookHealthz) Name() string {
return h.name

View File

@ -62,20 +62,20 @@ type kmsPluginProbe struct {
l *sync.Mutex
}
func (h *kmsPluginProbe) toHealthzCheck(idx int) healthz.HealthzChecker {
func (h *kmsPluginProbe) toHealthzCheck(idx int) healthz.HealthChecker {
return healthz.NamedCheck(fmt.Sprintf("kms-provider-%d", idx), func(r *http.Request) error {
return h.Check()
})
}
// GetKMSPluginHealthzCheckers extracts KMSPluginProbes from the EncryptionConfig.
func GetKMSPluginHealthzCheckers(filepath string) ([]healthz.HealthzChecker, error) {
func GetKMSPluginHealthzCheckers(filepath string) ([]healthz.HealthChecker, error) {
f, err := os.Open(filepath)
if err != nil {
return nil, fmt.Errorf("error opening encryption provider configuration file %q: %v", filepath, err)
}
defer f.Close()
var result []healthz.HealthzChecker
var result []healthz.HealthChecker
probes, err := getKMSPluginProbes(f)
if err != nil {
return nil, err