Skip to content

Commit 3ef2291

Browse files
authored
Merge pull request #4295 from nojnhuh/aks-delete-fields
test deleting all tags, node labels, and node taints in AKS e2e
2 parents 82786b8 + a8a1f0f commit 3ef2291

File tree

4 files changed

+63
-47
lines changed

4 files changed

+63
-47
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ require (
4040
go.opentelemetry.io/otel/trace v1.21.0
4141
go.uber.org/mock v0.3.0
4242
golang.org/x/crypto v0.15.0
43+
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
4344
golang.org/x/mod v0.14.0
4445
golang.org/x/text v0.14.0
4546
gopkg.in/yaml.v3 v3.0.1
@@ -182,7 +183,6 @@ require (
182183
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
183184
go.uber.org/multierr v1.11.0 // indirect
184185
go.uber.org/zap v1.25.0 // indirect
185-
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
186186
golang.org/x/net v0.17.0 // indirect
187187
golang.org/x/oauth2 v0.13.0 // indirect
188188
golang.org/x/sync v0.4.0 // indirect

test/e2e/aks_node_labels.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,24 @@ func AKSNodeLabelsSpec(ctx context.Context, inputGetter func() AKSNodeLabelsSpec
9595
}
9696
}
9797

98-
Byf("Creating node labels for machine pool %s", mp.Name)
98+
Byf("Deleting all node labels for machine pool %s", mp.Name)
99+
expectedLabels = nil
99100
var initialLabels map[string]string
101+
Eventually(func(g Gomega) {
102+
g.Expect(mgmtClient.Get(ctx, client.ObjectKeyFromObject(ammp), ammp)).To(Succeed())
103+
initialLabels = ammp.Spec.NodeLabels
104+
ammp.Spec.NodeLabels = expectedLabels
105+
g.Expect(mgmtClient.Update(ctx, ammp)).To(Succeed())
106+
}, inputGetter().WaitForUpdate...).Should(Succeed())
107+
Eventually(checkLabels, input.WaitForUpdate...).Should(Succeed())
108+
109+
Byf("Creating node labels for machine pool %s", mp.Name)
100110
expectedLabels = map[string]string{
101111
"test": "label",
102112
"another": "value",
103113
}
104114
Eventually(func(g Gomega) {
105115
g.Expect(mgmtClient.Get(ctx, client.ObjectKeyFromObject(ammp), ammp)).To(Succeed())
106-
initialLabels = ammp.Spec.NodeLabels
107116
ammp.Spec.NodeLabels = expectedLabels
108117
g.Expect(mgmtClient.Update(ctx, ammp)).To(Succeed())
109118
}, input.WaitForUpdate...).Should(Succeed())
@@ -120,16 +129,14 @@ func AKSNodeLabelsSpec(ctx context.Context, inputGetter func() AKSNodeLabelsSpec
120129
}, input.WaitForUpdate...).Should(Succeed())
121130
Eventually(checkLabels, input.WaitForUpdate...).Should(Succeed())
122131

123-
if initialLabels != nil {
124-
Byf("Restoring initial node labels for machine pool %s", mp.Name)
125-
expectedLabels = initialLabels
126-
Eventually(func(g Gomega) {
127-
g.Expect(mgmtClient.Get(ctx, client.ObjectKeyFromObject(ammp), ammp)).To(Succeed())
128-
ammp.Spec.NodeLabels = expectedLabels
129-
g.Expect(mgmtClient.Update(ctx, ammp)).To(Succeed())
130-
}, input.WaitForUpdate...).Should(Succeed())
131-
Eventually(checkLabels, input.WaitForUpdate...).Should(Succeed())
132-
}
132+
Byf("Restoring initial node labels for machine pool %s", mp.Name)
133+
expectedLabels = initialLabels
134+
Eventually(func(g Gomega) {
135+
g.Expect(mgmtClient.Get(ctx, client.ObjectKeyFromObject(ammp), ammp)).To(Succeed())
136+
ammp.Spec.NodeLabels = expectedLabels
137+
g.Expect(mgmtClient.Update(ctx, ammp)).To(Succeed())
138+
}, input.WaitForUpdate...).Should(Succeed())
139+
Eventually(checkLabels, input.WaitForUpdate...).Should(Succeed())
133140
}(mp)
134141
}
135142

