mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 10:43:56 +00:00
Modify the AWS cloud provider to ensure additional load balancer tags are added to existing load balancers
This commit is contained in:
parent
33f873dbbe
commit
36d59704d9
@ -255,6 +255,7 @@ type ELB interface {
|
|||||||
CreateLoadBalancer(*elb.CreateLoadBalancerInput) (*elb.CreateLoadBalancerOutput, error)
|
CreateLoadBalancer(*elb.CreateLoadBalancerInput) (*elb.CreateLoadBalancerOutput, error)
|
||||||
DeleteLoadBalancer(*elb.DeleteLoadBalancerInput) (*elb.DeleteLoadBalancerOutput, error)
|
DeleteLoadBalancer(*elb.DeleteLoadBalancerInput) (*elb.DeleteLoadBalancerOutput, error)
|
||||||
DescribeLoadBalancers(*elb.DescribeLoadBalancersInput) (*elb.DescribeLoadBalancersOutput, error)
|
DescribeLoadBalancers(*elb.DescribeLoadBalancersInput) (*elb.DescribeLoadBalancersOutput, error)
|
||||||
|
AddTags(*elb.AddTagsInput) (*elb.AddTagsOutput, error)
|
||||||
RegisterInstancesWithLoadBalancer(*elb.RegisterInstancesWithLoadBalancerInput) (*elb.RegisterInstancesWithLoadBalancerOutput, error)
|
RegisterInstancesWithLoadBalancer(*elb.RegisterInstancesWithLoadBalancerInput) (*elb.RegisterInstancesWithLoadBalancerOutput, error)
|
||||||
DeregisterInstancesFromLoadBalancer(*elb.DeregisterInstancesFromLoadBalancerInput) (*elb.DeregisterInstancesFromLoadBalancerOutput, error)
|
DeregisterInstancesFromLoadBalancer(*elb.DeregisterInstancesFromLoadBalancerInput) (*elb.DeregisterInstancesFromLoadBalancerOutput, error)
|
||||||
CreateLoadBalancerPolicy(*elb.CreateLoadBalancerPolicyInput) (*elb.CreateLoadBalancerPolicyOutput, error)
|
CreateLoadBalancerPolicy(*elb.CreateLoadBalancerPolicyInput) (*elb.CreateLoadBalancerPolicyOutput, error)
|
||||||
@ -2178,6 +2179,27 @@ func (c *Cloud) describeLoadBalancer(name string) (*elb.LoadBalancerDescription,
|
|||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Cloud) addLoadBalancerTags(loadBalancerName string, requested map[string]string) error {
|
||||||
|
var tags []*elb.Tag
|
||||||
|
for k, v := range requested {
|
||||||
|
tag := &elb.Tag{
|
||||||
|
Key: aws.String(k),
|
||||||
|
Value: aws.String(v),
|
||||||
|
}
|
||||||
|
tags = append(tags, tag)
|
||||||
|
}
|
||||||
|
|
||||||
|
request := &elb.AddTagsInput{}
|
||||||
|
request.LoadBalancerNames = []*string{&loadBalancerName}
|
||||||
|
request.Tags = tags
|
||||||
|
|
||||||
|
_, err := c.elb.AddTags(request)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error adding tags to load balancer: %v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Retrieves instance's vpc id from metadata
|
// Retrieves instance's vpc id from metadata
|
||||||
func (c *Cloud) findVPCID() (string, error) {
|
func (c *Cloud) findVPCID() (string, error) {
|
||||||
macs, err := c.metadata.GetMetadata("network/interfaces/macs/")
|
macs, err := c.metadata.GetMetadata("network/interfaces/macs/")
|
||||||
|
@ -312,6 +312,10 @@ func (elb *FakeELB) DescribeLoadBalancers(input *elb.DescribeLoadBalancersInput)
|
|||||||
panic("Not implemented")
|
panic("Not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (elb *FakeELB) AddTags(input *elb.AddTagsInput) (*elb.AddTagsOutput, error) {
|
||||||
|
panic("Not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
func (elb *FakeELB) RegisterInstancesWithLoadBalancer(*elb.RegisterInstancesWithLoadBalancerInput) (*elb.RegisterInstancesWithLoadBalancerOutput, error) {
|
func (elb *FakeELB) RegisterInstancesWithLoadBalancer(*elb.RegisterInstancesWithLoadBalancerInput) (*elb.RegisterInstancesWithLoadBalancerOutput, error) {
|
||||||
panic("Not implemented")
|
panic("Not implemented")
|
||||||
}
|
}
|
||||||
|
@ -314,6 +314,18 @@ func (c *Cloud) ensureLoadBalancer(namespacedName types.NamespacedName, loadBala
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// Add additional tags
|
||||||
|
glog.V(2).Infof("Creating additional load balancer tags for %s", loadBalancerName)
|
||||||
|
tags := getLoadBalancerAdditionalTags(annotations)
|
||||||
|
if len(tags) > 0 {
|
||||||
|
err := c.addLoadBalancerTags(loadBalancerName, tags)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to create additional load balancer tags: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Whether the ELB was new or existing, sync attributes regardless. This accounts for things
|
// Whether the ELB was new or existing, sync attributes regardless. This accounts for things
|
||||||
|
@ -82,6 +82,11 @@ func (m *MockedFakeELB) expectDescribeLoadBalancers(loadBalancerName string) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *MockedFakeELB) AddTags(input *elb.AddTagsInput) (*elb.AddTagsOutput, error) {
|
||||||
|
args := m.Called(input)
|
||||||
|
return args.Get(0).(*elb.AddTagsOutput), nil
|
||||||
|
}
|
||||||
|
|
||||||
func TestReadAWSCloudConfig(t *testing.T) {
|
func TestReadAWSCloudConfig(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@ -1130,6 +1135,31 @@ func TestLBExtraSecurityGroupsAnnotation(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test that we can add a load balancer tag
|
||||||
|
func TestAddLoadBalancerTags(t *testing.T) {
|
||||||
|
loadBalancerName := "test-elb"
|
||||||
|
awsServices := newMockedFakeAWSServices(TestClusterId)
|
||||||
|
c, _ := newAWSCloud(strings.NewReader("[global]"), awsServices)
|
||||||
|
|
||||||
|
want := make(map[string]string)
|
||||||
|
want["tag1"] = "val1"
|
||||||
|
|
||||||
|
expectedAddTagsRequest := &elb.AddTagsInput{
|
||||||
|
LoadBalancerNames: []*string{&loadBalancerName},
|
||||||
|
Tags: []*elb.Tag{
|
||||||
|
{
|
||||||
|
Key: aws.String("tag1"),
|
||||||
|
Value: aws.String("val1"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
awsServices.elb.(*MockedFakeELB).On("AddTags", expectedAddTagsRequest).Return(&elb.AddTagsOutput{})
|
||||||
|
|
||||||
|
err := c.addLoadBalancerTags(loadBalancerName, want)
|
||||||
|
assert.Nil(t, err, "Error adding load balancer tags: %v", err)
|
||||||
|
awsServices.elb.(*MockedFakeELB).AssertExpectations(t)
|
||||||
|
}
|
||||||
|
|
||||||
func newMockedFakeAWSServices(id string) *FakeAWSServices {
|
func newMockedFakeAWSServices(id string) *FakeAWSServices {
|
||||||
s := NewFakeAWSServices(id)
|
s := NewFakeAWSServices(id)
|
||||||
s.ec2 = &MockedFakeEC2{FakeEC2Impl: s.ec2.(*FakeEC2Impl)}
|
s.ec2 = &MockedFakeEC2{FakeEC2Impl: s.ec2.(*FakeEC2Impl)}
|
||||||
|
Loading…
Reference in New Issue
Block a user