@@ -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