test/e2e/aks_node_taints.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ func AKSNodeTaintsSpec(ctx context.Context, inputGetter func() AKSNodeTaintsSpec
9898
}
9999
}
100100

101+
Byf("Deleting all node taints for machine pool %s", mp.Name)
102+
expectedTaints = nil
103+
Eventually(func(g Gomega) {
104+
g.Expect(mgmtClient.Get(ctx, client.ObjectKeyFromObject(ammp), ammp)).To(Succeed())
105+
ammp.Spec.Taints = expectedTaints
106+
g.Expect(mgmtClient.Update(ctx, ammp)).To(Succeed())
107+
}, inputGetter().WaitForUpdate...).Should(Succeed())
108+
Eventually(checkTaints, input.WaitForUpdate...).Should(Succeed())
109+
101110
Byf("Creating taints for machine pool %s", mp.Name)
102111
expectedTaints = infrav1.Taints{
103112
{
@@ -127,16 +136,14 @@ func AKSNodeTaintsSpec(ctx context.Context, inputGetter func() AKSNodeTaintsSpec
127136
}, input.WaitForUpdate...).Should(Succeed())
128137
Eventually(checkTaints, input.WaitForUpdate...).Should(Succeed())
129138

130-
if initialTaints != nil {
131-
Byf("Restoring initial taints for machine pool %s", mp.Name)
132-
expectedTaints = initialTaints
133-
Eventually(func(g Gomega) {
134-
g.Expect(mgmtClient.Get(ctx, client.ObjectKeyFromObject(ammp), ammp)).To(Succeed())
135-
ammp.Spec.Taints = expectedTaints
136-
g.Expect(mgmtClient.Update(ctx, ammp)).To(Succeed())
137-
}, input.WaitForUpdate...).Should(Succeed())
138-
Eventually(checkTaints, input.WaitForUpdate...).Should(Succeed())
139-
}
139+
Byf("Restoring initial taints for machine pool %s", mp.Name)
140+
expectedTaints = initialTaints
141+
Eventually(func(g Gomega) {
142+
g.Expect(mgmtClient.Get(ctx, client.ObjectKeyFromObject(ammp), ammp)).To(Succeed())
143+
ammp.Spec.Taints = expectedTaints
144+
g.Expect(mgmtClient.Update(ctx, ammp)).To(Succeed())
145+
}, input.WaitForUpdate...).Should(Succeed())
146+
Eventually(checkTaints, input.WaitForUpdate...).Should(Succeed())
140147
}(mp)
141148
}
142149

test/e2e/aks_tags.go

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v4"
2828
. "github.com/onsi/ginkgo/v2"
2929
. "github.com/onsi/gomega"
30+
"golang.org/x/exp/maps"
3031
"k8s.io/apimachinery/pkg/types"
3132
"k8s.io/utils/ptr"
3233
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
@@ -107,10 +108,10 @@ func AKSAdditionalTagsSpec(ctx context.Context, inputGetter func() AKSAdditional
107108
}, inputGetter().WaitForUpdate...).Should(Succeed())
108109

