Skip to content

Commit e1f427e

Browse files
Fix review comments 2
1 parent ddaf62c commit e1f427e

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

api/v1beta2/awsmachinetemplate_types.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,16 @@ const (
3333
ArchitectureArm64 Architecture = "arm64"
3434
)
3535

36+
// OperatingSystem represents the operating system of the node.
37+
// Its underlying type is a string and its value can be any of linux, windows.
38+
type OperatingSystem string
39+
3640
// Operating system constants.
3741
const (
3842
// OperatingSystemLinux represents the Linux operating system.
39-
OperatingSystemLinux = "linux"
43+
OperatingSystemLinux OperatingSystem = "linux"
4044
// OperatingSystemWindows represents the Windows operating system.
41-
OperatingSystemWindows = "windows"
45+
OperatingSystemWindows OperatingSystem = "windows"
4246
)
4347

4448
// NodeInfo contains information about the node's architecture and operating system.
@@ -48,11 +52,11 @@ type NodeInfo struct {
4852
// +kubebuilder:validation:Enum=amd64;arm64
4953
// +optional
5054
Architecture Architecture `json:"architecture,omitempty"`
51-
// OperatingSystem is a string representing the operating system of the node.
52-
// This may be a string like 'linux' or 'windows'.
55+
// OperatingSystem is the operating system of the node.
56+
// Its underlying type is a string and its value can be any of linux, windows.
5357
// +kubebuilder:validation:Enum=linux;windows
5458
// +optional
55-
OperatingSystem string `json:"operatingSystem,omitempty"`
59+
OperatingSystem OperatingSystem `json:"operatingSystem,omitempty"`
5660
}
5761

5862
// AWSMachineTemplateStatus defines a status for an AWSMachineTemplate.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,8 +1172,8 @@ spec:
11721172
type: string
11731173
operatingSystem:
11741174
description: |-
1175-
OperatingSystem is a string representing the operating system of the node.
1176-
This may be a string like 'linux' or 'windows'.
1175+
OperatingSystem is the operating system of the node.
1176+
Its underlying type is a string and its value can be any of linux, windows.
11771177
enum:
11781178
- linux
11791179
- windows

controllers/awsmachinetemplate_controller.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"sigs.k8s.io/controller-runtime/pkg/controller"
3333

3434
infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
35+
ekscontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/eks/api/v1beta2"
3536
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/scope"
3637
ec2service "sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/ec2"
3738
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/logger"
@@ -169,6 +170,21 @@ func (r *AWSMachineTemplateReconciler) getRegion(ctx context.Context, template *
169170
}
170171
}
171172

173+
// Get region from AWSManagedControlPlane (EKS cluster)
174+
if cluster.Spec.ControlPlaneRef != nil && cluster.Spec.ControlPlaneRef.Kind == "AWSManagedControlPlane" {
175+
awsManagedCP := &ekscontrolplanev1.AWSManagedControlPlane{}
176+
if err := r.Get(ctx, client.ObjectKey{
177+
Namespace: cluster.Namespace,
178+
Name: cluster.Spec.ControlPlaneRef.Name,
179+
}, awsManagedCP); err != nil {
180+
if !apierrors.IsNotFound(err) {
181+
return "", errors.Wrapf(err, "failed to get AWSManagedControlPlane %s/%s", cluster.Namespace, cluster.Spec.ControlPlaneRef.Name)
182+
}
183+
} else if awsManagedCP.Spec.Region != "" {
184+
return awsManagedCP.Spec.Region, nil
185+
}
186+
}
187+
172188
return "", nil
173189
}
174190

@@ -288,7 +304,7 @@ func (r *AWSMachineTemplateReconciler) getNodeInfo(ctx context.Context, ec2Clien
288304
}
289305

290306
// getNodeInfoFromAMI queries the AMI to determine architecture and operating system.
291-
func (r *AWSMachineTemplateReconciler) getNodeInfoFromAMI(ctx context.Context, ec2Client *ec2.Client, amiID string) (infrav1.Architecture, string, error) {
307+
func (r *AWSMachineTemplateReconciler) getNodeInfoFromAMI(ctx context.Context, ec2Client *ec2.Client, amiID string) (infrav1.Architecture, infrav1.OperatingSystem, error) {
292308
input := &ec2.DescribeImagesInput{
293309
ImageIds: []string{amiID},
294310
}
@@ -325,7 +341,7 @@ func (r *AWSMachineTemplateReconciler) getNodeInfoFromAMI(ctx context.Context, e
325341
// 2. Check PlatformDetails field for Windows indication
326342
if os != infrav1.OperatingSystemWindows && image.PlatformDetails != nil {
327343
platformDetails := strings.ToLower(*image.PlatformDetails)
328-
if strings.Contains(platformDetails, infrav1.OperatingSystemWindows) {
344+
if strings.Contains(platformDetails, string(infrav1.OperatingSystemWindows)) {
329345
os = infrav1.OperatingSystemWindows
330346
}
331347
}

0 commit comments

Comments
 (0)