@@ -40,8 +40,9 @@ import (
4040 ec2service "sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/ec2"
4141 "sigs.k8s.io/cluster-api-provider-aws/v2/pkg/logger"
4242 "sigs.k8s.io/cluster-api-provider-aws/v2/pkg/record"
43- clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
44- controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1"
43+ "sigs.k8s.io/cluster-api-provider-aws/v2/util/paused"
44+ controlplanev1 "sigs.k8s.io/cluster-api/api/controlplane/kubeadm/v1beta2"
45+ clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
4546 "sigs.k8s.io/cluster-api/util"
4647 "sigs.k8s.io/cluster-api/util/predicates"
4748)
@@ -101,8 +102,22 @@ func (r *AWSMachineTemplateReconciler) Reconcile(ctx context.Context, req ctrl.R
101102 return ctrl.Result {}, nil
102103 }
103104
105+ // Get the owner cluster
106+ cluster , err := util .GetOwnerCluster (ctx , r .Client , awsMachineTemplate .ObjectMeta )
107+ if err != nil {
108+ return ctrl.Result {}, err
109+ }
110+ if cluster == nil {
111+ return ctrl.Result {}, nil
112+ }
113+
114+ // Check if the resource is paused
115+ if isPaused , conditionChanged , err := paused .EnsurePausedCondition (ctx , r .Client , cluster , awsMachineTemplate ); err != nil || isPaused || conditionChanged {
116+ return ctrl.Result {}, err
117+ }
118+
104119 // Find the region by checking ownerReferences
105- region , err := r .getRegion (ctx , awsMachineTemplate )
120+ region , err := r .getRegion (ctx , cluster )
106121 if err != nil {
107122 return ctrl.Result {}, err
108123 }
@@ -155,18 +170,13 @@ func (r *AWSMachineTemplateReconciler) Reconcile(ctx context.Context, req ctrl.R
155170}
156171
157172// getRegion finds the region by checking the template's owner cluster reference.
158- func (r * AWSMachineTemplateReconciler ) getRegion (ctx context.Context , template * infrav1.AWSMachineTemplate ) (string , error ) {
159- // Get the owner cluster
160- cluster , err := util .GetOwnerCluster (ctx , r .Client , template .ObjectMeta )
161- if err != nil {
162- return "" , err
163- }
173+ func (r * AWSMachineTemplateReconciler ) getRegion (ctx context.Context , cluster * clusterv1.Cluster ) (string , error ) {
164174 if cluster == nil {
165175 return "" , errors .New ("no owner cluster found" )
166176 }
167177
168178 // Get region from AWSCluster (standard EC2-based cluster)
169- if cluster .Spec .InfrastructureRef != nil && cluster .Spec .InfrastructureRef .Kind == "AWSCluster" {
179+ if cluster .Spec .InfrastructureRef . IsDefined () && cluster .Spec .InfrastructureRef .Kind == "AWSCluster" {
170180 awsCluster := & infrav1.AWSCluster {}
171181 if err := r .Get (ctx , client.ObjectKey {
172182 Namespace : cluster .Namespace ,
@@ -181,7 +191,7 @@ func (r *AWSMachineTemplateReconciler) getRegion(ctx context.Context, template *
181191 }
182192
183193 // Get region from AWSManagedControlPlane (EKS cluster)
184- if cluster .Spec .ControlPlaneRef != nil && cluster .Spec .ControlPlaneRef .Kind == "AWSManagedControlPlane" {
194+ if cluster .Spec .ControlPlaneRef . IsDefined () && cluster .Spec .ControlPlaneRef .Kind == "AWSManagedControlPlane" {
185195 awsManagedCP := & ekscontrolplanev1.AWSManagedControlPlane {}
186196 if err := r .Get (ctx , client.ObjectKey {
187197 Namespace : cluster .Namespace ,
@@ -363,9 +373,10 @@ func (r *AWSMachineTemplateReconciler) getKubernetesVersion(ctx context.Context,
363373
364374 // Find MachineDeployments that reference this AWSMachineTemplate
365375 for _ , md := range machineDeploymentList .Items {
366- if version := ptr .Deref (md .Spec .Template .Spec .Version , "" ); md .Spec .Template .Spec .InfrastructureRef .Kind == "AWSMachineTemplate" &&
367- md .Spec .Template .Spec .InfrastructureRef .Name == template .Name && version != "" {
368- 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
369380 }
370381 }
371382
@@ -377,8 +388,8 @@ func (r *AWSMachineTemplateReconciler) getKubernetesVersion(ctx context.Context,
377388
378389 // Find KubeadmControlPlanes that reference this AWSMachineTemplate
379390 for _ , kcp := range kcpList .Items {
380- if kcp .Spec .MachineTemplate .InfrastructureRef .Kind == "AWSMachineTemplate" &&
381- 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 &&
382393 kcp .Spec .Version != "" {
383394 return kcp .Spec .Version , nil
384395 }
0 commit comments