mirror of https://github.com/kubernetes/kops.git
Merge pull request #4281 from appvia/loadbalancer-update-subnets
Implement ability to update Load Balancer subnets
This commit is contained in:
commit
e271f9edfb
|
|
@ -160,6 +160,7 @@ k8s.io/kops/upup/pkg/kutil
|
||||||
k8s.io/kops/upup/tools/generators/fitask
|
k8s.io/kops/upup/tools/generators/fitask
|
||||||
k8s.io/kops/upup/tools/generators/pkg/codegen
|
k8s.io/kops/upup/tools/generators/pkg/codegen
|
||||||
k8s.io/kops/util/pkg/hashing
|
k8s.io/kops/util/pkg/hashing
|
||||||
|
k8s.io/kops/util/pkg/slice
|
||||||
k8s.io/kops/util/pkg/tables
|
k8s.io/kops/util/pkg/tables
|
||||||
k8s.io/kops/util/pkg/ui
|
k8s.io/kops/util/pkg/ui
|
||||||
k8s.io/kops/util/pkg/vfs
|
k8s.io/kops/util/pkg/vfs
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/util/pkg/slice"
|
||||||
)
|
)
|
||||||
|
|
||||||
// LoadBalancer manages an ELB. We find the existing ELB using the Name tag.
|
// LoadBalancer manages an ELB. We find the existing ELB using the Name tag.
|
||||||
|
|
@ -527,7 +528,29 @@ func (_ *LoadBalancer) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *LoadBalan
|
||||||
actualSubnets = append(actualSubnets, fi.StringValue(s.ID))
|
actualSubnets = append(actualSubnets, fi.StringValue(s.ID))
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Errorf("subnet changes on LoadBalancer not yet implemented: actual=%s -> expected=%s", actualSubnets, expectedSubnets)
|
oldSubnetIDs := slice.GetUniqueStrings(expectedSubnets, actualSubnets)
|
||||||
|
if len(oldSubnetIDs) > 0 {
|
||||||
|
request := &elb.DetachLoadBalancerFromSubnetsInput{}
|
||||||
|
request.SetLoadBalancerName(loadBalancerName)
|
||||||
|
request.SetSubnets(aws.StringSlice(oldSubnetIDs))
|
||||||
|
|
||||||
|
glog.V(2).Infof("Detaching Load Balancer from old subnets")
|
||||||
|
if _, err := t.Cloud.ELB().DetachLoadBalancerFromSubnets(request); err != nil {
|
||||||
|
return fmt.Errorf("Error detaching Load Balancer from old subnets: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
newSubnetIDs := slice.GetUniqueStrings(actualSubnets, expectedSubnets)
|
||||||
|
if len(newSubnetIDs) > 0 {
|
||||||
|
request := &elb.AttachLoadBalancerToSubnetsInput{}
|
||||||
|
request.SetLoadBalancerName(loadBalancerName)
|
||||||
|
request.SetSubnets(aws.StringSlice(newSubnetIDs))
|
||||||
|
|
||||||
|
glog.V(2).Infof("Attaching Load Balancer to new subnets")
|
||||||
|
if _, err := t.Cloud.ELB().AttachLoadBalancerToSubnets(request); err != nil {
|
||||||
|
return fmt.Errorf("Error attaching Load Balancer to new subnets: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if changes.Listeners != nil {
|
if changes.Listeners != nil {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
Copyright 2018 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Package slice provides utility methods for common operations on slices.
|
||||||
|
package slice
|
||||||
|
|
||||||
|
// GetUniqueStrings returns a slice of strings in the extra slice that are not
|
||||||
|
// present in the main slice
|
||||||
|
func GetUniqueStrings(main, extra []string) []string {
|
||||||
|
unique := []string{}
|
||||||
|
|
||||||
|
for _, item := range extra {
|
||||||
|
found := false
|
||||||
|
|
||||||
|
for _, s := range main {
|
||||||
|
if item == s {
|
||||||
|
found = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !found {
|
||||||
|
unique = append(unique, item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return unique
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue