@@ -27,6 +27,7 @@ import (
27
27
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v4"
28
28
. "github.com/onsi/ginkgo/v2"
29
29
. "github.com/onsi/gomega"
30
+ "golang.org/x/exp/maps"
30
31
"k8s.io/apimachinery/pkg/types"
31
32
"k8s.io/utils/ptr"
32
33
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
@@ -107,10 +108,10 @@ func AKSAdditionalTagsSpec(ctx context.Context, inputGetter func() AKSAdditional
107
108
}, inputGetter ().WaitForUpdate ... ).Should (Succeed ())
108
109
109
110
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"
114
115
Eventually (func (g Gomega ) {
115
116
g .Expect (mgmtClient .Get (ctx , client .ObjectKeyFromObject (infraControlPlane ), infraControlPlane )).To (Succeed ())
116
117
infraControlPlane .Spec .AdditionalTags = expectedTags
@@ -129,16 +130,14 @@ func AKSAdditionalTagsSpec(ctx context.Context, inputGetter func() AKSAdditional
129
130
}, inputGetter ().WaitForUpdate ... ).Should (Succeed ())
130
131
Eventually (checkTags , input .WaitForUpdate ... ).Should (Succeed ())
131
132
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 ())
142
141
}()
143
142
144
143
for _ , mp := range input .MachinePools {
@@ -182,11 +181,16 @@ func AKSAdditionalTagsSpec(ctx context.Context, inputGetter func() AKSAdditional
182
181
}
183
182
}
184
183
184
+ Byf ("Deleting all tags for machine pool %s" , mp .Name )
185
+ expectedTags = nil
185
186
var initialTags infrav1.Tags
186
187
Eventually (func (g Gomega ) {
187
188
g .Expect (mgmtClient .Get (ctx , client .ObjectKeyFromObject (ammp ), ammp )).To (Succeed ())
188
189
initialTags = ammp .Spec .AdditionalTags
190
+ ammp .Spec .AdditionalTags = expectedTags
191
+ g .Expect (mgmtClient .Update (ctx , ammp )).To (Succeed ())
189
192
}, inputGetter ().WaitForUpdate ... ).Should (Succeed ())
193
+ Eventually (checkTags , input .WaitForUpdate ... ).Should (Succeed ())
190
194
191
195
Byf ("Creating tags for machine pool %s" , mp .Name )
192
196
expectedTags = infrav1.Tags {
@@ -211,16 +215,14 @@ func AKSAdditionalTagsSpec(ctx context.Context, inputGetter func() AKSAdditional
211
215
}, inputGetter ().WaitForUpdate ... ).Should (Succeed ())
212
216
Eventually (checkTags , input .WaitForUpdate ... ).Should (Succeed ())
213
217
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 ())
224
226
}(mp )
225
227
}
226
228
0 commit comments