Skip to content

Commit 2c63fbb

Browse files
committed
Add AWSMachines to back the ec2 instances in AWSMachinePools and AWSManagedMachinePools
1 parent f0c605e commit 2c63fbb

15 files changed

+485
-37
lines changed

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

+4
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,10 @@ spec:
11031103
can be added as events to the Machine object and/or logged in the
11041104
controller's output.
11051105
type: string
1106+
infrastructureMachineKind:
1107+
description: InfrastructureMachineKind is the kind of the infrastructure
1108+
resources behind MachinePool Machines.
1109+
type: string
11061110
instances:
11071111
description: Instances contains the status for each instance in the
11081112
pool

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

+4
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,10 @@ spec:
10431043
can be added as events to the MachinePool object and/or logged in the
10441044
controller's output.
10451045
type: string
1046+
infrastructureMachineKind:
1047+
description: InfrastructureMachineKind is the kind of the infrastructure
1048+
resources behind MachinePool Machines.
1049+
type: string
10461050
launchTemplateID:
10471051
description: The ID of the launch template
10481052
type: string

config/rbac/role.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ rules:
126126
- cluster.x-k8s.io
127127
resources:
128128
- machines
129+
verbs:
130+
- delete
131+
- get
132+
- list
133+
- watch
134+
- apiGroups:
135+
- cluster.x-k8s.io
136+
resources:
129137
- machines/status
130138
verbs:
131139
- get
@@ -310,6 +318,7 @@ rules:
310318
resources:
311319
- awsmachines
312320
verbs:
321+
- create
313322
- delete
314323
- get
315324
- list

controllers/awsmachine_controller.go

+17-7
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,11 @@ func (r *AWSMachineReconciler) getObjectStoreService(scope scope.S3Scope) servic
143143
return s3.NewService(scope)
144144
}
145145

146-
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=awsmachines,verbs=get;list;watch;update;patch;delete
147-
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=awsmachines/status,verbs=get;update;patch
148146
// +kubebuilder:rbac:groups=controlplane.cluster.x-k8s.io,resources=*,verbs=get;list;watch
149-
// +kubebuilder:rbac:groups=cluster.x-k8s.io,resources=machines;machines/status,verbs=get;list;watch
147+
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=awsmachines,verbs=create;get;list;watch;update;patch;delete
148+
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=awsmachines/status,verbs=get;update;patch
149+
// +kubebuilder:rbac:groups=cluster.x-k8s.io,resources=machines,verbs=get;list;watch;delete
150+
// +kubebuilder:rbac:groups=cluster.x-k8s.io,resources=machines/status,verbs=get;list;watch
150151
// +kubebuilder:rbac:groups="",resources=secrets;,verbs=get;list;watch
151152
// +kubebuilder:rbac:groups="",resources=namespaces,verbs=get;list;watch
152153
// +kubebuilder:rbac:groups="",resources=events,verbs=get;list;watch;create;update;patch
@@ -459,6 +460,7 @@ func (r *AWSMachineReconciler) findInstance(machineScope *scope.MachineScope, ec
459460
return instance, nil
460461
}
461462

