diff --git a/go.mod b/go.mod index ca533f0286e..cf0c894845d 100644 --- a/go.mod +++ b/go.mod @@ -40,6 +40,7 @@ require ( go.opentelemetry.io/otel/trace v1.21.0 go.uber.org/mock v0.3.0 golang.org/x/crypto v0.15.0 + golang.org/x/exp v0.0.0-20231006140011-7918f672742d golang.org/x/mod v0.14.0 golang.org/x/text v0.14.0 gopkg.in/yaml.v3 v3.0.1 @@ -182,7 +183,6 @@ require ( go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.25.0 // indirect - golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect golang.org/x/net v0.17.0 // indirect golang.org/x/oauth2 v0.13.0 // indirect golang.org/x/sync v0.4.0 // indirect diff --git a/test/e2e/aks_node_labels.go b/test/e2e/aks_node_labels.go index 5655f5ab04d..5ac398c734f 100644 --- a/test/e2e/aks_node_labels.go +++ b/test/e2e/aks_node_labels.go @@ -95,15 +95,24 @@ func AKSNodeLabelsSpec(ctx context.Context, inputGetter func() AKSNodeLabelsSpec } } - Byf("Creating node labels for machine pool %s", mp.Name) + Byf("Deleting all node labels for machine pool %s", mp.Name) + expectedLabels = nil var initialLabels map[string]string + Eventually(func(g Gomega) { + g.Expect(mgmtClient.Get(ctx, client.ObjectKeyFromObject(ammp), ammp)).To(Succeed()) + initialLabels = ammp.Spec.NodeLabels + ammp.Spec.NodeLabels = expectedLabels + g.Expect(mgmtClient.Update(ctx, ammp)).To(Succeed()) + }, inputGetter().WaitForUpdate...).Should(Succeed()) + Eventually(checkLabels, input.WaitForUpdate...).Should(Succeed()) + + Byf("Creating node labels for machine pool %s", mp.Name) expectedLabels = map[string]string{ "test": "label", "another": "value", } Eventually(func(g Gomega) { g.Expect(mgmtClient.Get(ctx, client.ObjectKeyFromObject(ammp), ammp)).To(Succeed()) - initialLabels = ammp.Spec.NodeLabels ammp.Spec.NodeLabels = expectedLabels g.Expect(mgmtClient.Update(ctx, ammp)).To(Succeed()) }, input.WaitForUpdate...).Should(Succeed()) @@ -120,16 +129,14 @@ func AKSNodeLabelsSpec(ctx context.Context, inputGetter func() AKSNodeLabelsSpec }, input.WaitForUpdate...).Should(Succeed()) Eventually(checkLabels, input.WaitForUpdate...).Should(Succeed()) - if initialLabels != nil { - Byf("Restoring initial node labels for machine pool %s", mp.Name) - expectedLabels = initialLabels - Eventually(func(g Gomega) { - g.Expect(mgmtClient.Get(ctx, client.ObjectKeyFromObject(ammp), ammp)).To(Succeed()) - ammp.Spec.NodeLabels = expectedLabels - g.Expect(mgmtClient.Update(ctx, ammp)).To(Succeed()) - }, input.WaitForUpdate...).Should(Succeed()) - Eventually(checkLabels, input.WaitForUpdate...).Should(Succeed()) - } + Byf("Restoring initial node labels for machine pool %s", mp.Name) + expectedLabels = initialLabels + Eventually(func(g Gomega) { + g.Expect(mgmtClient.Get(ctx, client.ObjectKeyFromObject(ammp), ammp)).To(Succeed()) + ammp.Spec.NodeLabels = expectedLabels + g.Expect(mgmtClient.Update(ctx, ammp)).To(Succeed()) + }, input.WaitForUpdate...).Should(Succeed()) + Eventually(checkLabels, input.WaitForUpdate...).Should(Succeed()) }(mp) } diff --git a/test/e2e/aks_node_taints.go b/test/e2e/aks_node_taints.go index 94d96cd9b8a..eacb010ce5c 100644 --- a/test/e2e/aks_node_taints.go +++ b/test/e2e/aks_node_taints.go @@ -98,6 +98,15 @@ func AKSNodeTaintsSpec(ctx context.Context, inputGetter func() AKSNodeTaintsSpec } } + Byf("Deleting all node taints for machine pool %s", mp.Name) + expectedTaints = nil + Eventually(func(g Gomega) { + g.Expect(mgmtClient.Get(ctx, client.ObjectKeyFromObject(ammp), ammp)).To(Succeed()) + ammp.Spec.Taints = expectedTaints + g.Expect(mgmtClient.Update(ctx, ammp)).To(Succeed()) + }, inputGetter().WaitForUpdate...).Should(Succeed()) + Eventually(checkTaints, input.WaitForUpdate...).Should(Succeed()) + Byf("Creating taints for machine pool %s", mp.Name) expectedTaints = infrav1.Taints{ { @@ -127,16 +136,14 @@ func AKSNodeTaintsSpec(ctx context.Context, inputGetter func() AKSNodeTaintsSpec }, input.WaitForUpdate...).Should(Succeed()) Eventually(checkTaints, input.WaitForUpdate...).Should(Succeed()) - if initialTaints != nil { - Byf("Restoring initial taints for machine pool %s", mp.Name) - expectedTaints = initialTaints - Eventually(func(g Gomega) { - g.Expect(mgmtClient.Get(ctx, client.ObjectKeyFromObject(ammp), ammp)).To(Succeed()) - ammp.Spec.Taints = expectedTaints - g.Expect(mgmtClient.Update(ctx, ammp)).To(Succeed()) - }, input.WaitForUpdate...).Should(Succeed()) - Eventually(checkTaints, input.WaitForUpdate...).Should(Succeed()) - } + Byf("Restoring initial taints for machine pool %s", mp.Name) + expectedTaints = initialTaints + Eventually(func(g Gomega) { + g.Expect(mgmtClient.Get(ctx, client.ObjectKeyFromObject(ammp), ammp)).To(Succeed()) + ammp.Spec.Taints = expectedTaints + g.Expect(mgmtClient.Update(ctx, ammp)).To(Succeed()) + }, input.WaitForUpdate...).Should(Succeed()) + Eventually(checkTaints, input.WaitForUpdate...).Should(Succeed()) }(mp) } diff --git a/test/e2e/aks_tags.go b/test/e2e/aks_tags.go index b8f10670260..d91d5f1577e 100644 --- a/test/e2e/aks_tags.go +++ b/test/e2e/aks_tags.go @@ -27,6 +27,7 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v4" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "golang.org/x/exp/maps" "k8s.io/apimachinery/pkg/types" "k8s.io/utils/ptr" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" @@ -107,10 +108,10 @@ func AKSAdditionalTagsSpec(ctx context.Context, inputGetter func() AKSAdditional }, inputGetter().WaitForUpdate...).Should(Succeed()) By("Creating tags for control plane") - expectedTags = infrav1.Tags{ - "test": "tag", - "another": "value", - } + // Preserve "creationTimestamp" so the RG cleanup doesn't fire on this cluster during this test. + expectedTags = maps.Clone(initialTags) + expectedTags["test"] = "tag" + expectedTags["another"] = "value" Eventually(func(g Gomega) { g.Expect(mgmtClient.Get(ctx, client.ObjectKeyFromObject(infraControlPlane), infraControlPlane)).To(Succeed()) infraControlPlane.Spec.AdditionalTags = expectedTags @@ -129,16 +130,14 @@ func AKSAdditionalTagsSpec(ctx context.Context, inputGetter func() AKSAdditional }, inputGetter().WaitForUpdate...).Should(Succeed()) Eventually(checkTags, input.WaitForUpdate...).Should(Succeed()) - if initialTags != nil { - By("Restoring initial tags for control plane") - expectedTags = initialTags - Eventually(func(g Gomega) { - g.Expect(mgmtClient.Get(ctx, client.ObjectKeyFromObject(infraControlPlane), infraControlPlane)).To(Succeed()) - infraControlPlane.Spec.AdditionalTags = expectedTags - g.Expect(mgmtClient.Update(ctx, infraControlPlane)).To(Succeed()) - }, inputGetter().WaitForUpdate...).Should(Succeed()) - Eventually(checkTags, input.WaitForUpdate...).Should(Succeed()) - } + By("Restoring initial tags for control plane") + expectedTags = initialTags + Eventually(func(g Gomega) { + g.Expect(mgmtClient.Get(ctx, client.ObjectKeyFromObject(infraControlPlane), infraControlPlane)).To(Succeed()) + infraControlPlane.Spec.AdditionalTags = expectedTags + g.Expect(mgmtClient.Update(ctx, infraControlPlane)).To(Succeed()) + }, inputGetter().WaitForUpdate...).Should(Succeed()) + Eventually(checkTags, input.WaitForUpdate...).Should(Succeed()) }() for _, mp := range input.MachinePools { @@ -182,11 +181,16 @@ func AKSAdditionalTagsSpec(ctx context.Context, inputGetter func() AKSAdditional } } + Byf("Deleting all tags for machine pool %s", mp.Name) + expectedTags = nil var initialTags infrav1.Tags Eventually(func(g Gomega) { g.Expect(mgmtClient.Get(ctx, client.ObjectKeyFromObject(ammp), ammp)).To(Succeed()) initialTags = ammp.Spec.AdditionalTags + ammp.Spec.AdditionalTags = expectedTags + g.Expect(mgmtClient.Update(ctx, ammp)).To(Succeed()) }, inputGetter().WaitForUpdate...).Should(Succeed()) + Eventually(checkTags, input.WaitForUpdate...).Should(Succeed()) Byf("Creating tags for machine pool %s", mp.Name) expectedTags = infrav1.Tags{ @@ -211,16 +215,14 @@ func AKSAdditionalTagsSpec(ctx context.Context, inputGetter func() AKSAdditional }, inputGetter().WaitForUpdate...).Should(Succeed()) Eventually(checkTags, input.WaitForUpdate...).Should(Succeed()) - if initialTags != nil { - Byf("Restoring initial tags for machine pool %s", mp.Name) - expectedTags = initialTags - Eventually(func(g Gomega) { - g.Expect(mgmtClient.Get(ctx, client.ObjectKeyFromObject(ammp), ammp)).To(Succeed()) - ammp.Spec.AdditionalTags = expectedTags - g.Expect(mgmtClient.Update(ctx, ammp)).To(Succeed()) - }, inputGetter().WaitForUpdate...).Should(Succeed()) - Eventually(checkTags, input.WaitForUpdate...).Should(Succeed()) - } + Byf("Restoring initial tags for machine pool %s", mp.Name) + expectedTags = initialTags + Eventually(func(g Gomega) { + g.Expect(mgmtClient.Get(ctx, client.ObjectKeyFromObject(ammp), ammp)).To(Succeed()) + ammp.Spec.AdditionalTags = expectedTags + g.Expect(mgmtClient.Update(ctx, ammp)).To(Succeed()) + }, inputGetter().WaitForUpdate...).Should(Succeed()) + Eventually(checkTags, input.WaitForUpdate...).Should(Succeed()) }(mp) }