Skip to content

Commit

Permalink
installer: log connection errors on retry
Browse files Browse the repository at this point in the history
  • Loading branch information
mfojtik committed Sep 9, 2020
1 parent b4f9ae5 commit 4c0f9d6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/operator/resource/retry/retry.go
Expand Up @@ -6,6 +6,7 @@ import (
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/util/retry"
"k8s.io/klog/v2"
)

// ignoreConnectionErrors is a wrapper for condition function that will cause to retry on all errors like
Expand All @@ -23,6 +24,7 @@ func ignoreConnectionErrors(lastError *error, fn ConditionWithContextFunc) Condi
return false, err
default:
*lastError = err
klog.V(4).Infof("Retrying connection error %v ...", err)
return false, nil
}
}
Expand Down
18 changes: 18 additions & 0 deletions pkg/operator/resource/retry/retry_test.go
Expand Up @@ -3,11 +3,13 @@ package retry
import (
"context"
"fmt"
"syscall"
"testing"
"time"

"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/net"
)

func TestRetryOnConnectionErrors(t *testing.T) {
Expand Down Expand Up @@ -36,6 +38,22 @@ func TestRetryOnConnectionErrors(t *testing.T) {
}
},
},
{
name: "retry on connection error",
contextTimeout: 500 * time.Millisecond,
jobDuration: 200 * time.Millisecond,
jobError: syscall.ECONNREFUSED,
evalError: func(t *testing.T, e error) {
if !net.IsConnectionRefused(e) {
t.Errorf("expected connection refused error, got %v", e)
}
},
evalAttempts: func(t *testing.T, attempts int) {
if attempts <= 1 {
t.Errorf("expected more than one attempt, got %d", attempts)
}
},
},
{
name: "retry on internal server error",
contextTimeout: 500 * time.Millisecond,
Expand Down

0 comments on commit 4c0f9d6

Please sign in to comment.