Skip to content

Commit

Permalink
Add readiness probe for the agent.
Browse files Browse the repository at this point in the history
Fixes #822
  • Loading branch information
hty690 committed Mar 11, 2021
1 parent d77f8ff commit 3ff16e7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmd/antrea-agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3ff16e7

Please sign in to comment.