Skip to content

Commit cef502c

Browse files
authored
Merge pull request #4781 from nojnhuh/v2-ready
ASOAPI: reconcile status.ready
2 parents 9f0c15a + d7c7b7a commit cef502c

12 files changed

+86
-0
lines changed

config/crd/bases/infrastructure.cluster.x-k8s.io_azureasomanagedclusters.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ spec:
7070
description: AzureASOManagedClusterStatus defines the observed state of
7171
AzureASOManagedCluster.
7272
properties:
73+
ready:
74+
description: |-
75+
Ready represents whether or not the cluster has been provisioned and is ready. It fulfills Cluster
76+
API's cluster infrastructure provider contract.
77+
type: boolean
7378
resources:
7479
items:
7580
description: ResourceStatus represents the status of a resource.

config/crd/bases/infrastructure.cluster.x-k8s.io_azureasomanagedcontrolplanes.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ spec:
7373
- host
7474
- port
7575
type: object
76+
initialized:
77+
description: |-
78+
Initialized represents whether or not the API server has been provisioned. It fulfills Cluster API's
79+
control plane provider contract. For AKS, this is equivalent to `ready`.
80+
type: boolean
81+
ready:
82+
description: |-
83+
Ready represents whether or not the API server is ready to receive requests. It fulfills Cluster API's
84+
control plane provider contract. For AKS, this is equivalent to `initialized`.
85+
type: boolean
7686
resources:
7787
items:
7888
description: ResourceStatus represents the status of a resource.

config/crd/bases/infrastructure.cluster.x-k8s.io_azureasomanagedmachinepools.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ spec:
6060
description: AzureASOManagedMachinePoolStatus defines the observed state
6161
of AzureASOManagedMachinePool.
6262
properties:
63+
ready:
64+
description: |-
65+
Ready represents whether or not the infrastructure is ready to be used. It fulfills Cluster API's
66+
machine pool infrastructure provider contract.
67+
type: boolean
6368
replicas:
6469
description: |-
6570
Replicas is the current number of provisioned replicas. It fulfills Cluster API's machine pool

exp/api/v1alpha1/azureasomanagedcluster_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ type AzureASOManagedClusterSpec struct {
4343

4444
// AzureASOManagedClusterStatus defines the observed state of AzureASOManagedCluster.
4545
type AzureASOManagedClusterStatus struct {
46+
// Ready represents whether or not the cluster has been provisioned and is ready. It fulfills Cluster
47+
// API's cluster infrastructure provider contract.
48+
//+optional
49+
Ready bool `json:"ready"`
50+
4651
//+optional
4752
Resources []ResourceStatus `json:"resources,omitempty"`
4853
}

exp/api/v1alpha1/azureasomanagedcontrolplane_types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ type AzureASOManagedControlPlaneSpec struct {
3131

3232
// AzureASOManagedControlPlaneStatus defines the observed state of AzureASOManagedControlPlane.
3333
type AzureASOManagedControlPlaneStatus struct {
34+
// Initialized represents whether or not the API server has been provisioned. It fulfills Cluster API's
35+
// control plane provider contract. For AKS, this is equivalent to `ready`.
36+
//+optional
37+
Initialized bool `json:"initialized"`
38+
39+
// Ready represents whether or not the API server is ready to receive requests. It fulfills Cluster API's
40+
// control plane provider contract. For AKS, this is equivalent to `initialized`.
41+
//+optional
42+
Ready bool `json:"ready"`
43+
3444
// Version is the observed Kubernetes version of the control plane. It fulfills Cluster API's control
3545
// plane provider contract.
3646
//+optional

exp/api/v1alpha1/azureasomanagedmachinepool_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ type AzureASOManagedMachinePoolStatus struct {
3535
//+optional
3636
Replicas int32 `json:"replicas"`
3737

38+
// Ready represents whether or not the infrastructure is ready to be used. It fulfills Cluster API's
39+
// machine pool infrastructure provider contract.
40+
//+optional
41+
Ready bool `json:"ready"`
42+
3843
//+optional
3944
Resources []ResourceStatus `json:"resources,omitempty"`
4045
}

exp/controllers/azureasomanagedcluster_controller.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ func (r *AzureASOManagedClusterReconciler) Reconcile(ctx context.Context, req ct
186186
}
187187
}()
188188

189+
asoManagedCluster.Status.Ready = false
190+
189191
cluster, err := util.GetOwnerCluster(ctx, r.Client, asoManagedCluster.ObjectMeta)
190192
if err != nil {
191193
return ctrl.Result{}, err
@@ -252,6 +254,8 @@ func (r *AzureASOManagedClusterReconciler) reconcileNormal(ctx context.Context,
252254
}
253255
asoManagedCluster.Spec.ControlPlaneEndpoint = asoManagedControlPlane.Status.ControlPlaneEndpoint
254256

257+
asoManagedCluster.Status.Ready = !asoManagedCluster.Spec.ControlPlaneEndpoint.IsZero()
258+
255259
return ctrl.Result{}, nil
256260
}
257261

exp/controllers/azureasomanagedcluster_controller_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ func TestAzureASOManagedClusterReconcile(t *testing.T) {
182182
clusterv1.ClusterFinalizer,
183183
},
184184
},
185+
Status: infrav1exp.AzureASOManagedClusterStatus{
186+
Ready: true,
187+
},
185188
}
186189
c := fakeClientBuilder().
187190
WithObjects(cluster, asoManagedCluster).
@@ -205,6 +208,9 @@ func TestAzureASOManagedClusterReconcile(t *testing.T) {
205208
result, err := r.Reconcile(ctx, ctrl.Request{NamespacedName: client.ObjectKeyFromObject(asoManagedCluster)})
206209
g.Expect(err).NotTo(HaveOccurred())
207210
g.Expect(result).To(Equal(ctrl.Result{}))
211+
212+
g.Expect(r.Get(ctx, client.ObjectKeyFromObject(asoManagedCluster), asoManagedCluster)).To(Succeed())
213+
g.Expect(asoManagedCluster.Status.Ready).To(BeFalse())
208214
})
209215

