Skip to content

Commit ddaf62c

Browse files
Fix review comments
1 parent 86fe072 commit ddaf62c

File tree

5 files changed

+18
-44
lines changed

5 files changed

+18
-44
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

config/rbac/role.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ rules:
101101
- controlplane.cluster.x-k8s.io
102102
resources:
103103
- '*'
104-
- kubeadmcontrolplanes
105104
verbs:
106105
- get
107106
- list

controllers/awsmachinetemplate_controller.go

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package controllers
1818

1919
import (
2020
"context"
21+
"fmt"
2122
"strings"
2223

2324
"github.com/aws/aws-sdk-go-v2/service/ec2"
@@ -52,12 +53,22 @@ type AWSMachineTemplateReconciler struct {
5253
WatchFilterValue string
5354
}
5455

56+
// SetupWithManager sets up the controller with the Manager.
57+
func (r *AWSMachineTemplateReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
58+
log := logger.FromContext(ctx)
59+
60+
return ctrl.NewControllerManagedBy(mgr).
61+
For(&infrav1.AWSMachineTemplate{}).
62+
WithOptions(options).
63+
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(mgr.GetScheme(), log.GetLogger(), r.WatchFilterValue)).
64+
Complete(r)
65+
}
66+
5567
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=awsmachinetemplates,verbs=get;list;watch
5668
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=awsmachinetemplates/status,verbs=get;update;patch
5769
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=awsclusters,verbs=get;list;watch
5870
// +kubebuilder:rbac:groups=cluster.x-k8s.io,resources=clusters,verbs=get;list;watch
5971
// +kubebuilder:rbac:groups=cluster.x-k8s.io,resources=machinedeployments,verbs=get;list;watch
60-
// +kubebuilder:rbac:groups=controlplane.cluster.x-k8s.io,resources=kubeadmcontrolplanes,verbs=get;list;watch
6172
// +kubebuilder:rbac:groups="",resources=events,verbs=get;list;watch;create;update;patch
6273

6374
// Reconcile populates capacity information for AWSMachineTemplate.
@@ -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 == "" {
@@ -194,8 +200,7 @@ func (r *AWSMachineTemplateReconciler) getInstanceTypeCapacity(ctx context.Conte
194200

195201
// Memory
196202
if info.MemoryInfo != nil && info.MemoryInfo.SizeInMiB != nil {
197-
memoryBytes := *info.MemoryInfo.SizeInMiB * 1024 * 1024
198-
resourceList[corev1.ResourceMemory] = *resource.NewQuantity(memoryBytes, resource.BinarySI)
203+
resourceList[corev1.ResourceMemory] = resource.MustParse(fmt.Sprintf("%dMi", *info.MemoryInfo.SizeInMiB))
199204
}
200205

201206
return resourceList, nil
@@ -363,14 +368,3 @@ func (r *AWSMachineTemplateReconciler) getKubernetesVersion(ctx context.Context,
363368

364369
return "", errors.New("no MachineDeployment or KubeadmControlPlane found referencing this AWSMachineTemplate with a version")
365370
}
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)