@@ -30,6 +30,7 @@ import (
30
30
"k8s.io/apimachinery/pkg/types"
31
31
infrav1exp "sigs.k8s.io/cluster-api-provider-azure/exp/api/v1alpha1"
32
32
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
33
+ clusterctlv1 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3"
33
34
ctrl "sigs.k8s.io/controller-runtime"
34
35
"sigs.k8s.io/controller-runtime/pkg/client"
35
36
fakeclient "sigs.k8s.io/controller-runtime/pkg/client/fake"
@@ -38,6 +39,7 @@ import (
38
39
type fakeResourceReconciler struct {
39
40
owner client.Object
40
41
reconcileFunc func (context.Context , client.Object ) error
42
+ pauseFunc func (context.Context , client.Object ) error
41
43
deleteFunc func (context.Context , client.Object ) error
42
44
}
43
45
@@ -48,6 +50,13 @@ func (r *fakeResourceReconciler) Reconcile(ctx context.Context) error {
48
50
return r .reconcileFunc (ctx , r .owner )
49
51
}
50
52
53
+ func (r * fakeResourceReconciler ) Pause (ctx context.Context ) error {
54
+ if r .pauseFunc == nil {
55
+ return nil
56
+ }
57
+ return r .pauseFunc (ctx , r .owner )
58
+ }
59
+
51
60
func (r * fakeResourceReconciler ) Delete (ctx context.Context ) error {
52
61
if r .deleteFunc == nil {
53
62
return nil
@@ -110,7 +119,7 @@ func TestAzureASOManagedClusterReconcile(t *testing.T) {
110
119
g .Expect (err ).To (HaveOccurred ())
111
120
})
112
121
113
- t .Run ("adds a finalizer" , func (t * testing.T ) {
122
+ t .Run ("adds a finalizer and block-move annotation " , func (t * testing.T ) {
114
123
g := NewGomegaWithT (t )
115
124
116
125
cluster := & clusterv1.Cluster {
@@ -150,6 +159,7 @@ func TestAzureASOManagedClusterReconcile(t *testing.T) {
150
159
151
160
g .Expect (c .Get (ctx , client .ObjectKeyFromObject (asoManagedCluster ), asoManagedCluster )).To (Succeed ())
152
161
g .Expect (asoManagedCluster .GetFinalizers ()).To (ContainElement (clusterv1 .ClusterFinalizer ))
162
+ g .Expect (asoManagedCluster .GetAnnotations ()).To (HaveKey (clusterctlv1 .BlockMoveAnnotation ))
153
163
})
154
164
155
165
t .Run ("reconciles resources that are not ready" , func (t * testing.T ) {
@@ -181,6 +191,9 @@ func TestAzureASOManagedClusterReconcile(t *testing.T) {
181
191
Finalizers : []string {
182
192
clusterv1 .ClusterFinalizer ,
183
193
},
194
+ Annotations : map [string ]string {
195
+ clusterctlv1 .BlockMoveAnnotation : "true" ,
196
+ },
184
197
},
185
198
Status : infrav1exp.AzureASOManagedClusterStatus {
186
199
Ready : true ,
@@ -244,6 +257,9 @@ func TestAzureASOManagedClusterReconcile(t *testing.T) {
244
257
Finalizers : []string {
245
258
clusterv1 .ClusterFinalizer ,
246
259
},
260
+ Annotations : map [string ]string {
261
+ clusterctlv1 .BlockMoveAnnotation : "true" ,
262
+ },
247
263
},
248
264
Status : infrav1exp.AzureASOManagedClusterStatus {
249
265
Ready : false ,
@@ -303,17 +319,30 @@ func TestAzureASOManagedClusterReconcile(t *testing.T) {
303
319
Name : cluster .Name ,
304
320
},
305
321
},
322
+ Annotations : map [string ]string {
323
+ clusterctlv1 .BlockMoveAnnotation : "true" ,
324
+ },
306
325
},
307
326
}
308
327
c := fakeClientBuilder ().
309
328
WithObjects (cluster , asoManagedCluster ).
310
329
Build ()
311
330
r := & AzureASOManagedClusterReconciler {
312
331
Client : c ,
332
+ newResourceReconciler : func (_ * infrav1exp.AzureASOManagedCluster , _ []* unstructured.Unstructured ) resourceReconciler {
333
+ return & fakeResourceReconciler {
334
+ pauseFunc : func (_ context.Context , _ client.Object ) error {
335
+ return nil
336
+ },
337
+ }
338
+ },
313
339
}
314
340
result , err := r .Reconcile (ctx , ctrl.Request {NamespacedName : client .ObjectKeyFromObject (asoManagedCluster )})
315
341
g .Expect (err ).NotTo (HaveOccurred ())
316
342
g .Expect (result ).To (Equal (ctrl.Result {}))
343
+
344
+ g .Expect (c .Get (ctx , client .ObjectKeyFromObject (asoManagedCluster ), asoManagedCluster )).To (Succeed ())
345
+ g .Expect (asoManagedCluster .GetAnnotations ()).NotTo (HaveKey (clusterctlv1 .BlockMoveAnnotation ))
317
346
})
318
347
319
348
t .Run ("successfully reconciles in-progress delete" , func (t * testing.T ) {
0 commit comments