Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨feat(awsmachinepool): custom lifecyclehooks for machinepools #4875

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
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 @@ -883,6 +883,55 @@ spec:
after it enters the InService state.
If no value is supplied by user a default value of 300 seconds is set
type: string
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
sebltm marked this conversation as resolved.
Show resolved Hide resolved
- 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 @@ -52,6 +52,9 @@ func (src *AWSMachinePool) 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
}

if restored.Spec.AWSLaunchTemplate.PrivateDNSName != nil {
dst.Spec.AWSLaunchTemplate.PrivateDNSName = restored.Spec.AWSLaunchTemplate.PrivateDNSName
Expand Down Expand Up @@ -113,6 +116,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 @@ -101,6 +101,10 @@ type AWSMachinePoolSpec struct {
// SuspendProcesses defines a list of processes to suspend for the given ASG. This is constantly reconciled.
// If a process is removed from this list it will automatically be resumed.
SuspendProcesses *SuspendProcessesTypes `json:"suspendProcesses,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 @@ -162,6 +162,10 @@ func (r *AWSMachinePool) validateRefreshPreferences() 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 @@ -176,6 +180,7 @@ func (r *AWSMachinePool) ValidateCreate() (admission.Warnings, error) {
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 All @@ -198,6 +203,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
Loading