From 9db3567cac9fb8e40306be4d5402ccfde79affc5 Mon Sep 17 00:00:00 2001 From: Liran Polak Date: Mon, 29 Oct 2018 22:28:15 +0200 Subject: [PATCH] fix: skip the load balancer attachment --- pkg/model/awsmodel/BUILD.bazel | 1 + pkg/model/awsmodel/api_loadbalancer.go | 22 ++++++++++++++-------- pkg/model/bastion.go | 24 +++++++++++++++--------- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/pkg/model/awsmodel/BUILD.bazel b/pkg/model/awsmodel/BUILD.bazel index b5efd0e979d82..b7d97f18cdef2 100644 --- a/pkg/model/awsmodel/BUILD.bazel +++ b/pkg/model/awsmodel/BUILD.bazel @@ -13,6 +13,7 @@ go_library( deps = [ "//pkg/apis/kops:go_default_library", "//pkg/dns:go_default_library", + "//pkg/featureflag:go_default_library", "//pkg/model:go_default_library", "//pkg/model/defaults:go_default_library", "//upup/pkg/fi:go_default_library", diff --git a/pkg/model/awsmodel/api_loadbalancer.go b/pkg/model/awsmodel/api_loadbalancer.go index af7ece83791bc..5a7ca79d9933b 100644 --- a/pkg/model/awsmodel/api_loadbalancer.go +++ b/pkg/model/awsmodel/api_loadbalancer.go @@ -25,6 +25,7 @@ import ( "k8s.io/apimachinery/pkg/util/sets" "k8s.io/kops/pkg/apis/kops" "k8s.io/kops/pkg/dns" + "k8s.io/kops/pkg/featureflag" "k8s.io/kops/upup/pkg/fi" "k8s.io/kops/upup/pkg/fi/cloudup/awstasks" "k8s.io/kops/upup/pkg/fi/fitasks" @@ -254,16 +255,21 @@ func (b *APILoadBalancerBuilder) Build(c *fi.ModelBuilderContext) error { masterKeypair.AlternateNameTasks = append(masterKeypair.AlternateNameTasks, elb) } - for _, ig := range b.MasterInstanceGroups() { - t := &awstasks.LoadBalancerAttachment{ - Name: s("api-" + ig.ObjectMeta.Name), - Lifecycle: b.Lifecycle, + // When Spotinst Elastigroups are used, there is no need to create + // a separate task for the attachment of the load balancer since this + // is already done as part of the Elastigroup's creation, if needed. + if !featureflag.Spotinst.Enabled() { + for _, ig := range b.MasterInstanceGroups() { + t := &awstasks.LoadBalancerAttachment{ + Name: s("api-" + ig.ObjectMeta.Name), + Lifecycle: b.Lifecycle, + + LoadBalancer: b.LinkToELB("api"), + AutoscalingGroup: b.LinkToAutoscalingGroup(ig), + } - LoadBalancer: b.LinkToELB("api"), - AutoscalingGroup: b.LinkToAutoscalingGroup(ig), + c.AddTask(t) } - - c.AddTask(t) } return nil diff --git a/pkg/model/bastion.go b/pkg/model/bastion.go index 47f75305b3f84..54aa9511ebeb6 100644 --- a/pkg/model/bastion.go +++ b/pkg/model/bastion.go @@ -21,6 +21,7 @@ import ( "k8s.io/apimachinery/pkg/util/sets" "k8s.io/kops/pkg/apis/kops" + "k8s.io/kops/pkg/featureflag" "k8s.io/kops/upup/pkg/fi" "k8s.io/kops/upup/pkg/fi/cloudup/awstasks" ) @@ -236,18 +237,23 @@ func (b *BastionModelBuilder) Build(c *fi.ModelBuilderContext) error { c.AddTask(elb) } - for _, ig := range bastionInstanceGroups { - // We build the ASG when we iterate over the instance groups + // When Spotinst Elastigroups are used, there is no need to create + // a separate task for the attachment of the load balancer since this + // is already done as part of the Elastigroup's creation, if needed. + if !featureflag.Spotinst.Enabled() { + for _, ig := range bastionInstanceGroups { + // We build the ASG when we iterate over the instance groups - // Attach the ELB to the ASG - t := &awstasks.LoadBalancerAttachment{ - Name: s("bastion-elb-attachment"), - Lifecycle: b.Lifecycle, + // Attach the ELB to the ASG + t := &awstasks.LoadBalancerAttachment{ + Name: s("bastion-elb-attachment"), + Lifecycle: b.Lifecycle, - LoadBalancer: elb, - AutoscalingGroup: b.LinkToAutoscalingGroup(ig), + LoadBalancer: elb, + AutoscalingGroup: b.LinkToAutoscalingGroup(ig), + } + c.AddTask(t) } - c.AddTask(t) } bastionPublicName := ""