Skip to content

Commit

Permalink
feat: custom lifecyclehooks for machinepools (#613)
Browse files Browse the repository at this point in the history
Backported from kubernetes-sigs#4875

Co-authored-by: Sebastien Michel <semichel@cisco.com>
  • Loading branch information
AndiDog and sebltm authored Dec 2, 2024
1 parent bf3472a commit 09d9674
Show file tree
Hide file tree
Showing 39 changed files with 1,187 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ func (t Template) ControllersPolicy() *iamv1.PolicyDocument {
"elasticloadbalancing:DeleteListener",
"autoscaling:DescribeAutoScalingGroups",
"autoscaling:DescribeInstanceRefreshes",
"autoscaling:DeleteLifecycleHook",
"autoscaling:DescribeLifecycleHooks",
"autoscaling:PutLifecycleHook",
"ec2:CreateLaunchTemplate",
"ec2:CreateLaunchTemplateVersion",
"ec2:DescribeLaunchTemplates",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ Resources:
- elasticloadbalancing:DeleteListener
- autoscaling:DescribeAutoScalingGroups
- autoscaling:DescribeInstanceRefreshes
- autoscaling:DeleteLifecycleHook
- autoscaling:DescribeLifecycleHooks
- autoscaling:PutLifecycleHook
- ec2:CreateLaunchTemplate
- ec2:CreateLaunchTemplateVersion
- ec2:DescribeLaunchTemplates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ Resources:
- elasticloadbalancing:DeleteListener
- autoscaling:DescribeAutoScalingGroups
- autoscaling:DescribeInstanceRefreshes
- autoscaling:DeleteLifecycleHook
- autoscaling:DescribeLifecycleHooks
- autoscaling:PutLifecycleHook
- ec2:CreateLaunchTemplate
- ec2:CreateLaunchTemplateVersion
- ec2:DescribeLaunchTemplates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ Resources:
- elasticloadbalancing:DeleteListener
- autoscaling:DescribeAutoScalingGroups
- autoscaling:DescribeInstanceRefreshes
- autoscaling:DeleteLifecycleHook
- autoscaling:DescribeLifecycleHooks
- autoscaling:PutLifecycleHook
- ec2:CreateLaunchTemplate
- ec2:CreateLaunchTemplateVersion
- ec2:DescribeLaunchTemplates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ Resources:
- elasticloadbalancing:DeleteListener
- autoscaling:DescribeAutoScalingGroups
- autoscaling:DescribeInstanceRefreshes
- autoscaling:DeleteLifecycleHook
- autoscaling:DescribeLifecycleHooks
- autoscaling:PutLifecycleHook
- ec2:CreateLaunchTemplate
- ec2:CreateLaunchTemplateVersion
- ec2:DescribeLaunchTemplates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ Resources:
- elasticloadbalancing:DeleteListener
- autoscaling:DescribeAutoScalingGroups
- autoscaling:DescribeInstanceRefreshes
- autoscaling:DeleteLifecycleHook
- autoscaling:DescribeLifecycleHooks
- autoscaling:PutLifecycleHook
- ec2:CreateLaunchTemplate
- ec2:CreateLaunchTemplateVersion
- ec2:DescribeLaunchTemplates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ Resources:
- elasticloadbalancing:DeleteListener
- autoscaling:DescribeAutoScalingGroups
- autoscaling:DescribeInstanceRefreshes
- autoscaling:DeleteLifecycleHook
- autoscaling:DescribeLifecycleHooks
- autoscaling:PutLifecycleHook
- ec2:CreateLaunchTemplate
- ec2:CreateLaunchTemplateVersion
- ec2:DescribeLaunchTemplates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ Resources:
- elasticloadbalancing:DeleteListener
- autoscaling:DescribeAutoScalingGroups
- autoscaling:DescribeInstanceRefreshes
- autoscaling:DeleteLifecycleHook
- autoscaling:DescribeLifecycleHooks
- autoscaling:PutLifecycleHook
- ec2:CreateLaunchTemplate
- ec2:CreateLaunchTemplateVersion
- ec2:DescribeLaunchTemplates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ Resources:
- elasticloadbalancing:DeleteListener
- autoscaling:DescribeAutoScalingGroups
- autoscaling:DescribeInstanceRefreshes
- autoscaling:DeleteLifecycleHook
- autoscaling:DescribeLifecycleHooks
- autoscaling:PutLifecycleHook
- ec2:CreateLaunchTemplate
- ec2:CreateLaunchTemplateVersion
- ec2:DescribeLaunchTemplates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ Resources:
- elasticloadbalancing:DeleteListener
- autoscaling:DescribeAutoScalingGroups
- autoscaling:DescribeInstanceRefreshes
- autoscaling:DeleteLifecycleHook
- autoscaling:DescribeLifecycleHooks
- autoscaling:PutLifecycleHook
- ec2:CreateLaunchTemplate
- ec2:CreateLaunchTemplateVersion
- ec2:DescribeLaunchTemplates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ Resources:
- elasticloadbalancing:DeleteListener
- autoscaling:DescribeAutoScalingGroups
- autoscaling:DescribeInstanceRefreshes
- autoscaling:DeleteLifecycleHook
- autoscaling:DescribeLifecycleHooks
- autoscaling:PutLifecycleHook
- ec2:CreateLaunchTemplate
- ec2:CreateLaunchTemplateVersion
- ec2:DescribeLaunchTemplates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ Resources:
- elasticloadbalancing:DeleteListener
- autoscaling:DescribeAutoScalingGroups
- autoscaling:DescribeInstanceRefreshes
- autoscaling:DeleteLifecycleHook
- autoscaling:DescribeLifecycleHooks
- autoscaling:PutLifecycleHook
- ec2:CreateLaunchTemplate
- ec2:CreateLaunchTemplateVersion
- ec2:DescribeLaunchTemplates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ Resources:
- elasticloadbalancing:DeleteListener
- autoscaling:DescribeAutoScalingGroups
- autoscaling:DescribeInstanceRefreshes
- autoscaling:DeleteLifecycleHook
- autoscaling:DescribeLifecycleHooks
- autoscaling:PutLifecycleHook
- ec2:CreateLaunchTemplate
- ec2:CreateLaunchTemplateVersion
- ec2:DescribeLaunchTemplates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ Resources:
- elasticloadbalancing:DeleteListener
- autoscaling:DescribeAutoScalingGroups
- autoscaling:DescribeInstanceRefreshes
- autoscaling:DeleteLifecycleHook
- autoscaling:DescribeLifecycleHooks
- autoscaling:PutLifecycleHook
- ec2:CreateLaunchTemplate
- ec2:CreateLaunchTemplateVersion
- ec2:DescribeLaunchTemplates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ Resources:
- elasticloadbalancing:DeleteListener
- autoscaling:DescribeAutoScalingGroups
- autoscaling:DescribeInstanceRefreshes
- autoscaling:DeleteLifecycleHook
- autoscaling:DescribeLifecycleHooks
- autoscaling:PutLifecycleHook
- ec2:CreateLaunchTemplate
- ec2:CreateLaunchTemplateVersion
- ec2:DescribeLaunchTemplates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,55 @@ spec:
- "3.4"
type: string
type: object
lifecycleHooks:
description: AWSLifecycleHooks specifies lifecycle hooks for the autoscaling
group.
items:
description: AWSLifecycleHook describes an AWS lifecycle hook
properties:
defaultResult:
description: The default result for the lifecycle hook. The
possible values are CONTINUE and ABANDON.
enum:
- CONTINUE
- ABANDON
type: string
heartbeatTimeout:
description: |-
The maximum time, in seconds, that an instance can remain in a Pending:Wait or
Terminating:Wait state. The maximum is 172800 seconds (48 hours) or 100 times
HeartbeatTimeout, whichever is smaller.
format: duration
type: string
lifecycleTransition:
description: The state of the EC2 instance to which to attach
the lifecycle hook.
enum:
- autoscaling:EC2_INSTANCE_LAUNCHING
- autoscaling:EC2_INSTANCE_TERMINATING
type: string
name:
description: The name of the lifecycle hook.
type: string
notificationMetadata:
description: Contains additional metadata that will be passed
to the notification target.
type: string
notificationTargetARN:
description: |-
The ARN of the notification target that Amazon EC2 Auto Scaling uses to
notify you when an instance is in the transition state for the lifecycle hook.
type: string
roleARN:
description: |-
The ARN of the IAM role that allows the Auto Scaling group to publish to the
specified notification target.
type: string
required:
- lifecycleTransition
- name
type: object
type: array
maxSize:
default: 1
description: MaxSize defines the maximum size of the group.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,55 @@ spec:
type: string
description: Labels specifies labels for the Kubernetes node objects
type: object
lifecycleHooks:
description: AWSLifecycleHooks specifies lifecycle hooks for the managed
node group.
items:
description: AWSLifecycleHook describes an AWS lifecycle hook
properties:
defaultResult:
description: The default result for the lifecycle hook. The
possible values are CONTINUE and ABANDON.
enum:
- CONTINUE
- ABANDON
type: string
heartbeatTimeout:
description: |-
The maximum time, in seconds, that an instance can remain in a Pending:Wait or
Terminating:Wait state. The maximum is 172800 seconds (48 hours) or 100 times
HeartbeatTimeout, whichever is smaller.
format: duration
type: string
lifecycleTransition:
description: The state of the EC2 instance to which to attach
the lifecycle hook.
enum:
- autoscaling:EC2_INSTANCE_LAUNCHING
- autoscaling:EC2_INSTANCE_TERMINATING
type: string
name:
description: The name of the lifecycle hook.
type: string
notificationMetadata:
description: Contains additional metadata that will be passed
to the notification target.
type: string
notificationTargetARN:
description: |-
The ARN of the notification target that Amazon EC2 Auto Scaling uses to
notify you when an instance is in the transition state for the lifecycle hook.
type: string
roleARN:
description: |-
The ARN of the IAM role that allows the Auto Scaling group to publish to the
specified notification target.
type: string
required:
- lifecycleTransition
- name
type: object
type: array
providerIDList:
description: |-
ProviderIDList are the provider IDs of instances in the
Expand Down
6 changes: 6 additions & 0 deletions exp/api/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ func (src *AWSMachinePool) ConvertTo(dstRaw conversion.Hub) error {
if restored.Spec.Ignition != nil {
dst.Spec.Ignition = restored.Spec.Ignition
}
if restored.Spec.AWSLifecycleHooks != nil {
dst.Spec.AWSLifecycleHooks = restored.Spec.AWSLifecycleHooks
}

if restored.Spec.AWSLaunchTemplate.PrivateDNSName != nil {
dst.Spec.AWSLaunchTemplate.PrivateDNSName = restored.Spec.AWSLaunchTemplate.PrivateDNSName
Expand Down Expand Up @@ -116,6 +119,9 @@ func (src *AWSManagedMachinePool) ConvertTo(dstRaw conversion.Hub) error {
if restored.Spec.AvailabilityZoneSubnetType != nil {
dst.Spec.AvailabilityZoneSubnetType = restored.Spec.AvailabilityZoneSubnetType
}
if restored.Spec.AWSLifecycleHooks != nil {
dst.Spec.AWSLifecycleHooks = restored.Spec.AWSLifecycleHooks
}

return nil
}
Expand Down
2 changes: 2 additions & 0 deletions exp/api/v1beta1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions exp/api/v1beta2/awsmachinepool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ type AWSMachinePoolSpec struct {
// Ignition defined options related to the bootstrapping systems where Ignition is used.
// +optional
Ignition *infrav1.Ignition `json:"ignition,omitempty"`

// AWSLifecycleHooks specifies lifecycle hooks for the autoscaling group.
// +optional
AWSLifecycleHooks []AWSLifecycleHook `json:"lifecycleHooks,omitempty"`
}

// SuspendProcessesTypes contains user friendly auto-completable values for suspended process names.
Expand Down
6 changes: 6 additions & 0 deletions exp/api/v1beta2/awsmachinepool_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ func (r *AWSMachinePool) validateIgnition() field.ErrorList {
return allErrs
}

func (r *AWSMachinePool) validateLifecycleHooks() field.ErrorList {
return validateLifecycleHooks(r.Spec.AWSLifecycleHooks)
}

// ValidateCreate will do any extra validation when creating a AWSMachinePool.
func (r *AWSMachinePool) ValidateCreate() (admission.Warnings, error) {
log.Info("AWSMachinePool validate create", "machine-pool", klog.KObj(r))
Expand All @@ -194,6 +198,7 @@ func (r *AWSMachinePool) ValidateCreate() (admission.Warnings, error) {
allErrs = append(allErrs, r.validateSpotInstances()...)
allErrs = append(allErrs, r.validateRefreshPreferences()...)
allErrs = append(allErrs, r.validateIgnition()...)
allErrs = append(allErrs, r.validateLifecycleHooks()...)

if len(allErrs) == 0 {
return nil, nil
Expand All @@ -216,6 +221,7 @@ func (r *AWSMachinePool) ValidateUpdate(_ runtime.Object) (admission.Warnings, e
allErrs = append(allErrs, r.validateAdditionalSecurityGroups()...)
allErrs = append(allErrs, r.validateSpotInstances()...)
allErrs = append(allErrs, r.validateRefreshPreferences()...)
allErrs = append(allErrs, r.validateLifecycleHooks()...)

if len(allErrs) == 0 {
return nil, nil
Expand Down
Loading

0 comments on commit 09d9674

Please sign in to comment.