463+
//nolint:gocyclo
462464
func (r *AWSMachineReconciler) reconcileNormal(_ context.Context, machineScope *scope.MachineScope, clusterScope cloud.ClusterScoper, ec2Scope scope.EC2Scope, elbScope scope.ELBScope, objectStoreScope scope.S3Scope) (ctrl.Result, error) {
463465
machineScope.Trace("Reconciling AWSMachine")
464466

@@ -482,7 +484,7 @@ func (r *AWSMachineReconciler) reconcileNormal(_ context.Context, machineScope *
482484
}
483485

484486
// Make sure bootstrap data is available and populated.
485-
if machineScope.Machine.Spec.Bootstrap.DataSecretName == nil {
487+
if !machineScope.IsMachinePoolMachine() && machineScope.Machine.Spec.Bootstrap.DataSecretName == nil {
486488
machineScope.Info("Bootstrap data secret reference is not yet available")
487489
conditions.MarkFalse(machineScope.AWSMachine, infrav1.InstanceReadyCondition, infrav1.WaitingForBootstrapDataReason, clusterv1.ConditionSeverityInfo, "")
488490
return ctrl.Result{}, nil
@@ -497,6 +499,12 @@ func (r *AWSMachineReconciler) reconcileNormal(_ context.Context, machineScope *
497499
conditions.MarkUnknown(machineScope.AWSMachine, infrav1.InstanceReadyCondition, infrav1.InstanceNotFoundReason, err.Error())
498500
return ctrl.Result{}, err
499501
}
502+
if instance == nil && machineScope.IsMachinePoolMachine() {
503+
err = errors.New("no instance found for machine pool")
504+
machineScope.Error(err, "unable to find instance")
505+
conditions.MarkUnknown(machineScope.AWSMachine, infrav1.InstanceReadyCondition, infrav1.InstanceNotFoundReason, err.Error())
506+
return ctrl.Result{}, err
507+
}
500508

501509
// If the AWSMachine doesn't have our finalizer, add it.
502510
if controllerutil.AddFinalizer(machineScope.AWSMachine, infrav1.MachineFinalizer) {
@@ -596,9 +604,11 @@ func (r *AWSMachineReconciler) reconcileNormal(_ context.Context, machineScope *
596604
}
597605

598606
// reconcile the deletion of the bootstrap data secret now that we have updated instance state
599-
if deleteSecretErr := r.deleteBootstrapData(machineScope, clusterScope, objectStoreScope); deleteSecretErr != nil {
600-
r.Log.Error(deleteSecretErr, "unable to delete secrets")
601-
return ctrl.Result{}, deleteSecretErr
607+
if !machineScope.IsMachinePoolMachine() {
608+
if deleteSecretErr := r.deleteBootstrapData(machineScope, clusterScope, objectStoreScope); deleteSecretErr != nil {
609+
r.Log.Error(deleteSecretErr, "unable to delete secrets")
610+
return ctrl.Result{}, deleteSecretErr
611+
}
602612
}
603613

604614
if instance.State == infrav1.InstanceStateTerminated {

exp/api/v1beta1/conversion.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func (src *AWSMachinePool) ConvertTo(dstRaw conversion.Hub) error {
5050
if restored.Spec.AvailabilityZoneSubnetType != nil {
5151
dst.Spec.AvailabilityZoneSubnetType = restored.Spec.AvailabilityZoneSubnetType
5252
}
53+
dst.Status.InfrastructureMachineKind = restored.Status.InfrastructureMachineKind
5354

5455
if restored.Spec.AWSLaunchTemplate.PrivateDNSName != nil {
5556
dst.Spec.AWSLaunchTemplate.PrivateDNSName = restored.Spec.AWSLaunchTemplate.PrivateDNSName
@@ -80,7 +81,6 @@ func (src *AWSMachinePoolList) ConvertTo(dstRaw conversion.Hub) error {
8081
// ConvertFrom converts the v1beta2 AWSMachinePoolList receiver to v1beta1 AWSMachinePoolList.
8182
func (r *AWSMachinePoolList) ConvertFrom(srcRaw conversion.Hub) error {
8283
src := srcRaw.(*infrav1exp.AWSMachinePoolList)
83-
8484
return Convert_v1beta2_AWSMachinePoolList_To_v1beta1_AWSMachinePoolList(src, r, nil)
8585
}
8686

@@ -110,6 +110,8 @@ func (src *AWSManagedMachinePool) ConvertTo(dstRaw conversion.Hub) error {
110110
dst.Spec.AvailabilityZoneSubnetType = restored.Spec.AvailabilityZoneSubnetType
111111
}
112112

113+
dst.Status.InfrastructureMachineKind = restored.Status.InfrastructureMachineKind
114+
113115
return nil
114116
}
115117

@@ -129,6 +131,14 @@ func Convert_v1beta2_AWSManagedMachinePoolSpec_To_v1beta1_AWSManagedMachinePoolS
129131
return autoConvert_v1beta2_AWSManagedMachinePoolSpec_To_v1beta1_AWSManagedMachinePoolSpec(in, out, s)
130132
}
131133

134+
func Convert_v1beta2_AWSMachinePoolStatus_To_v1beta1_AWSMachinePoolStatus(in *infrav1exp.AWSMachinePoolStatus, out *AWSMachinePoolStatus, s apiconversion.Scope) error {
135+
return autoConvert_v1beta2_AWSMachinePoolStatus_To_v1beta1_AWSMachinePoolStatus(in, out, s)
136+
}
137+
138+
func Convert_v1beta2_AWSManagedMachinePoolStatus_To_v1beta1_AWSManagedMachinePoolStatus(in *infrav1exp.AWSManagedMachinePoolStatus, out *AWSManagedMachinePoolStatus, s apiconversion.Scope) error {
139+
return autoConvert_v1beta2_AWSManagedMachinePoolStatus_To_v1beta1_AWSManagedMachinePoolStatus(in, out, s)
140+
}
141+
132142
// ConvertTo converts the v1beta1 AWSManagedMachinePoolList receiver to a v1beta2 AWSManagedMachinePoolList.
133143
func (src *AWSManagedMachinePoolList) ConvertTo(dstRaw conversion.Hub) error {
134144
dst := dstRaw.(*infrav1exp.AWSManagedMachinePoolList)

exp/api/v1beta1/zz_generated.conversion.go

+12-20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exp/api/v1beta2/awsmachinepool_types.go

+4
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ type AWSMachinePoolStatus struct {
199199
// +optional
200200
LaunchTemplateVersion *string `json:"launchTemplateVersion,omitempty"`
201201

202+
// InfrastructureMachineKind is the kind of the infrastructure resources behind MachinePool Machines.
203+
// +optional
204+
InfrastructureMachineKind string `json:"infrastructureMachineKind,omitempty"`
205+
202206
// FailureReason will be set in the event that there is a terminal problem
203207
// reconciling the Machine and will contain a succinct value suitable
204208
// for machine interpretation.

exp/api/v1beta2/awsmanagedmachinepool_types.go

+4
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ type AWSManagedMachinePoolStatus struct {
199199
// +optional
200200
LaunchTemplateVersion *string `json:"launchTemplateVersion,omitempty"`
201201

202+
// InfrastructureMachineKind is the kind of the infrastructure resources behind MachinePool Machines.
203+
// +optional
204+
InfrastructureMachineKind string `json:"infrastructureMachineKind,omitempty"`
205+
202206
// FailureReason will be set in the event that there is a terminal problem
203207
// reconciling the MachinePool and will contain a succinct value suitable
204208
// for machine interpretation.

exp/api/v1beta2/conditions_consts.go

+5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ const (
5454
InstanceRefreshNotReadyReason = "InstanceRefreshNotReady"
5555
// InstanceRefreshFailedReason used to report when there instance refresh is not initiated.
5656
InstanceRefreshFailedReason = "InstanceRefreshFailed"
57+
58+
// AWSMachineCreationFailed reports if creating AWSMachines to represent ASG (machine pool) machines failed.
59+
AWSMachineCreationFailed = "AWSMachineCreationFailed"
60+
// AWSMachineDeletionFailed reports if deleting AWSMachines failed.
61+
AWSMachineDeletionFailed = "AWSMachineDeletionFailed"
5762
)
5863

5964
const (

exp/api/v1beta2/types.go

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ import (
2222
infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
2323
)
2424

25+
const (
26+
// KindMachinePool is a MachinePool resource Kind
27+
KindMachinePool string = "MachinePool"
28+
)
29+
2530
// EBS can be used to automatically set up EBS volumes when an instance is launched.
2631
type EBS struct {
2732
// Encrypted is whether the volume should be encrypted or not.

0 commit comments

Comments
 (0)