mirror of https://github.com/kubernetes/kops.git
Delete disabled lifecycle hooks and implement disable logic for warmpools
This commit is contained in:
parent
161d30b743
commit
7a48391172
|
|
@ -88,10 +88,9 @@ func (b *AutoscalingGroupModelBuilder) Build(c *fi.ModelBuilderContext) error {
|
||||||
}
|
}
|
||||||
tsk.LaunchTemplate = task
|
tsk.LaunchTemplate = task
|
||||||
c.AddTask(tsk)
|
c.AddTask(tsk)
|
||||||
}
|
|
||||||
|
|
||||||
warmPool := b.Cluster.Spec.WarmPool.ResolveDefaults(ig)
|
warmPool := b.Cluster.Spec.WarmPool.ResolveDefaults(ig)
|
||||||
{
|
|
||||||
enabled := fi.Bool(warmPool.IsEnabled())
|
enabled := fi.Bool(warmPool.IsEnabled())
|
||||||
warmPoolTask := &awstasks.WarmPool{
|
warmPoolTask := &awstasks.WarmPool{
|
||||||
Name: &name,
|
Name: &name,
|
||||||
|
|
@ -102,30 +101,30 @@ func (b *AutoscalingGroupModelBuilder) Build(c *fi.ModelBuilderContext) error {
|
||||||
warmPoolTask.MinSize = warmPool.MinSize
|
warmPoolTask.MinSize = warmPool.MinSize
|
||||||
warmPoolTask.MaxSize = warmPool.MaxSize
|
warmPoolTask.MaxSize = warmPool.MaxSize
|
||||||
|
|
||||||
if warmPool.EnableLifecycleHook {
|
}
|
||||||
|
c.AddTask(warmPoolTask)
|
||||||
|
|
||||||
hookName := "kops-warmpool"
|
hookName := "kops-warmpool"
|
||||||
name := fmt.Sprintf("%s-%s", hookName, ig.GetName())
|
name := fmt.Sprintf("%s-%s", hookName, ig.GetName())
|
||||||
|
enableHook := warmPool.IsEnabled() && warmPool.EnableLifecycleHook
|
||||||
|
|
||||||
lifecyleTask := &awstasks.AutoscalingLifecycleHook{
|
lifecyleTask := &awstasks.AutoscalingLifecycleHook{
|
||||||
ID: aws.String(name),
|
ID: aws.String(name),
|
||||||
Name: aws.String(name),
|
Name: aws.String(name),
|
||||||
HookName: aws.String(hookName),
|
HookName: aws.String(hookName),
|
||||||
Lifecycle: b.Lifecycle,
|
|
||||||
AutoscalingGroup: b.LinkToAutoscalingGroup(ig),
|
AutoscalingGroup: b.LinkToAutoscalingGroup(ig),
|
||||||
|
Lifecycle: b.Lifecycle,
|
||||||
DefaultResult: aws.String("ABANDON"),
|
DefaultResult: aws.String("ABANDON"),
|
||||||
// We let nodeup have 10 min to complete. Normally this should happen much faster,
|
// We let nodeup have 10 min to complete. Normally this should happen much faster,
|
||||||
// but CP nodes need 5 min or so to start on new clusters, and we need to wait for that.
|
// but CP nodes need 5 min or so to start on new clusters, and we need to wait for that.
|
||||||
HeartbeatTimeout: aws.Int64(600),
|
HeartbeatTimeout: aws.Int64(600),
|
||||||
LifecycleTransition: aws.String("autoscaling:EC2_INSTANCE_LAUNCHING"),
|
LifecycleTransition: aws.String("autoscaling:EC2_INSTANCE_LAUNCHING"),
|
||||||
|
Enabled: &enableHook,
|
||||||
}
|
}
|
||||||
|
|
||||||
c.AddTask(lifecyleTask)
|
c.AddTask(lifecyleTask)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
c.AddTask(warmPoolTask)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,7 @@ func (b *NodeTerminationHandlerBuilder) configureASG(c *fi.ModelBuilderContext,
|
||||||
DefaultResult: aws.String("CONTINUE"),
|
DefaultResult: aws.String("CONTINUE"),
|
||||||
HeartbeatTimeout: aws.Int64(DefaultMessageRetentionPeriod),
|
HeartbeatTimeout: aws.Int64(DefaultMessageRetentionPeriod),
|
||||||
LifecycleTransition: aws.String("autoscaling:EC2_INSTANCE_TERMINATING"),
|
LifecycleTransition: aws.String("autoscaling:EC2_INSTANCE_TERMINATING"),
|
||||||
|
Enabled: aws.Bool(true),
|
||||||
}
|
}
|
||||||
|
|
||||||
c.AddTask(lifecyleTask)
|
c.AddTask(lifecyleTask)
|
||||||
|
|
|
||||||
|
|
@ -225,3 +225,4 @@ spec:
|
||||||
nodes: public
|
nodes: public
|
||||||
warmPool:
|
warmPool:
|
||||||
enableLifecycleHook: true
|
enableLifecycleHook: true
|
||||||
|
maxSize: 1
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ spec:
|
||||||
zone: us-test-1a
|
zone: us-test-1a
|
||||||
warmPool:
|
warmPool:
|
||||||
enableLifecycleHook: true
|
enableLifecycleHook: true
|
||||||
|
maxSize: 1
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,8 @@ type AutoscalingLifecycleHook struct {
|
||||||
DefaultResult *string
|
DefaultResult *string
|
||||||
HeartbeatTimeout *int64
|
HeartbeatTimeout *int64
|
||||||
LifecycleTransition *string
|
LifecycleTransition *string
|
||||||
|
|
||||||
|
Enabled *bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ fi.CompareWithID = &AutoscalingLifecycleHook{}
|
var _ fi.CompareWithID = &AutoscalingLifecycleHook{}
|
||||||
|
|
@ -64,6 +66,10 @@ func (h *AutoscalingLifecycleHook) Find(c *fi.Context) (*AutoscalingLifecycleHoo
|
||||||
return nil, fmt.Errorf("error listing ASG Lifecycle Hooks: %v", err)
|
return nil, fmt.Errorf("error listing ASG Lifecycle Hooks: %v", err)
|
||||||
}
|
}
|
||||||
if response == nil || len(response.LifecycleHooks) == 0 {
|
if response == nil || len(response.LifecycleHooks) == 0 {
|
||||||
|
if !fi.BoolValue(h.Enabled) {
|
||||||
|
return h, nil
|
||||||
|
}
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
if len(response.LifecycleHooks) > 1 {
|
if len(response.LifecycleHooks) > 1 {
|
||||||
|
|
@ -80,6 +86,7 @@ func (h *AutoscalingLifecycleHook) Find(c *fi.Context) (*AutoscalingLifecycleHoo
|
||||||
DefaultResult: hook.DefaultResult,
|
DefaultResult: hook.DefaultResult,
|
||||||
HeartbeatTimeout: hook.HeartbeatTimeout,
|
HeartbeatTimeout: hook.HeartbeatTimeout,
|
||||||
LifecycleTransition: hook.LifecycleTransition,
|
LifecycleTransition: hook.LifecycleTransition,
|
||||||
|
Enabled: fi.Bool(true),
|
||||||
}
|
}
|
||||||
|
|
||||||
return actual, nil
|
return actual, nil
|
||||||
|
|
@ -104,6 +111,7 @@ func (_ *AutoscalingLifecycleHook) CheckChanges(a, e, changes *AutoscalingLifecy
|
||||||
|
|
||||||
func (*AutoscalingLifecycleHook) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *AutoscalingLifecycleHook) error {
|
func (*AutoscalingLifecycleHook) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *AutoscalingLifecycleHook) error {
|
||||||
if changes != nil {
|
if changes != nil {
|
||||||
|
if fi.BoolValue(e.Enabled) {
|
||||||
request := &autoscaling.PutLifecycleHookInput{
|
request := &autoscaling.PutLifecycleHookInput{
|
||||||
AutoScalingGroupName: e.AutoscalingGroup.Name,
|
AutoScalingGroupName: e.AutoscalingGroup.Name,
|
||||||
DefaultResult: e.DefaultResult,
|
DefaultResult: e.DefaultResult,
|
||||||
|
|
@ -115,6 +123,16 @@ func (*AutoscalingLifecycleHook) RenderAWS(t *awsup.AWSAPITarget, a, e, changes
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
request := &autoscaling.DeleteLifecycleHookInput{
|
||||||
|
AutoScalingGroupName: e.AutoscalingGroup.Name,
|
||||||
|
LifecycleHookName: e.GetHookName(),
|
||||||
|
}
|
||||||
|
_, err := t.Cloud.Autoscaling().DeleteLifecycleHook(request)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -129,6 +147,9 @@ type terraformASGLifecycleHook struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *AutoscalingLifecycleHook) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *AutoscalingLifecycleHook) error {
|
func (_ *AutoscalingLifecycleHook) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *AutoscalingLifecycleHook) error {
|
||||||
|
if !fi.BoolValue(e.Enabled) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
tf := &terraformASGLifecycleHook{
|
tf := &terraformASGLifecycleHook{
|
||||||
Name: e.GetHookName(),
|
Name: e.GetHookName(),
|
||||||
AutoScalingGroupName: e.AutoscalingGroup.TerraformLink(),
|
AutoScalingGroupName: e.AutoscalingGroup.TerraformLink(),
|
||||||
|
|
@ -149,6 +170,9 @@ type cloudformationASGLifecycleHook struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *AutoscalingLifecycleHook) RenderCloudformation(t *cloudformation.CloudformationTarget, a, e, changes *AutoscalingLifecycleHook) error {
|
func (_ *AutoscalingLifecycleHook) RenderCloudformation(t *cloudformation.CloudformationTarget, a, e, changes *AutoscalingLifecycleHook) error {
|
||||||
|
if !fi.BoolValue(e.Enabled) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
tf := &cloudformationASGLifecycleHook{
|
tf := &cloudformationASGLifecycleHook{
|
||||||
LifecycleHookName: e.GetHookName(),
|
LifecycleHookName: e.GetHookName(),
|
||||||
AutoScalingGroupName: e.AutoscalingGroup.CloudformationLink(),
|
AutoScalingGroupName: e.AutoscalingGroup.CloudformationLink(),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue