Skip to content

Commit 6493363

Browse files
rebase #5720
1 parent ffdf7db commit 6493363

File tree

4 files changed

+45
-48
lines changed

4 files changed

+45
-48
lines changed

api/v1beta1/zz_generated.conversion.go

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta2/awsmachinetemplate_types.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ type AWSMachineTemplateStatus struct {
7575

7676
// Conditions defines current service state of the AWSMachineTemplate.
7777
// +optional
78-
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
78+
Conditions clusterv1beta1.Conditions `json:"conditions,omitempty"`
7979
}
8080

8181
// AWSMachineTemplateSpec defines the desired state of AWSMachineTemplate.
@@ -119,12 +119,12 @@ type AWSMachineTemplateResource struct {
119119
}
120120

121121
// GetConditions returns the observations of the operational state of the AWSMachineTemplate resource.
122-
func (r *AWSMachineTemplate) GetConditions() clusterv1.Conditions {
122+
func (r *AWSMachineTemplate) GetConditions() clusterv1beta1.Conditions {
123123
return r.Status.Conditions
124124
}
125125

126-
// SetConditions sets the underlying service state of the AWSMachineTemplate to the predescribed clusterv1.Conditions.
127-
func (r *AWSMachineTemplate) SetConditions(conditions clusterv1.Conditions) {
126+
// SetConditions sets the underlying service state of the AWSMachineTemplate to the predescribed clusterv1beta1.Conditions.
127+
func (r *AWSMachineTemplate) SetConditions(conditions clusterv1beta1.Conditions) {
128128
r.Status.Conditions = conditions
129129
}
130130

controllers/awsmachinetemplate_controller.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ import (
4141
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/logger"
4242
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/record"
4343
"sigs.k8s.io/cluster-api-provider-aws/v2/util/paused"
44-
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
45-
controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1"
44+
controlplanev1 "sigs.k8s.io/cluster-api/api/controlplane/kubeadm/v1beta2"
45+
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
4646
"sigs.k8s.io/cluster-api/util"
4747
"sigs.k8s.io/cluster-api/util/predicates"
4848
)
@@ -176,7 +176,7 @@ func (r *AWSMachineTemplateReconciler) getRegion(ctx context.Context, cluster *c
176176
}
177177

178178
// Get region from AWSCluster (standard EC2-based cluster)
179-
if cluster.Spec.InfrastructureRef != nil && cluster.Spec.InfrastructureRef.Kind == "AWSCluster" {
179+
if cluster.Spec.InfrastructureRef.IsDefined() && cluster.Spec.InfrastructureRef.Kind == "AWSCluster" {
180180
awsCluster := &infrav1.AWSCluster{}
181181
if err := r.Get(ctx, client.ObjectKey{
182182
Namespace: cluster.Namespace,
@@ -191,7 +191,7 @@ func (r *AWSMachineTemplateReconciler) getRegion(ctx context.Context, cluster *c
191191
}
192192

193193
// Get region from AWSManagedControlPlane (EKS cluster)
194-
if cluster.Spec.ControlPlaneRef != nil && cluster.Spec.ControlPlaneRef.Kind == "AWSManagedControlPlane" {
194+
if cluster.Spec.ControlPlaneRef.IsDefined() && cluster.Spec.ControlPlaneRef.Kind == "AWSManagedControlPlane" {
195195
awsManagedCP := &ekscontrolplanev1.AWSManagedControlPlane{}
196196
if err := r.Get(ctx, client.ObjectKey{
197197
Namespace: cluster.Namespace,
@@ -373,9 +373,10 @@ func (r *AWSMachineTemplateReconciler) getKubernetesVersion(ctx context.Context,
373373

374374
// Find MachineDeployments that reference this AWSMachineTemplate
375375
for _, md := range machineDeploymentList.Items {
376-
if version := ptr.Deref(md.Spec.Template.Spec.Version, ""); md.Spec.Template.Spec.InfrastructureRef.Kind == "AWSMachineTemplate" &&
377-
md.Spec.Template.Spec.InfrastructureRef.Name == template.Name && version != "" {
378-
return version, nil
376+
if md.Spec.Template.Spec.InfrastructureRef.Kind == "AWSMachineTemplate" &&
377+
md.Spec.Template.Spec.InfrastructureRef.Name == template.Name &&
378+
md.Spec.Template.Spec.Version != "" {
379+
return md.Spec.Template.Spec.Version, nil
379380
}
380381
}
381382

@@ -387,8 +388,8 @@ func (r *AWSMachineTemplateReconciler) getKubernetesVersion(ctx context.Context,
387388

388389
// Find KubeadmControlPlanes that reference this AWSMachineTemplate
389390
for _, kcp := range kcpList.Items {
390-
if kcp.Spec.MachineTemplate.InfrastructureRef.Kind == "AWSMachineTemplate" &&
391-
kcp.Spec.MachineTemplate.InfrastructureRef.Name == template.Name &&
391+
if kcp.Spec.MachineTemplate.Spec.InfrastructureRef.Kind == "AWSMachineTemplate" &&
392+
kcp.Spec.MachineTemplate.Spec.InfrastructureRef.Name == template.Name &&
392393
kcp.Spec.Version != "" {
393394
return kcp.Spec.Version, nil
394395
}

controllers/awsmachinetemplate_controller_unit_test.go

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ import (
2525
"k8s.io/apimachinery/pkg/api/resource"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727
"k8s.io/apimachinery/pkg/runtime"
28+
"k8s.io/utils/ptr"
2829
ctrl "sigs.k8s.io/controller-runtime"
2930
"sigs.k8s.io/controller-runtime/pkg/client"
3031
"sigs.k8s.io/controller-runtime/pkg/client/fake"
3132

3233
infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
33-
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
34+
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
3435
)
3536

3637
func TestAWSMachineTemplateReconciler(t *testing.T) {
@@ -75,10 +76,9 @@ func TestAWSMachineTemplateReconciler(t *testing.T) {
7576
Namespace: "default",
7677
},
7778
Spec: clusterv1.ClusterSpec{
78-
InfrastructureRef: &corev1.ObjectReference{
79-
Kind: "AWSCluster",
80-
Name: "test-aws-cluster",
81-
Namespace: "default",
79+
InfrastructureRef: clusterv1.ContractVersionedObjectReference{
80+
Kind: "AWSCluster",
81+
Name: "test-aws-cluster",
8282
},
8383
},
8484
}
@@ -143,10 +143,9 @@ func TestAWSMachineTemplateReconciler(t *testing.T) {
143143
Namespace: "default",
144144
},
145145
Spec: clusterv1.ClusterSpec{
146-
InfrastructureRef: &corev1.ObjectReference{
147-
Kind: "AWSCluster",
148-
Name: "test-aws-cluster",
149-
Namespace: "default",
146+
InfrastructureRef: clusterv1.ContractVersionedObjectReference{
147+
Kind: "AWSCluster",
148+
Name: "test-aws-cluster",
150149
},
151150
},
152151
}
@@ -190,7 +189,7 @@ func TestAWSMachineTemplateReconciler(t *testing.T) {
190189
})
191190

192191
g.Expect(err).To(BeNil())
193-
g.Expect(result.Requeue).To(BeFalse())
192+
g.Expect(result.RequeueAfter).To(BeZero())
194193
})
195194

196195
t.Run("should reconcile when capacity set but nodeInfo is not", func(t *testing.T) {
@@ -212,10 +211,9 @@ func TestAWSMachineTemplateReconciler(t *testing.T) {
212211
Namespace: "default",
213212
},
214213
Spec: clusterv1.ClusterSpec{
215-
InfrastructureRef: &corev1.ObjectReference{
216-
Kind: "AWSCluster",
217-
Name: "test-aws-cluster",
218-
Namespace: "default",
214+
InfrastructureRef: clusterv1.ContractVersionedObjectReference{
215+
Kind: "AWSCluster",
216+
Name: "test-aws-cluster",
219217
},
220218
},
221219
}
@@ -239,7 +237,7 @@ func TestAWSMachineTemplateReconciler(t *testing.T) {
239237
})
240238

241239
g.Expect(err).To(BeNil())
242-
g.Expect(result.Requeue).To(BeFalse())
240+
g.Expect(result.RequeueAfter).To(BeZero())
243241
})
244242

245243
t.Run("should skip when instance type is empty", func(t *testing.T) {
@@ -256,7 +254,7 @@ func TestAWSMachineTemplateReconciler(t *testing.T) {
256254
})
257255

258256
g.Expect(err).To(BeNil())
259-
g.Expect(result.Requeue).To(BeFalse())
257+
g.Expect(result.RequeueAfter).To(BeZero())
260258
})
261259

262260
t.Run("should not reconcile when cluster is paused", func(t *testing.T) {
@@ -275,11 +273,10 @@ func TestAWSMachineTemplateReconciler(t *testing.T) {
275273
Namespace: "default",
276274
},
277275
Spec: clusterv1.ClusterSpec{
278-
Paused: true,
279-
InfrastructureRef: &corev1.ObjectReference{
280-
Kind: "AWSCluster",
281-
Name: "test-aws-cluster",
282-
Namespace: "default",
276+
Paused: ptr.To(true),
277+
InfrastructureRef: clusterv1.ContractVersionedObjectReference{
278+
Kind: "AWSCluster",
279+
Name: "test-aws-cluster",
283280
},
284281
},
285282
}
@@ -302,7 +299,7 @@ func TestAWSMachineTemplateReconciler(t *testing.T) {
302299
})
303300

304301
g.Expect(err).To(BeNil())
305-
g.Expect(result.Requeue).To(BeFalse())
302+
g.Expect(result.RequeueAfter).To(BeZero())
306303
})
307304

308305
t.Run("should not reconcile when template has paused annotation", func(t *testing.T) {
@@ -322,10 +319,9 @@ func TestAWSMachineTemplateReconciler(t *testing.T) {
322319
Namespace: "default",
323320
},
324321
Spec: clusterv1.ClusterSpec{
325-
InfrastructureRef: &corev1.ObjectReference{
326-
Kind: "AWSCluster",
327-
Name: "test-aws-cluster",
328-
Namespace: "default",
322+
InfrastructureRef: clusterv1.ContractVersionedObjectReference{
323+
Kind: "AWSCluster",
324+
Name: "test-aws-cluster",
329325
},
330326
},
331327
}
@@ -348,7 +344,7 @@ func TestAWSMachineTemplateReconciler(t *testing.T) {
348344
})
349345

350346
g.Expect(err).To(BeNil())
351-
g.Expect(result.Requeue).To(BeFalse())
347+
g.Expect(result.RequeueAfter).To(BeZero())
352348
})
353349

354350
t.Run("should skip when no owner cluster", func(t *testing.T) {
@@ -364,7 +360,7 @@ func TestAWSMachineTemplateReconciler(t *testing.T) {
364360
})
365361

366362
g.Expect(err).To(BeNil())
367-
g.Expect(result.Requeue).To(BeFalse())
363+
g.Expect(result.RequeueAfter).To(BeZero())
368364
})
369365

370366
t.Run("should skip when region is empty", func(t *testing.T) {
@@ -393,7 +389,7 @@ func TestAWSMachineTemplateReconciler(t *testing.T) {
393389
})
394390

395391
g.Expect(err).To(BeNil())
396-
g.Expect(result.Requeue).To(BeFalse())
392+
g.Expect(result.RequeueAfter).To(BeZero())
397393
})
398394

399395
t.Run("should return nil when template not found", func(t *testing.T) {
@@ -411,7 +407,7 @@ func TestAWSMachineTemplateReconciler(t *testing.T) {
411407
})
412408

413409
g.Expect(err).To(BeNil())
414-
g.Expect(result.Requeue).To(BeFalse())
410+
g.Expect(result.RequeueAfter).To(BeZero())
415411
})
416412
})
417413
}

0 commit comments

Comments
 (0)