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

This commit is contained in:
Han Kang 2019-08-13 12:42:13 -07:00
parent f2c82f49e8
commit 2e23788fda
15 changed files with 60 additions and 60 deletions

View File

@ -139,8 +139,8 @@ func Run(c *cloudcontrollerconfig.CompletedConfig, stopCh <-chan struct{}) error
klog.Errorf("unable to register configz: %v", err)
}
// Setup any healthz checks we will want to use.
var checks []healthz.HealthzChecker
// Setup any health checks we will want to use.
var checks []healthz.HealthChecker
var electionChecker *leaderelection.HealthzAdaptor
if c.ComponentConfig.Generic.LeaderElection.LeaderElect {
electionChecker = leaderelection.NewLeaderHealthzAdaptor(time.Second * 20)

View File

@ -52,7 +52,7 @@ func BuildHandlerChain(apiHandler http.Handler, authorizationInfo *apiserver.Aut
}
// NewBaseHandler takes in CompletedConfig and returns a handler.
func NewBaseHandler(c *componentbaseconfig.DebuggingConfiguration, checks ...healthz.HealthzChecker) *mux.PathRecorderMux {
func NewBaseHandler(c *componentbaseconfig.DebuggingConfiguration, checks ...healthz.HealthChecker) *mux.PathRecorderMux {
mux := mux.NewPathRecorderMux("controller-manager")
healthz.InstallHandler(mux, checks...)
if c.EnableProfiling {

View File

@ -153,8 +153,8 @@ func createAggregatorServer(aggregatorConfig *aggregatorapiserver.Config, delega
return nil, err
}
err = aggregatorServer.GenericAPIServer.AddHealthzChecks(
makeAPIServiceAvailableHealthzCheck(
err = aggregatorServer.GenericAPIServer.AddHealthChecks(
makeAPIServiceAvailableHealthCheck(
"autoregister-completion",
apiServices,
aggregatorServer.APIRegistrationInformers.Apiregistration().V1().APIServices(),
@ -186,9 +186,9 @@ func makeAPIService(gv schema.GroupVersion) *v1.APIService {
}
}
// makeAPIServiceAvailableHealthzCheck returns a healthz check that returns healthy
// makeAPIServiceAvailableHealthCheck returns a healthz check that returns healthy
// once all of the specified services have been observed to be available at least once.
func makeAPIServiceAvailableHealthzCheck(name string, apiServices []*v1.APIService, apiServiceInformer informers.APIServiceInformer) healthz.HealthzChecker {
func makeAPIServiceAvailableHealthCheck(name string, apiServices []*v1.APIService, apiServiceInformer informers.APIServiceInformer) healthz.HealthChecker {
// Track the auto-registered API services that have not been observed to be available yet
pendingServiceNamesLock := &sync.RWMutex{}
pendingServiceNames := sets.NewString()

View File

@ -47,7 +47,7 @@ type TestServerInstanceOptions struct {
// DisableStorageCleanup Disable the automatic storage cleanup
DisableStorageCleanup bool
// Injected health
InjectedHealthzChecker healthz.HealthzChecker
InjectedHealthChecker healthz.HealthChecker
}
// TestServer return values supplied by kube-test-ApiServer
@ -151,9 +151,9 @@ func StartTestServer(t Logger, instanceOptions *TestServerInstanceOptions, custo
return result, fmt.Errorf("failed to create server chain: %v", err)
}
if instanceOptions.InjectedHealthzChecker != nil {
t.Logf("Adding health check with delay %v %v", s.GenericServerRunOptions.MaxStartupSequenceDuration, instanceOptions.InjectedHealthzChecker.Name())
if err := server.GenericAPIServer.AddDelayedHealthzChecks(s.GenericServerRunOptions.MaxStartupSequenceDuration, instanceOptions.InjectedHealthzChecker); err != nil {
if instanceOptions.InjectedHealthChecker != nil {
t.Logf("Adding health check with delay %v %v", s.GenericServerRunOptions.MaxStartupSequenceDuration, instanceOptions.InjectedHealthChecker.Name())
if err := server.GenericAPIServer.AddDelayedHealthzChecks(s.GenericServerRunOptions.MaxStartupSequenceDuration, instanceOptions.InjectedHealthChecker); err != nil {
return result, err
}
}

View File

@ -170,7 +170,7 @@ func Run(c *config.CompletedConfig, stopCh <-chan struct{}) error {
}
// Setup any healthz checks we will want to use.
var checks []healthz.HealthzChecker
var checks []healthz.HealthChecker
var electionChecker *leaderelection.HealthzAdaptor
if c.ComponentConfig.Generic.LeaderElection.LeaderElect {
electionChecker = leaderelection.NewLeaderHealthzAdaptor(time.Second * 20)

View File

@ -205,7 +205,7 @@ func Run(cc schedulerserverconfig.CompletedConfig, stopCh <-chan struct{}, regis
cc.LeaderElectionBroadcaster.StartRecordingToSink(&corev1.EventSinkImpl{Interface: cc.CoreEventClient.Events("")})
}
// Setup healthz checks.
var checks []healthz.HealthzChecker
var checks []healthz.HealthChecker
if cc.ComponentConfig.LeaderElection.LeaderElect {
checks = append(checks, cc.LeaderElection.WatchDog)
}
@ -322,7 +322,7 @@ func newMetricsHandler(config *kubeschedulerconfig.KubeSchedulerConfiguration) h
// newHealthzHandler creates a healthz server from the config, and will also
// embed the metrics handler if the healthz and metrics address configurations
// are the same.
func newHealthzHandler(config *kubeschedulerconfig.KubeSchedulerConfiguration, separateMetrics bool, checks ...healthz.HealthzChecker) http.Handler {
func newHealthzHandler(config *kubeschedulerconfig.KubeSchedulerConfiguration, separateMetrics bool, checks ...healthz.HealthChecker) http.Handler {
pathRecorderMux := mux.NewPathRecorderMux("kube-scheduler")
healthz.InstallHandler(pathRecorderMux, checks...)
if !separateMetrics {

View File

@ -391,7 +391,7 @@ func (m *Master) InstallLegacyAPI(c *completedConfig, restOptionsGetter generic.
func (m *Master) installTunneler(nodeTunneler tunneler.Tunneler, nodeClient corev1client.NodeInterface) {
nodeTunneler.Run(nodeAddressProvider{nodeClient}.externalAddresses)
m.GenericAPIServer.AddHealthzChecks(healthz.NamedCheck("SSH Tunnel Check", tunneler.TunnelSyncHealthChecker(nodeTunneler)))
m.GenericAPIServer.AddHealthChecks(healthz.NamedCheck("SSH Tunnel Check", tunneler.TunnelSyncHealthChecker(nodeTunneler)))
prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Name: "apiserver_proxy_tunnel_sync_duration_seconds",
Help: "The time since the last successful synchronization of the SSH tunnels for proxy requests.",

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

View File

@ -96,7 +96,7 @@ func endpointReturnsStatusOK(client *kubernetes.Clientset, path string) bool {
func TestStartupSequenceHealthzAndReadyz(t *testing.T) {
hc := &delayedCheck{}
instanceOptions := &kubeapiservertesting.TestServerInstanceOptions{
InjectedHealthzChecker: hc,
InjectedHealthChecker: hc,
}
server := kubeapiservertesting.StartTestServerOrDie(t, instanceOptions, []string{"--maximum-startup-sequence-duration", "15s"}, framework.SharedEtcd())
defer server.TearDownFn()