Skip to content

Commit c196b5c

Browse files
committed
WaitForEKSClusterUpgradePolicy fail early on NotFound
1 parent c274519 commit c196b5c

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

test/e2e/suites/managed/eks_upgrade_policy_test.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ import (
2525
"time"
2626

2727
"github.com/aws/aws-sdk-go-v2/aws"
28+
ekstypes "github.com/aws/aws-sdk-go-v2/service/eks/types"
2829
"github.com/onsi/ginkgo/v2"
2930
. "github.com/onsi/gomega"
3031
corev1 "k8s.io/api/core/v1"
3132

3233
ekscontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/eks/api/v1beta2"
34+
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/awserrors"
3335
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/converters"
3436
"sigs.k8s.io/cluster-api-provider-aws/v2/test/e2e/shared"
3537
"sigs.k8s.io/cluster-api/test/framework"
@@ -109,11 +111,27 @@ var _ = ginkgo.Describe("EKS upgrade policy test", func() {
109111

110112
func WaitForEKSClusterUpgradePolicy(ctx context.Context, sess *aws.Config, eksClusterName string, upgradePolicy ekscontrolplanev1.UpgradePolicy) {
111113
ginkgo.By(fmt.Sprintf("Checking EKS control plane upgrade policy matches %s", upgradePolicy))
112-
Eventually(func() (bool, error) {
114+
Eventually(func() error {
113115
cluster, err := getEKSCluster(ctx, eksClusterName, sess)
114116
if err != nil {
115-
return false, err
117+
smithyErr := awserrors.ParseSmithyError(err)
118+
notFoundErr := &ekstypes.ResourceNotFoundException{}
119+
if smithyErr.ErrorCode() == notFoundErr.ErrorCode() {
120+
// Unrecoverable error stop trying and fail early.
121+
return StopTrying(fmt.Sprintf("unrecoverable error: cluster %q not found: %s", eksClusterName, smithyErr.ErrorMessage()))
122+
}
123+
return err // For transient errors, retry
116124
}
117-
return converters.SupportTypeToSDK(upgradePolicy) == cluster.UpgradePolicy.SupportType, nil
118-
}, 5*time.Minute, 10*time.Second).Should(BeTrue(), fmt.Sprintf("eventually failed checking EKS Cluster %q upgrade policy is %s", eksClusterName, upgradePolicy))
125+
126+
expectedPolicy := converters.SupportTypeToSDK(upgradePolicy)
127+
actualPolicy := cluster.UpgradePolicy.SupportType
128+
129+
if actualPolicy != expectedPolicy {
130+
// The upgrade policy change hasn't been reflected in EKS yet, error and try again.
131+
return fmt.Errorf("upgrade policy mismatch: expected %s, but found %s", expectedPolicy, actualPolicy)
132+
}
133+
134+
// Success in finding the change has been reflected in EKS.
135+
return nil
136+
}, 5*time.Minute, 10*time.Second).Should(Succeed(), fmt.Sprintf("eventually failed checking EKS Cluster %q upgrade policy is %s", eksClusterName, upgradePolicy))
119137
}

test/e2e/suites/managed/helpers.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ func getEKSCluster(ctx context.Context, eksClusterName string, sess *aws.Config)
106106
}
107107
result, err := eksClient.DescribeCluster(ctx, input)
108108

109+
if err != nil {
110+
return nil, err
111+
}
112+
109113
return result.Cluster, err
110114
}
111115

0 commit comments

Comments
 (0)