Skip to content

Commit

Permalink
Improve logs when there is a timeout error
Browse files Browse the repository at this point in the history
The agent logs will print the failure message when the connection to
the controller is timeout. Also adding HealthCheck to remind
the users of the connectivity issue.

Fixes #822
  • Loading branch information
hty690 committed Mar 11, 2021
1 parent d77f8ff commit d016c18
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
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,7 +576,12 @@ func (w *watcher) watch() {
klog.Warningf("Failed to start watch for %s: %v", w.objectType, err)
return
}

//Make sure that watcher is not the type of watch.NewEmptyWatch()
_, 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)
eventCount := 0
Expand Down

0 comments on commit d016c18

Please sign in to comment.