Skip to content

Commit

Permalink
cilium: Don't report health error when disabled
Browse files Browse the repository at this point in the history
When the user configures --enable-health-checking=false, 'cilium status'
would previously print:

  $ cilium status
  ...
  Cluster health:               Warning   cilium-health daemon unreachable

This would occur despite the user explicitly disabling the feature. To
better reflect whether the feature is enabled or not, check in the
status response whether there is a health endpoint. If there is one,
then the feature is enabled and we can query & print its status. If
there isn't one, then the feature is disabled and we won't get a
successful response anyway, so just report back that the feature is
disabled instead:

  $ cilium status
  ...
  Cluster health:               Probe disabled

Signed-off-by: Joe Stringer <joe@cilium.io>
  • Loading branch information
joestringer committed Oct 20, 2021
1 parent 67ac052 commit 5cfd761
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
14 changes: 13 additions & 1 deletion cilium/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
pkg "github.com/cilium/cilium/pkg/client"
"github.com/cilium/cilium/pkg/command"
healthPkg "github.com/cilium/cilium/pkg/health/client"
"github.com/cilium/cilium/pkg/health/defaults"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -95,7 +96,18 @@ func statusDaemon() {
os.Exit(1)
}

healthPkg.GetAndFormatHealthStatus(w, true, allHealth, healthLines)
healthEnabled := false
for _, c := range sr.Controllers {
if c.Name == defaults.HealthEPName {
healthEnabled = true
break
}
}
if healthEnabled {
healthPkg.GetAndFormatHealthStatus(w, true, allHealth, healthLines)
} else {
fmt.Fprint(w, "Cluster health:\t\tProbe disabled\n")
}
w.Flush()
}
}
3 changes: 2 additions & 1 deletion daemon/cmd/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/cilium/cilium/pkg/cleanup"
"github.com/cilium/cilium/pkg/controller"
"github.com/cilium/cilium/pkg/endpoint"
"github.com/cilium/cilium/pkg/health/defaults"
"github.com/cilium/cilium/pkg/k8s"
"github.com/cilium/cilium/pkg/logging/logfields"
"github.com/cilium/cilium/pkg/option"
Expand Down Expand Up @@ -50,7 +51,7 @@ func (d *Daemon) initHealth() {
// Wait for the API, then launch the controller
var client *health.Client

controller.NewManager().UpdateController("cilium-health-ep",
controller.NewManager().UpdateController(defaults.HealthEPName,
controller.ControllerParams{
DoFunc: func(ctx context.Context) error {
var err error
Expand Down
4 changes: 4 additions & 0 deletions pkg/health/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ const (

// HTTPPathPort is used for probing base HTTP path connectivity
HTTPPathPort = daemon.ClusterHealthPort

// HealthEPName is the name used for the health endpoint, which is also
// used by the CLI client to detect when connectivity health is enabled
HealthEPName = "cilium-health-ep"
)

0 comments on commit 5cfd761

Please sign in to comment.