210216
t.Run("successfully reconciles normally", func(t *testing.T) {
@@ -239,6 +245,9 @@ func TestAzureASOManagedClusterReconcile(t *testing.T) {
239245
clusterv1.ClusterFinalizer,
240246
},
241247
},
248+
Status: infrav1exp.AzureASOManagedClusterStatus{
249+
Ready: false,
250+
},
242251
}
243252
asoManagedControlPlane := &infrav1exp.AzureASOManagedControlPlane{
244253
ObjectMeta: metav1.ObjectMeta{
@@ -268,6 +277,7 @@ func TestAzureASOManagedClusterReconcile(t *testing.T) {
268277

269278
g.Expect(c.Get(ctx, client.ObjectKeyFromObject(asoManagedCluster), asoManagedCluster)).To(Succeed())
270279
g.Expect(asoManagedCluster.Spec.ControlPlaneEndpoint.Host).To(Equal("endpoint"))
280+
g.Expect(asoManagedCluster.Status.Ready).To(BeTrue())
271281
})
272282

273283
t.Run("successfully reconciles pause", func(t *testing.T) {

exp/controllers/azureasomanagedcontrolplane_controller.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ func (r *AzureASOManagedControlPlaneReconciler) Reconcile(ctx context.Context, r
137137
}
138138
}()
139139

140+
asoManagedControlPlane.Status.Ready = false
141+
asoManagedControlPlane.Status.Initialized = false
142+
140143
cluster, err := util.GetOwnerCluster(ctx, r.Client, asoManagedControlPlane.ObjectMeta)
141144
if err != nil {
142145
return ctrl.Result{}, err
@@ -220,6 +223,11 @@ func (r *AzureASOManagedControlPlaneReconciler) reconcileNormal(ctx context.Cont
220223
return ctrl.Result{}, fmt.Errorf("failed to reconcile kubeconfig: %w", err)
221224
}
222225

226+
asoManagedControlPlane.Status.Ready = !asoManagedControlPlane.Status.ControlPlaneEndpoint.IsZero()
227+
// The AKS API doesn't allow us to distinguish between CAPI's definitions of "initialized" and "ready" so
228+
// we treat them equivalently.
229+
asoManagedControlPlane.Status.Initialized = asoManagedControlPlane.Status.Ready
230+
223231
return ctrl.Result{}, nil
224232
}
225233

exp/controllers/azureasomanagedcontrolplane_controller_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ func TestAzureASOManagedControlPlaneReconcile(t *testing.T) {
181181
},
182182
},
183183
},
184+
Status: infrav1exp.AzureASOManagedControlPlaneStatus{
185+
Ready: true,
186+
},
184187
}
185188
c := fakeClientBuilder().
186189
WithObjects(cluster, asoManagedControlPlane).
@@ -204,6 +207,9 @@ func TestAzureASOManagedControlPlaneReconcile(t *testing.T) {
204207
result, err := r.Reconcile(ctx, ctrl.Request{NamespacedName: client.ObjectKeyFromObject(asoManagedControlPlane)})
205208
g.Expect(err).NotTo(HaveOccurred())
206209
g.Expect(result).To(Equal(ctrl.Result{}))
210+
211+
g.Expect(c.Get(ctx, client.ObjectKeyFromObject(asoManagedControlPlane), asoManagedControlPlane)).To(Succeed())
212+
g.Expect(asoManagedControlPlane.Status.Ready).To(BeFalse())
207213
})
208214

209215
t.Run("successfully reconciles normally", func(t *testing.T) {
@@ -278,6 +284,9 @@ func TestAzureASOManagedControlPlaneReconcile(t *testing.T) {
278284
},
279285
},
280286
},
287+
Status: infrav1exp.AzureASOManagedControlPlaneStatus{
288+
Ready: false,
289+
},
281290
}
282291
c := fakeClientBuilder().
283292
WithObjects(cluster, asoManagedControlPlane, managedCluster, kubeconfig).
@@ -309,6 +318,7 @@ func TestAzureASOManagedControlPlaneReconcile(t *testing.T) {
309318
g.Expect(asoManagedControlPlane.Status.ControlPlaneEndpoint.Host).To(Equal("endpoint"))
310319
g.Expect(asoManagedControlPlane.Status.Version).To(Equal("vCurrent"))
311320
g.Expect(kubeConfigPatched).To(BeTrue())
321+
g.Expect(asoManagedControlPlane.Status.Ready).To(BeTrue())
312322
})
313323

314324
t.Run("successfully reconciles pause", func(t *testing.T) {

0 commit comments

Comments
 (0)