Skip to content

Commit

Permalink
feat(general): support disable healthz check
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzzhhb committed Mar 8, 2024
1 parent d44805f commit f9ab27a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
10 changes: 8 additions & 2 deletions cmd/base/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func NewGenericContext(

// add profiling and health check http paths listening on generic endpoint
serveProfilingHTTP(mux)
c.serveHealthZHTTP(mux)
c.serveHealthZHTTP(mux, genericConf.EnableHealthzCheck)

return c, nil
}
Expand Down Expand Up @@ -264,8 +264,14 @@ func (c *GenericContext) StartInformer(ctx context.Context) {
}

// serveHealthZHTTP is used to provide health check for current running components.
func (c *GenericContext) serveHealthZHTTP(mux *http.ServeMux) {
func (c *GenericContext) serveHealthZHTTP(mux *http.ServeMux, enableHealthzCheck bool) {
mux.HandleFunc(healthZPath, func(w http.ResponseWriter, r *http.Request) {
if !enableHealthzCheck {
w.WriteHeader(200)
_, _ = w.Write([]byte("healthz check is disabled"))
return
}

ok, content := c.healthChecker.CheckHealthy()
if ok {
w.WriteHeader(200)
Expand Down
6 changes: 5 additions & 1 deletion cmd/base/options/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import (

// GenericOptions holds the configurations for multi components.
type GenericOptions struct {
DryRun bool
DryRun bool
EnableHealthzCheck bool

MasterURL string
KubeConfig string
Expand All @@ -53,6 +54,7 @@ type GenericOptions struct {
func NewGenericOptions() *GenericOptions {
return &GenericOptions{
DryRun: false,
EnableHealthzCheck: false,
TransformedInformerForPod: false,
GenericEndpoint: ":9316",
qosOptions: NewQoSOptions(),
Expand All @@ -75,6 +77,7 @@ func (o *GenericOptions) AddFlags(fss *cliflag.NamedFlagSets) {
})

fs.BoolVar(&o.DryRun, "dry-run", o.DryRun, "A bool to enable and disable dry-run.")
fs.BoolVar(&o.EnableHealthzCheck, "enable-healthz-check", o.EnableHealthzCheck, "A bool to enable and disable healthz check.")

fs.BoolVar(&o.TransformedInformerForPod, "transformed-informer-pod", o.TransformedInformerForPod,
"whether we should enable the ability of transformed informer for pods")
Expand All @@ -100,6 +103,7 @@ func (o *GenericOptions) AddFlags(fss *cliflag.NamedFlagSets) {
// ApplyTo fills up config with options
func (o *GenericOptions) ApplyTo(c *generic.GenericConfiguration) error {
c.DryRun = o.DryRun
c.EnableHealthzCheck = o.EnableHealthzCheck

c.TransformedInformerForPod = o.TransformedInformerForPod

Expand Down
2 changes: 2 additions & 0 deletions pkg/config/generic/generic_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
type GenericConfiguration struct {
DryRun bool

EnableHealthzCheck bool

// for some cases, we may need to enable the ability of transformed informer
TransformedInformerForPod bool

Expand Down

0 comments on commit f9ab27a

Please sign in to comment.