Skip to content

Commit

Permalink
test deleting all tags, node labels, and node taints in AKS e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
nojnhuh committed Nov 20, 2023
1 parent 63df74f commit 19e1f0d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 46 deletions.
31 changes: 19 additions & 12 deletions test/e2e/aks_node_labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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)
}

Expand Down
27 changes: 17 additions & 10 deletions test/e2e/aks_node_taints.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
{
Expand Down Expand Up @@ -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)
}

Expand Down
50 changes: 26 additions & 24 deletions test/e2e/aks_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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{
Expand All @@ -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)
}

Expand Down

0 comments on commit 19e1f0d

Please sign in to comment.