Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
Improve readability of WatchForService function
Browse files Browse the repository at this point in the history
Signed-off-by: Nino Kodabande <[email protected]>
  • Loading branch information
Nino-K committed May 7, 2024
1 parent b26db19 commit ae6abd7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmd/rancher-desktop-guestagent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func main() {
k8sServiceListenerIP := net.ParseIP(*k8sServiceListenerAddr)

if k8sServiceListenerIP == nil || !(k8sServiceListenerIP.Equal(net.IPv4zero) ||
k8sServiceListenerIP.Equal(net.IPv4(127, 0, 0, 1))) { //nolint:gomnd,mnd // IPv4 addr localhost
k8sServiceListenerIP.Equal(net.IPv4(127, 0, 0, 1))) {
log.Fatalf("empty or none valid input for Kubernetes service listener IP address %s. "+
"Valid options are 0.0.0.0 and 127.0.0.1.", *k8sServiceListenerAddr)
}
Expand Down
19 changes: 10 additions & 9 deletions pkg/kube/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,17 @@ func WatchForServices(
eventCh, errorCh, err = watchServices(watchContext, clientset)
if err != nil {
switch {
default:
return err
case isTimeout(err):
fallthrough
case errors.Is(err, unix.ENETUNREACH):
fallthrough
case errors.Is(err, unix.ECONNREFUSED):
fallthrough
case isAPINotReady(err):
// sleep and continue for all the expected case
time.Sleep(time.Second)

continue
default:
return err
}
// sleep and continue for all the expected case
time.Sleep(time.Second)

continue
}

log.Debugf("watching kubernetes services")
Expand Down Expand Up @@ -267,6 +264,10 @@ func isTimeout(err error) bool {
return false
}

// This is a k3s error that is received over
// the HTTP, Also, it is worth noting that this
// error is wrapped. This is why we are not testing
// against the real error object using errors.Is().
func isAPINotReady(err error) bool {
return strings.Contains(err.Error(), "apiserver not ready")
}
Expand Down

0 comments on commit ae6abd7

Please sign in to comment.