Skip to content

Commit b0477c1

Browse files
Fix review comments
1 parent 86fe072 commit b0477c1

File tree

4 files changed

+16
-40
lines changed

4 files changed

+16
-40
lines changed

api/v1beta2/awsmachinetemplate_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ import (
2525

2626
// Architecture represents the CPU architecture of the node.
2727
// Its underlying type is a string and its value can be any of amd64, arm64.
28-
// +kubebuilder:validation:Enum=amd64;arm64
29-
// +enum
3028
type Architecture string
3129

3230
// Architecture constants.
@@ -47,10 +45,12 @@ const (
4745
type NodeInfo struct {
4846
// Architecture is the CPU architecture of the node.
4947
// Its underlying type is a string and its value can be any of amd64, arm64.
48+
// +kubebuilder:validation:Enum=amd64;arm64
5049
// +optional
5150
Architecture Architecture `json:"architecture,omitempty"`
5251
// OperatingSystem is a string representing the operating system of the node.
5352
// This may be a string like 'linux' or 'windows'.
53+
// +kubebuilder:validation:Enum=linux;windows
5454
// +optional
5555
OperatingSystem string `json:"operatingSystem,omitempty"`
5656
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,9 @@ spec:
11741174
description: |-
11751175
OperatingSystem is a string representing the operating system of the node.
11761176
This may be a string like 'linux' or 'windows'.
1177+
enum:
1178+
- linux
1179+
- windows
11771180
type: string
11781181
type: object
11791182
type: object

controllers/awsmachinetemplate_controller.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@ type AWSMachineTemplateReconciler struct {
5252
WatchFilterValue string
5353
}
5454

55+
// SetupWithManager sets up the controller with the Manager.
56+
func (r *AWSMachineTemplateReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
57+
log := logger.FromContext(ctx)
58+
59+
return ctrl.NewControllerManagedBy(mgr).
60+
For(&infrav1.AWSMachineTemplate{}).
61+
WithOptions(options).
62+
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(mgr.GetScheme(), log.GetLogger(), r.WatchFilterValue)).
63+
Complete(r)
64+
}
65+
5566
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=awsmachinetemplates,verbs=get;list;watch
5667
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=awsmachinetemplates/status,verbs=get;update;patch
5768
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=awsclusters,verbs=get;list;watch
@@ -73,11 +84,6 @@ func (r *AWSMachineTemplateReconciler) Reconcile(ctx context.Context, req ctrl.R
7384
return ctrl.Result{}, err
7485
}
7586

76-
// Skip if capacity and nodeInfo are already set
77-
if len(awsMachineTemplate.Status.Capacity) > 0 && awsMachineTemplate.Status.NodeInfo != nil {
78-
return ctrl.Result{}, nil
79-
}
80-
8187
// Get instance type from spec
8288
instanceType := awsMachineTemplate.Spec.Template.Spec.InstanceType
8389
if instanceType == "" {
@@ -363,14 +369,3 @@ func (r *AWSMachineTemplateReconciler) getKubernetesVersion(ctx context.Context,
363369

364370
return "", errors.New("no MachineDeployment or KubeadmControlPlane found referencing this AWSMachineTemplate with a version")
365371
}
366-
367-
// SetupWithManager sets up the controller with the Manager.
368-
func (r *AWSMachineTemplateReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
369-
log := logger.FromContext(ctx)
370-
371-
return ctrl.NewControllerManagedBy(mgr).
372-
For(&infrav1.AWSMachineTemplate{}).
373-
WithOptions(options).
374-
WithEventFilter(predicates.ResourceHasFilterLabel(mgr.GetScheme(), log.GetLogger(), r.WatchFilterValue)).
375-
Complete(r)
376-
}

controllers/awsmachinetemplate_controller_unit_test.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -192,28 +192,6 @@ func TestAWSMachineTemplateReconciler(t *testing.T) {
192192
// integration tests.
193193

194194
t.Run("Reconcile", func(t *testing.T) {
195-
t.Run("should skip when capacity and nodeInfo already set", func(t *testing.T) {
196-
g := NewWithT(t)
197-
template := newAWSMachineTemplate("test-template")
198-
template.Status.Capacity = corev1.ResourceList{
199-
corev1.ResourceCPU: *resource.NewQuantity(2, resource.DecimalSI),
200-
}
201-
template.Status.NodeInfo = &infrav1.NodeInfo{
202-
Architecture: infrav1.ArchitectureAmd64,
203-
}
204-
205-
reconciler := &AWSMachineTemplateReconciler{
206-
Client: newFakeClient(template),
207-
}
208-
209-
result, err := reconciler.Reconcile(context.Background(), ctrl.Request{
210-
NamespacedName: client.ObjectKeyFromObject(template),
211-
})
212-
213-
g.Expect(err).To(BeNil())
214-
g.Expect(result.Requeue).To(BeFalse())
215-
})
216-
217195
t.Run("should reconcile when capacity set but nodeInfo is not", func(t *testing.T) {
218196
g := NewWithT(t)
219197
template := newAWSMachineTemplate("test-template")

0 commit comments

Comments
 (0)