Skip to content

Commit

Permalink
PodWatcher: retry net.OpError errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dfinkel committed Oct 12, 2021
1 parent e0a5933 commit 61058c0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions k8s_pod_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,14 @@ func (p *PodWatcher) Run(ctx context.Context) error {
t.Status().Code, watchStartErr)
}
default:
noe := (*net.OpError)(nil)
if errors.As(watchStartErr, &noe) {
// If it's a connection error of some sort, we want to backoff and retry
if sleepBackoff() {
return nil
}
continue
}
return fmt.Errorf("failed to startup watcher: %w", watchStartErr)
}
switch resync() {
Expand Down
17 changes: 17 additions & 0 deletions k8s_pod_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"net"
"net/http"
"net/url"
"reflect"
"sync"
"testing"
Expand Down Expand Up @@ -769,6 +770,22 @@ func TestPodWatcherErrorRecovery(t *testing.T) {
&DeletePod{name: "foobar"},
},
},
{
name: "one_ready_then_dies_one_reconnect_network_error",
listRets: []listRetPI{{pi: []podInfo{{name: "foobar", ip: "10.42.42.42", labels: map[string]string{"app": "fimbat"},
ready: true, phase: k8score.PodRunning}}}},
watchRets: []watchRet{
{watch: []watchEvent{}},
{err: &url.Error{Op: "foo", Err: &net.OpError{}}},
{err: goneErr{}},
{watch: []watchEvent{}},
},
expectedEvents: []PodEvent{
&CreatePod{name: "foobar", IP: &net.IPAddr{IP: net.IPv4(10, 42, 42, 42)},
Def: genPod("foobar", "10.42.42.42", map[string]string{"app": "fimbat"}, true, k8score.PodRunning)},
&DeletePod{name: "foobar"},
},
},
{
name: "one_ready_then_dies_one_reconnect_change_error_no_watch_gone_error",
listRets: []listRetPI{{pi: []podInfo{{name: "foobar", ip: "10.42.42.42", labels: map[string]string{"app": "fimbat"},
Expand Down

0 comments on commit 61058c0

Please sign in to comment.