From 8e10d390b26eee3e3558b08f8094f1317c9601b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Wei=C3=9Fe?= Date: Tue, 16 Apr 2024 13:57:36 +0200 Subject: [PATCH] maxRetries->maxAttempts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel Weiße --- internal/constellation/kubecmd/kubecmd.go | 12 +++++----- .../constellation/kubecmd/kubecmd_test.go | 24 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/internal/constellation/kubecmd/kubecmd.go b/internal/constellation/kubecmd/kubecmd.go index d49d9ccf6..1ebf99265 100644 --- a/internal/constellation/kubecmd/kubecmd.go +++ b/internal/constellation/kubecmd/kubecmd.go @@ -65,7 +65,7 @@ func (e *applyError) Error() string { type KubeCmd struct { kubectl kubectlInterface retryInterval time.Duration - maxRetries int + maxAttempts int log debugLog } @@ -79,7 +79,7 @@ func New(kubeConfig []byte, log debugLog) (*KubeCmd, error) { return &KubeCmd{ kubectl: client, retryInterval: time.Second * 5, - maxRetries: 20, + maxAttempts: 20, log: log, }, nil } @@ -440,8 +440,8 @@ func (k *KubeCmd) retryGetJoinConfig(ctx context.Context) (*corev1.ConfigMap, er return false } ctr++ - k.log.Debug("Getting join-config ConfigMap failed", "attempt", ctr, "maxRetries", k.maxRetries, "error", err) - return ctr < k.maxRetries + k.log.Debug("Getting join-config ConfigMap failed", "attempt", ctr, "maxAttempts", k.maxAttempts, "error", err) + return ctr < k.maxAttempts } var joinConfig *corev1.ConfigMap @@ -462,8 +462,8 @@ func (k *KubeCmd) retryAction(ctx context.Context, action func(ctx context.Conte ctr := 0 retrier := conretry.NewIntervalRetrier(&kubeDoer{action: action}, k.retryInterval, func(err error) bool { ctr++ - k.log.Debug("Action failed", "attempt", ctr, "maxRetries", k.maxRetries, "error", err) - return ctr < k.maxRetries + k.log.Debug("Action failed", "attempt", ctr, "maxAttempts", k.maxAttempts, "error", err) + return ctr < k.maxAttempts }) return retrier.Do(ctx) } diff --git a/internal/constellation/kubecmd/kubecmd_test.go b/internal/constellation/kubecmd/kubecmd_test.go index 5a4840522..74e9562c1 100644 --- a/internal/constellation/kubecmd/kubecmd_test.go +++ b/internal/constellation/kubecmd/kubecmd_test.go @@ -176,7 +176,7 @@ func TestUpgradeNodeImage(t *testing.T) { upgrader := KubeCmd{ kubectl: kubectl, retryInterval: time.Millisecond, - maxRetries: 5, + maxAttempts: 5, log: logger.NewTest(t), } @@ -289,7 +289,7 @@ func TestUpgradeKubernetesVersion(t *testing.T) { upgrader := KubeCmd{ kubectl: kubectl, retryInterval: time.Millisecond, - maxRetries: 5, + maxAttempts: 5, log: logger.NewTest(t), } @@ -346,7 +346,7 @@ func TestIsValidImageUpgrade(t *testing.T) { upgrader := &KubeCmd{ retryInterval: time.Millisecond, - maxRetries: 5, + maxAttempts: 5, log: logger.NewTest(t), } @@ -399,7 +399,7 @@ func TestUpdateK8s(t *testing.T) { upgrader := &KubeCmd{ retryInterval: time.Millisecond, - maxRetries: 5, + maxAttempts: 5, log: logger.NewTest(t), } @@ -597,7 +597,7 @@ func TestApplyJoinConfig(t *testing.T) { kubectl: tc.kubectl, log: logger.NewTest(t), retryInterval: time.Millisecond, - maxRetries: 5, + maxAttempts: 5, } err := cmd.ApplyJoinConfig(context.Background(), tc.newAttestationCfg, []byte{0x11}) @@ -621,7 +621,7 @@ func TestApplyJoinConfig(t *testing.T) { } func TestRetryAction(t *testing.T) { - maxRetries := 3 + maxAttempts := 3 testCases := map[string]struct { failures int @@ -633,12 +633,12 @@ func TestRetryAction(t *testing.T) { "fail once": { failures: 1, }, - "fail equal to maxRetries": { - failures: maxRetries, + "fail equal to maxAttempts": { + failures: maxAttempts, wantErr: true, }, - "fail more than maxRetries": { - failures: maxRetries + 5, + "fail more than maxAttempts": { + failures: maxAttempts + 5, wantErr: true, }, } @@ -647,7 +647,7 @@ func TestRetryAction(t *testing.T) { t.Run(name, func(t *testing.T) { k := &KubeCmd{ retryInterval: time.Millisecond, - maxRetries: maxRetries, + maxAttempts: maxAttempts, log: logger.NewTest(t), } @@ -667,7 +667,7 @@ func TestRetryAction(t *testing.T) { err := k.retryAction(context.Background(), action) if tc.wantErr { assert.Error(err) - assert.Equal(min(tc.failures, maxRetries), failureCtr) + assert.Equal(min(tc.failures, maxAttempts), failureCtr) return } assert.NoError(err)