From 3ff16e774e999179707fc0e74b9d286edf7b7bab Mon Sep 17 00:00:00 2001 From: hty Date: Thu, 11 Mar 2021 15:41:03 +0800 Subject: [PATCH] Add readiness probe for the agent. Fixes #822 --- cmd/antrea-agent/agent.go | 9 +++++++++ .../controller/networkpolicy/networkpolicy_controller.go | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/cmd/antrea-agent/agent.go b/cmd/antrea-agent/agent.go index 8588bb07e50..5213e7f9f48 100644 --- a/cmd/antrea-agent/agent.go +++ b/cmd/antrea-agent/agent.go @@ -17,8 +17,10 @@ package main import ( "fmt" "net" + "net/http" "time" + "k8s.io/apiserver/pkg/server/healthz" "k8s.io/client-go/informers" "k8s.io/klog" @@ -319,6 +321,13 @@ func run(o *Options) error { if err != nil { return fmt.Errorf("error when creating agent API server: %v", err) } + check := healthz.NamedCheck("watcher", func(_ *http.Request) error { + if networkPolicyController.GetControllerConnectionStatus() { + return nil + } + return fmt.Errorf("Some watchers may not be connected") + }) + apiServer.GenericAPIServer.AddHealthChecks(check) go apiServer.Run(stopCh) // Start PacketIn for features and specify their own reason. diff --git a/pkg/agent/controller/networkpolicy/networkpolicy_controller.go b/pkg/agent/controller/networkpolicy/networkpolicy_controller.go index 7316c543f56..d8322ddea0d 100644 --- a/pkg/agent/controller/networkpolicy/networkpolicy_controller.go +++ b/pkg/agent/controller/networkpolicy/networkpolicy_controller.go @@ -576,6 +576,11 @@ func (w *watcher) watch() { klog.Warningf("Failed to start watch for %s: %v", w.objectType, err) return } + _, ok := watcher.(*watch.StreamWatcher) + if !ok { + klog.Warningf("Failed to start watch for %s. Something wrong with the connection?", w.objectType) + return + } klog.Infof("Started watch for %s", w.objectType) w.setConnected(true)