109110
By("Creating tags for control plane")
110-
expectedTags = infrav1.Tags{
111-
"test": "tag",
112-
"another": "value",
113-
}
111+
// Preserve "creationTimestamp" so the RG cleanup doesn't fire on this cluster during this test.
112+
expectedTags = maps.Clone(initialTags)
113+
expectedTags["test"] = "tag"
114+
expectedTags["another"] = "value"
114115
Eventually(func(g Gomega) {
115116
g.Expect(mgmtClient.Get(ctx, client.ObjectKeyFromObject(infraControlPlane), infraControlPlane)).To(Succeed())
116117
infraControlPlane.Spec.AdditionalTags = expectedTags
@@ -129,16 +130,14 @@ func AKSAdditionalTagsSpec(ctx context.Context, inputGetter func() AKSAdditional
129130
}, inputGetter().WaitForUpdate...).Should(Succeed())
130131
Eventually(checkTags, input.WaitForUpdate...).Should(Succeed())
131132

132-
if initialTags != nil {
133-
By("Restoring initial tags for control plane")
134-
expectedTags = initialTags
135-
Eventually(func(g Gomega) {
136-
g.Expect(mgmtClient.Get(ctx, client.ObjectKeyFromObject(infraControlPlane), infraControlPlane)).To(Succeed())
137-
infraControlPlane.Spec.AdditionalTags = expectedTags
138-
g.Expect(mgmtClient.Update(ctx, infraControlPlane)).To(Succeed())
139-
}, inputGetter().WaitForUpdate...).Should(Succeed())
140-
Eventually(checkTags, input.WaitForUpdate...).Should(Succeed())
141-
}
133+
By("Restoring initial tags for control plane")
134+
expectedTags = initialTags
135+
Eventually(func(g Gomega) {
136+
g.Expect(mgmtClient.Get(ctx, client.ObjectKeyFromObject(infraControlPlane), infraControlPlane)).To(Succeed())
137+
infraControlPlane.Spec.AdditionalTags = expectedTags
138+
g.Expect(mgmtClient.Update(ctx, infraControlPlane)).To(Succeed())
139+
}, inputGetter().WaitForUpdate...).Should(Succeed())
140+
Eventually(checkTags, input.WaitForUpdate...).Should(Succeed())
142141
}()
143142

144143
for _, mp := range input.MachinePools {
@@ -182,11 +181,16 @@ func AKSAdditionalTagsSpec(ctx context.Context, inputGetter func() AKSAdditional
182181
}
183182
}
184183

184+
Byf("Deleting all tags for machine pool %s", mp.Name)
185+
expectedTags = nil
185186
var initialTags infrav1.Tags
186187
Eventually(func(g Gomega) {
187188
g.Expect(mgmtClient.Get(ctx, client.ObjectKeyFromObject(ammp), ammp)).To(Succeed())
188189
initialTags = ammp.Spec.AdditionalTags
190+
ammp.Spec.AdditionalTags = expectedTags
191+
g.Expect(mgmtClient.Update(ctx, ammp)).To(Succeed())
189192
}, inputGetter().WaitForUpdate...).Should(Succeed())
193+
Eventually(checkTags, input.WaitForUpdate...).Should(Succeed())
190194

191195
Byf("Creating tags for machine pool %s", mp.Name)
192196
expectedTags = infrav1.Tags{
@@ -211,16 +215,14 @@ func AKSAdditionalTagsSpec(ctx context.Context, inputGetter func() AKSAdditional
211215
}, inputGetter().WaitForUpdate...).Should(Succeed())
212216
Eventually(checkTags, input.WaitForUpdate...).Should(Succeed())
213217

214-
if initialTags != nil {
215-
Byf("Restoring initial tags for machine pool %s", mp.Name)
216-
expectedTags = initialTags
217-
Eventually(func(g Gomega) {
218-
g.Expect(mgmtClient.Get(ctx, client.ObjectKeyFromObject(ammp), ammp)).To(Succeed())
219-
ammp.Spec.AdditionalTags = expectedTags
220-
g.Expect(mgmtClient.Update(ctx, ammp)).To(Succeed())
221-
}, inputGetter().WaitForUpdate...).Should(Succeed())
222-
Eventually(checkTags, input.WaitForUpdate...).Should(Succeed())
223-
}
218+
Byf("Restoring initial tags for machine pool %s", mp.Name)
219+
expectedTags = initialTags
220+
Eventually(func(g Gomega) {
221+
g.Expect(mgmtClient.Get(ctx, client.ObjectKeyFromObject(ammp), ammp)).To(Succeed())
222+
ammp.Spec.AdditionalTags = expectedTags
223+
g.Expect(mgmtClient.Update(ctx, ammp)).To(Succeed())
224+
}, inputGetter().WaitForUpdate...).Should(Succeed())
225+
Eventually(checkTags, input.WaitForUpdate...).Should(Succeed())
224226
}(mp)
225227
}
226228

0 commit comments

Comments
 (0)