mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
rename healthz methodNames to be more consistent w/ present day usages
This commit is contained in:
parent
f2c82f49e8
commit
2e23788fda
@ -139,8 +139,8 @@ func Run(c *cloudcontrollerconfig.CompletedConfig, stopCh <-chan struct{}) error
|
|||||||
klog.Errorf("unable to register configz: %v", err)
|
klog.Errorf("unable to register configz: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup any healthz checks we will want to use.
|
// Setup any health checks we will want to use.
|
||||||
var checks []healthz.HealthzChecker
|
var checks []healthz.HealthChecker
|
||||||
var electionChecker *leaderelection.HealthzAdaptor
|
var electionChecker *leaderelection.HealthzAdaptor
|
||||||
if c.ComponentConfig.Generic.LeaderElection.LeaderElect {
|
if c.ComponentConfig.Generic.LeaderElection.LeaderElect {
|
||||||
electionChecker = leaderelection.NewLeaderHealthzAdaptor(time.Second * 20)
|
electionChecker = leaderelection.NewLeaderHealthzAdaptor(time.Second * 20)
|
||||||
|
@ -52,7 +52,7 @@ func BuildHandlerChain(apiHandler http.Handler, authorizationInfo *apiserver.Aut
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewBaseHandler takes in CompletedConfig and returns a handler.
|
// 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")
|
mux := mux.NewPathRecorderMux("controller-manager")
|
||||||
healthz.InstallHandler(mux, checks...)
|
healthz.InstallHandler(mux, checks...)
|
||||||
if c.EnableProfiling {
|
if c.EnableProfiling {
|
||||||
|
@ -153,8 +153,8 @@ func createAggregatorServer(aggregatorConfig *aggregatorapiserver.Config, delega
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = aggregatorServer.GenericAPIServer.AddHealthzChecks(
|
err = aggregatorServer.GenericAPIServer.AddHealthChecks(
|
||||||
makeAPIServiceAvailableHealthzCheck(
|
makeAPIServiceAvailableHealthCheck(
|
||||||
"autoregister-completion",
|
"autoregister-completion",
|
||||||
apiServices,
|
apiServices,
|
||||||
aggregatorServer.APIRegistrationInformers.Apiregistration().V1().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.
|
// 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
|
// Track the auto-registered API services that have not been observed to be available yet
|
||||||
pendingServiceNamesLock := &sync.RWMutex{}
|
pendingServiceNamesLock := &sync.RWMutex{}
|
||||||
pendingServiceNames := sets.NewString()
|
pendingServiceNames := sets.NewString()
|
||||||
|
@ -47,7 +47,7 @@ type TestServerInstanceOptions struct {
|
|||||||
// DisableStorageCleanup Disable the automatic storage cleanup
|
// DisableStorageCleanup Disable the automatic storage cleanup
|
||||||
DisableStorageCleanup bool
|
DisableStorageCleanup bool
|
||||||
// Injected health
|
// Injected health
|
||||||
InjectedHealthzChecker healthz.HealthzChecker
|
InjectedHealthChecker healthz.HealthChecker
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestServer return values supplied by kube-test-ApiServer
|
// 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)
|
return result, fmt.Errorf("failed to create server chain: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if instanceOptions.InjectedHealthzChecker != nil {
|
if instanceOptions.InjectedHealthChecker != nil {
|
||||||
t.Logf("Adding health check with delay %v %v", s.GenericServerRunOptions.MaxStartupSequenceDuration, instanceOptions.InjectedHealthzChecker.Name())
|
t.Logf("Adding health check with delay %v %v", s.GenericServerRunOptions.MaxStartupSequenceDuration, instanceOptions.InjectedHealthChecker.Name())
|
||||||
if err := server.GenericAPIServer.AddDelayedHealthzChecks(s.GenericServerRunOptions.MaxStartupSequenceDuration, instanceOptions.InjectedHealthzChecker); err != nil {
|
if err := server.GenericAPIServer.AddDelayedHealthzChecks(s.GenericServerRunOptions.MaxStartupSequenceDuration, instanceOptions.InjectedHealthChecker); err != nil {
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,7 +170,7 @@ func Run(c *config.CompletedConfig, stopCh <-chan struct{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Setup any healthz checks we will want to use.
|
// Setup any healthz checks we will want to use.
|
||||||
var checks []healthz.HealthzChecker
|
var checks []healthz.HealthChecker
|
||||||
var electionChecker *leaderelection.HealthzAdaptor
|
var electionChecker *leaderelection.HealthzAdaptor
|
||||||
if c.ComponentConfig.Generic.LeaderElection.LeaderElect {
|
if c.ComponentConfig.Generic.LeaderElection.LeaderElect {
|
||||||
electionChecker = leaderelection.NewLeaderHealthzAdaptor(time.Second * 20)
|
electionChecker = leaderelection.NewLeaderHealthzAdaptor(time.Second * 20)
|
||||||
|
@ -205,7 +205,7 @@ func Run(cc schedulerserverconfig.CompletedConfig, stopCh <-chan struct{}, regis
|
|||||||
cc.LeaderElectionBroadcaster.StartRecordingToSink(&corev1.EventSinkImpl{Interface: cc.CoreEventClient.Events("")})
|
cc.LeaderElectionBroadcaster.StartRecordingToSink(&corev1.EventSinkImpl{Interface: cc.CoreEventClient.Events("")})
|
||||||
}
|
}
|
||||||
// Setup healthz checks.
|
// Setup healthz checks.
|
||||||
var checks []healthz.HealthzChecker
|
var checks []healthz.HealthChecker
|
||||||
if cc.ComponentConfig.LeaderElection.LeaderElect {
|
if cc.ComponentConfig.LeaderElection.LeaderElect {
|
||||||
checks = append(checks, cc.LeaderElection.WatchDog)
|
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
|
// newHealthzHandler creates a healthz server from the config, and will also
|
||||||
// embed the metrics handler if the healthz and metrics address configurations
|
// embed the metrics handler if the healthz and metrics address configurations
|
||||||
// are the same.
|
// 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")
|
pathRecorderMux := mux.NewPathRecorderMux("kube-scheduler")
|
||||||
healthz.InstallHandler(pathRecorderMux, checks...)
|
healthz.InstallHandler(pathRecorderMux, checks...)
|
||||||
if !separateMetrics {
|
if !separateMetrics {
|
||||||
|
@ -391,7 +391,7 @@ func (m *Master) InstallLegacyAPI(c *completedConfig, restOptionsGetter generic.
|
|||||||
|
|
||||||
func (m *Master) installTunneler(nodeTunneler tunneler.Tunneler, nodeClient corev1client.NodeInterface) {
|
func (m *Master) installTunneler(nodeTunneler tunneler.Tunneler, nodeClient corev1client.NodeInterface) {
|
||||||
nodeTunneler.Run(nodeAddressProvider{nodeClient}.externalAddresses)
|
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{
|
prometheus.NewGaugeFunc(prometheus.GaugeOpts{
|
||||||
Name: "apiserver_proxy_tunnel_sync_duration_seconds",
|
Name: "apiserver_proxy_tunnel_sync_duration_seconds",
|
||||||
Help: "The time since the last successful synchronization of the SSH tunnels for proxy requests.",
|
Help: "The time since the last successful synchronization of the SSH tunnels for proxy requests.",
|
||||||
|
@ -137,10 +137,10 @@ type Config struct {
|
|||||||
// DiscoveryAddresses is used to build the IPs pass to discovery. If nil, the ExternalAddress is
|
// DiscoveryAddresses is used to build the IPs pass to discovery. If nil, the ExternalAddress is
|
||||||
// always reported
|
// always reported
|
||||||
DiscoveryAddresses discovery.Addresses
|
DiscoveryAddresses discovery.Addresses
|
||||||
// The default set of healthz checks. There might be more added via AddHealthzChecks dynamically.
|
// The default set of healthz checks. There might be more added via AddHealthChecks dynamically.
|
||||||
HealthzChecks []healthz.HealthzChecker
|
HealthzChecks []healthz.HealthChecker
|
||||||
// The default set of readyz-only checks. There might be more added via AddReadyzChecks dynamically.
|
// 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
|
// 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.
|
// to InstallLegacyAPIGroup. New API servers don't generally have legacy groups at all.
|
||||||
LegacyAPIGroupPrefixes sets.String
|
LegacyAPIGroupPrefixes sets.String
|
||||||
@ -269,15 +269,15 @@ type AuthorizationInfo struct {
|
|||||||
|
|
||||||
// NewConfig returns a Config struct with the default values
|
// NewConfig returns a Config struct with the default values
|
||||||
func NewConfig(codecs serializer.CodecFactory) *Config {
|
func NewConfig(codecs serializer.CodecFactory) *Config {
|
||||||
defaultHealthChecks := []healthz.HealthzChecker{healthz.PingHealthz, healthz.LogHealthz}
|
defaultHealthChecks := []healthz.HealthChecker{healthz.PingHealthz, healthz.LogHealthz}
|
||||||
return &Config{
|
return &Config{
|
||||||
Serializer: codecs,
|
Serializer: codecs,
|
||||||
BuildHandlerChainFunc: DefaultBuildHandlerChain,
|
BuildHandlerChainFunc: DefaultBuildHandlerChain,
|
||||||
HandlerChainWaitGroup: new(utilwaitgroup.SafeWaitGroup),
|
HandlerChainWaitGroup: new(utilwaitgroup.SafeWaitGroup),
|
||||||
LegacyAPIGroupPrefixes: sets.NewString(DefaultLegacyAPIPrefix),
|
LegacyAPIGroupPrefixes: sets.NewString(DefaultLegacyAPIPrefix),
|
||||||
DisabledPostStartHooks: sets.NewString(),
|
DisabledPostStartHooks: sets.NewString(),
|
||||||
HealthzChecks: append([]healthz.HealthzChecker{}, defaultHealthChecks...),
|
HealthzChecks: append([]healthz.HealthChecker{}, defaultHealthChecks...),
|
||||||
ReadyzChecks: append([]healthz.HealthzChecker{}, defaultHealthChecks...),
|
ReadyzChecks: append([]healthz.HealthChecker{}, defaultHealthChecks...),
|
||||||
EnableIndex: true,
|
EnableIndex: true,
|
||||||
EnableDiscovery: true,
|
EnableDiscovery: true,
|
||||||
EnableProfiling: true,
|
EnableProfiling: true,
|
||||||
|
@ -147,10 +147,10 @@ type GenericAPIServer struct {
|
|||||||
|
|
||||||
// healthz checks
|
// healthz checks
|
||||||
healthzLock sync.Mutex
|
healthzLock sync.Mutex
|
||||||
healthzChecks []healthz.HealthzChecker
|
healthzChecks []healthz.HealthChecker
|
||||||
healthzChecksInstalled bool
|
healthzChecksInstalled bool
|
||||||
readyzLock sync.Mutex
|
readyzLock sync.Mutex
|
||||||
readyzChecks []healthz.HealthzChecker
|
readyzChecks []healthz.HealthChecker
|
||||||
readyzChecksInstalled bool
|
readyzChecksInstalled bool
|
||||||
maxStartupSequenceDuration time.Duration
|
maxStartupSequenceDuration time.Duration
|
||||||
healthzClock clock.Clock
|
healthzClock clock.Clock
|
||||||
@ -203,7 +203,7 @@ type DelegationTarget interface {
|
|||||||
PreShutdownHooks() map[string]preShutdownHookEntry
|
PreShutdownHooks() map[string]preShutdownHookEntry
|
||||||
|
|
||||||
// HealthzChecks returns the healthz checks that need to be combined
|
// 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 returns the paths for supporting an index
|
||||||
ListedPaths() []string
|
ListedPaths() []string
|
||||||
@ -225,7 +225,7 @@ func (s *GenericAPIServer) PostStartHooks() map[string]postStartHookEntry {
|
|||||||
func (s *GenericAPIServer) PreShutdownHooks() map[string]preShutdownHookEntry {
|
func (s *GenericAPIServer) PreShutdownHooks() map[string]preShutdownHookEntry {
|
||||||
return s.preShutdownHooks
|
return s.preShutdownHooks
|
||||||
}
|
}
|
||||||
func (s *GenericAPIServer) HealthzChecks() []healthz.HealthzChecker {
|
func (s *GenericAPIServer) HealthzChecks() []healthz.HealthChecker {
|
||||||
return s.healthzChecks
|
return s.healthzChecks
|
||||||
}
|
}
|
||||||
func (s *GenericAPIServer) ListedPaths() []string {
|
func (s *GenericAPIServer) ListedPaths() []string {
|
||||||
@ -252,8 +252,8 @@ func (s emptyDelegate) PostStartHooks() map[string]postStartHookEntry {
|
|||||||
func (s emptyDelegate) PreShutdownHooks() map[string]preShutdownHookEntry {
|
func (s emptyDelegate) PreShutdownHooks() map[string]preShutdownHookEntry {
|
||||||
return map[string]preShutdownHookEntry{}
|
return map[string]preShutdownHookEntry{}
|
||||||
}
|
}
|
||||||
func (s emptyDelegate) HealthzChecks() []healthz.HealthzChecker {
|
func (s emptyDelegate) HealthzChecks() []healthz.HealthChecker {
|
||||||
return []healthz.HealthzChecker{}
|
return []healthz.HealthChecker{}
|
||||||
}
|
}
|
||||||
func (s emptyDelegate) ListedPaths() []string {
|
func (s emptyDelegate) ListedPaths() []string {
|
||||||
return []string{}
|
return []string{}
|
||||||
|
@ -25,15 +25,15 @@ import (
|
|||||||
"k8s.io/apiserver/pkg/server/healthz"
|
"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
|
// are automatically added to readyz, since we want to avoid the situation where the
|
||||||
// apiserver is ready but not live.
|
// 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...)
|
return s.AddDelayedHealthzChecks(0, checks...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddReadyzChecks allows you to add a HealthzCheck to readyz.
|
// 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()
|
s.readyzLock.Lock()
|
||||||
defer s.readyzLock.Unlock()
|
defer s.readyzLock.Unlock()
|
||||||
return s.addReadyzChecks(checks...)
|
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.
|
// addReadyzChecks allows you to add a HealthzCheck to readyz.
|
||||||
// premise: readyzLock has been obtained
|
// premise: readyzLock has been obtained
|
||||||
func (s *GenericAPIServer) addReadyzChecks(checks ...healthz.HealthzChecker) error {
|
func (s *GenericAPIServer) addReadyzChecks(checks ...healthz.HealthChecker) error {
|
||||||
if s.readyzChecksInstalled {
|
if s.readyzChecksInstalled {
|
||||||
return fmt.Errorf("unable to add because the readyz endpoint has already been created")
|
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
|
// 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
|
// 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.
|
// 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()
|
s.healthzLock.Lock()
|
||||||
defer s.healthzLock.Unlock()
|
defer s.healthzLock.Unlock()
|
||||||
if s.healthzChecksInstalled {
|
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.
|
// 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{
|
return delayedHealthzCheck{
|
||||||
check,
|
check,
|
||||||
clock.Now().Add(delay),
|
clock.Now().Add(delay),
|
||||||
@ -119,7 +119,7 @@ func delayedHealthCheck(check healthz.HealthzChecker, clock clock.Clock, delay t
|
|||||||
}
|
}
|
||||||
|
|
||||||
type delayedHealthzCheck struct {
|
type delayedHealthzCheck struct {
|
||||||
check healthz.HealthzChecker
|
check healthz.HealthChecker
|
||||||
startCheck time.Time
|
startCheck time.Time
|
||||||
clock clock.Clock
|
clock clock.Clock
|
||||||
}
|
}
|
||||||
|
@ -31,14 +31,14 @@ import (
|
|||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HealthzChecker is a named healthz checker.
|
// HealthChecker is a named healthz checker.
|
||||||
type HealthzChecker interface {
|
type HealthChecker interface {
|
||||||
Name() string
|
Name() string
|
||||||
Check(req *http.Request) error
|
Check(req *http.Request) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// PingHealthz returns true automatically when checked
|
// PingHealthz returns true automatically when checked
|
||||||
var PingHealthz HealthzChecker = ping{}
|
var PingHealthz HealthChecker = ping{}
|
||||||
|
|
||||||
// ping implements the simplest possible healthz checker.
|
// ping implements the simplest possible healthz checker.
|
||||||
type ping struct{}
|
type ping struct{}
|
||||||
@ -53,7 +53,7 @@ func (ping) Check(_ *http.Request) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// LogHealthz returns true if logging is not blocked
|
// LogHealthz returns true if logging is not blocked
|
||||||
var LogHealthz HealthzChecker = &log{}
|
var LogHealthz HealthChecker = &log{}
|
||||||
|
|
||||||
type log struct {
|
type log struct {
|
||||||
startOnce sync.Once
|
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.
|
// 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}
|
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
|
// "/healthz" to mux. *All handlers* for mux must be specified in
|
||||||
// exactly one call to InstallHandler. Calling InstallHandler more
|
// exactly one call to InstallHandler. Calling InstallHandler more
|
||||||
// than once for the same mux will result in a panic.
|
// 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...)
|
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
|
// "/readyz" to mux. *All handlers* for mux must be specified in
|
||||||
// exactly one call to InstallHandler. Calling InstallHandler more
|
// exactly one call to InstallHandler. Calling InstallHandler more
|
||||||
// than once for the same mux will result in a panic.
|
// 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...)
|
InstallPathHandler(mux, "/readyz", checks...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,13 +106,13 @@ func InstallReadyzHandler(mux mux, checks ...HealthzChecker) {
|
|||||||
// specified in exactly one call to InstallPathHandler. Calling
|
// specified in exactly one call to InstallPathHandler. Calling
|
||||||
// InstallPathHandler more than once for the same path and mux will
|
// InstallPathHandler more than once for the same path and mux will
|
||||||
// result in a panic.
|
// result in a panic.
|
||||||
func InstallPathHandler(mux mux, path string, checks ...HealthzChecker) {
|
func InstallPathHandler(mux mux, path string, checks ...HealthChecker) {
|
||||||
if len(checks) == 0 {
|
if len(checks) == 0 {
|
||||||
klog.V(5).Info("No default health checks specified. Installing the ping handler.")
|
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...))
|
mux.Handle(path, handleRootHealthz(checks...))
|
||||||
for _, check := range checks {
|
for _, check := range checks {
|
||||||
@ -125,13 +125,13 @@ type mux interface {
|
|||||||
Handle(pattern string, handler http.Handler)
|
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 {
|
type healthzCheck struct {
|
||||||
name string
|
name string
|
||||||
check func(r *http.Request) error
|
check func(r *http.Request) error
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ HealthzChecker = &healthzCheck{}
|
var _ HealthChecker = &healthzCheck{}
|
||||||
|
|
||||||
func (c *healthzCheck) Name() string {
|
func (c *healthzCheck) Name() string {
|
||||||
return c.name
|
return c.name
|
||||||
@ -151,7 +151,7 @@ func getExcludedChecks(r *http.Request) sets.String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// handleRootHealthz returns an http.HandlerFunc that serves the provided checks.
|
// 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) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
failed := false
|
failed := false
|
||||||
excluded := getExcludedChecks(r)
|
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.
|
// 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.
|
// accumulate the names of checks for printing them out.
|
||||||
checkerNames := make([]string, 0, len(checks))
|
checkerNames := make([]string, 0, len(checks))
|
||||||
for _, check := range checks {
|
for _, check := range checks {
|
||||||
|
@ -111,7 +111,7 @@ func testMultipleChecks(path string, t *testing.T) {
|
|||||||
|
|
||||||
for i, test := range tests {
|
for i, test := range tests {
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
checks := []HealthzChecker{PingHealthz}
|
checks := []HealthChecker{PingHealthz}
|
||||||
if test.addBadCheck {
|
if test.addBadCheck {
|
||||||
checks = append(checks, NamedCheck("bad", func(_ *http.Request) error {
|
checks = append(checks, NamedCheck("bad", func(_ *http.Request) error {
|
||||||
return errors.New("this will fail")
|
return errors.New("this will fail")
|
||||||
@ -158,14 +158,14 @@ func TestCheckerNames(t *testing.T) {
|
|||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
have []HealthzChecker
|
have []HealthChecker
|
||||||
want []string
|
want []string
|
||||||
}{
|
}{
|
||||||
{"no checker", []HealthzChecker{}, []string{}},
|
{"no checker", []HealthChecker{}, []string{}},
|
||||||
{"one checker", []HealthzChecker{c1}, []string{n1}},
|
{"one checker", []HealthChecker{c1}, []string{n1}},
|
||||||
{"other checker", []HealthzChecker{c2}, []string{n2}},
|
{"other checker", []HealthChecker{c2}, []string{n2}},
|
||||||
{"checker order", []HealthzChecker{c1, c2}, []string{n1, n2}},
|
{"checker order", []HealthChecker{c1, c2}, []string{n1, n2}},
|
||||||
{"different checker order", []HealthzChecker{c2, c1}, []string{n2, n1}},
|
{"different checker order", []HealthChecker{c2, c1}, []string{n2, n1}},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
|
@ -219,7 +219,7 @@ type postStartHookHealthz struct {
|
|||||||
done chan struct{}
|
done chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ healthz.HealthzChecker = postStartHookHealthz{}
|
var _ healthz.HealthChecker = postStartHookHealthz{}
|
||||||
|
|
||||||
func (h postStartHookHealthz) Name() string {
|
func (h postStartHookHealthz) Name() string {
|
||||||
return h.name
|
return h.name
|
||||||
|
@ -62,20 +62,20 @@ type kmsPluginProbe struct {
|
|||||||
l *sync.Mutex
|
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 healthz.NamedCheck(fmt.Sprintf("kms-provider-%d", idx), func(r *http.Request) error {
|
||||||
return h.Check()
|
return h.Check()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetKMSPluginHealthzCheckers extracts KMSPluginProbes from the EncryptionConfig.
|
// 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)
|
f, err := os.Open(filepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error opening encryption provider configuration file %q: %v", filepath, err)
|
return nil, fmt.Errorf("error opening encryption provider configuration file %q: %v", filepath, err)
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
var result []healthz.HealthzChecker
|
var result []healthz.HealthChecker
|
||||||
probes, err := getKMSPluginProbes(f)
|
probes, err := getKMSPluginProbes(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -96,7 +96,7 @@ func endpointReturnsStatusOK(client *kubernetes.Clientset, path string) bool {
|
|||||||
func TestStartupSequenceHealthzAndReadyz(t *testing.T) {
|
func TestStartupSequenceHealthzAndReadyz(t *testing.T) {
|
||||||
hc := &delayedCheck{}
|
hc := &delayedCheck{}
|
||||||
instanceOptions := &kubeapiservertesting.TestServerInstanceOptions{
|
instanceOptions := &kubeapiservertesting.TestServerInstanceOptions{
|
||||||
InjectedHealthzChecker: hc,
|
InjectedHealthChecker: hc,
|
||||||
}
|
}
|
||||||
server := kubeapiservertesting.StartTestServerOrDie(t, instanceOptions, []string{"--maximum-startup-sequence-duration", "15s"}, framework.SharedEtcd())
|
server := kubeapiservertesting.StartTestServerOrDie(t, instanceOptions, []string{"--maximum-startup-sequence-duration", "15s"}, framework.SharedEtcd())
|
||||||
defer server.TearDownFn()
|
defer server.TearDownFn()
|
||||||
|
Loading…
Reference in New Issue
Block a user