Skip to content

Commit c9a342e

Browse files
committed
fix(e2e): use targeted patch for EKS upgrade policy test
The upgrade policy e2e test flakes because it re-applies the entire cluster template to change the upgradePolicy field. The CAPI framework's CreateOrUpdate performs a full object Update, which wipes ownerReferences, finalizers, and status from the existing AWSManagedControlPlane. This creates a race where the controller may never reconcile within the 5-minute timeout. Replace the second ManagedClusterSpec() call with a targeted patch using the CAPI patch helper, matching the pattern used by UpgradeControlPlaneVersionSpec(). The Get and Patch calls are wrapped in Eventually blocks for resilience against transient API errors. Signed-off-by: Damiano Donati <damiano.donati@gmail.com>
1 parent 50875b6 commit c9a342e

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

test/e2e/suites/managed/eks_upgrade_policy_test.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ import (
2929
"github.com/onsi/ginkgo/v2"
3030
. "github.com/onsi/gomega"
3131
corev1 "k8s.io/api/core/v1"
32+
crclient "sigs.k8s.io/controller-runtime/pkg/client"
3233

3334
ekscontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/eks/api/v1beta2"
3435
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/awserrors"
3536
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/converters"
3637
"sigs.k8s.io/cluster-api-provider-aws/v2/test/e2e/shared"
3738
"sigs.k8s.io/cluster-api/test/framework"
3839
"sigs.k8s.io/cluster-api/util"
40+
"sigs.k8s.io/cluster-api/util/patch"
3941
)
4042

4143
// EKS upgrade policy test.
@@ -92,10 +94,28 @@ var _ = ginkgo.Describe("EKS upgrade policy test", func() {
9294

9395
changedUpgradePolicy := ekscontrolplanev1.UpgradePolicyExtended
9496
ginkgo.By(fmt.Sprintf("Changing the UpgradePolicy from %s to %s", upgradePolicy, changedUpgradePolicy))
95-
shared.SetEnvVar(shared.UpgradePolicy, changedUpgradePolicy.String(), false)
96-
ManagedClusterSpec(ctx, getManagedClusterSpec)
97+
98+
mgmtClient := e2eCtx.Environment.BootstrapClusterProxy.GetClient()
99+
controlPlane := &ekscontrolplanev1.AWSManagedControlPlane{}
100+
101+
// Get the AWSManagedControlPlane.
102+
Eventually(func() error {
103+
return mgmtClient.Get(ctx, crclient.ObjectKey{Namespace: namespace.Name, Name: getControlPlaneName(clusterName)}, controlPlane)
104+
}, e2eCtx.E2EConfig.GetIntervals("", "wait-client-request")...).Should(Succeed(), "eventually failed trying to get the AWSManagedControlPlane")
105+
106+
// Patch the AWSManagedControlPlane with the new upgrade policy.
107+
patchHelper, err := patch.NewHelper(controlPlane, mgmtClient)
108+
Expect(err).ToNot(HaveOccurred())
109+
controlPlane.Spec.UpgradePolicy = changedUpgradePolicy
110+
111+
Eventually(func() error {
112+
return patchHelper.Patch(ctx, controlPlane)
113+
}, e2eCtx.E2EConfig.GetIntervals("", "wait-client-request")...).Should(Succeed(), "eventually failed patching the AWSManagedControlPlane")
114+
115+
// Wait for the upgrade policy to be reflected in AWS EKS.
97116
WaitForEKSClusterUpgradePolicy(ctx, e2eCtx.BootstrapUserAWSSession, eksClusterName, changedUpgradePolicy)
98117

118+
// Clean up the cluster.
99119
framework.DeleteCluster(ctx, framework.DeleteClusterInput{
100120
Deleter: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
101121
Cluster: cluster,
@@ -109,6 +129,8 @@ var _ = ginkgo.Describe("EKS upgrade policy test", func() {
109129
})
110130
})
111131

132+
// WaitForEKSClusterUpgradePolicy polls the AWS EKS API until the cluster's upgrade policy
133+
// matches the expected value, failing early if the cluster is not found.
112134
func WaitForEKSClusterUpgradePolicy(ctx context.Context, sess *aws.Config, eksClusterName string, upgradePolicy ekscontrolplanev1.UpgradePolicy) {
113135
ginkgo.By(fmt.Sprintf("Checking EKS control plane upgrade policy matches %s", upgradePolicy))
114136
Eventually(func() error {

0 commit comments

Comments
 (0)