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

Support for deletion of aws resources albs nlbs during delete #5635

Merged
merged 12 commits into from
Sep 21, 2018
11 changes: 8 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions cloudmock/aws/mockelbv2/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = ["api.go"],
importpath = "k8s.io/kops/cloudmock/aws/mockelbv2",
visibility = ["//visibility:public"],
deps = [
"//vendor/github.com/aws/aws-sdk-go/aws:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/service/elbv2:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/service/elbv2/elbv2iface:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
],
)
142 changes: 142 additions & 0 deletions cloudmock/aws/mockelbv2/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*
Copyright 2016 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 mockelbv2

import (
"sync"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/elbv2"
"github.com/aws/aws-sdk-go/service/elbv2/elbv2iface"
"github.com/golang/glog"
)

type MockELBV2 struct {
elbv2iface.ELBV2API

mutex sync.Mutex

LoadBalancers map[string]*loadBalancer
TargetGroups map[string]*targetGroup
}

type loadBalancer struct {
description elbv2.LoadBalancer
tags map[string]string
}

type targetGroup struct {
description elbv2.TargetGroup
tags map[string]string
}

func (m *MockELBV2) DescribeLoadBalancers(request *elbv2.DescribeLoadBalancersInput) (*elbv2.DescribeLoadBalancersOutput, error) {
m.mutex.Lock()
defer m.mutex.Unlock()

glog.V(2).Infof("DescribeLoadBalancers v2 %v", request)

if request.PageSize != nil {
glog.Warningf("PageSize not implemented")
}
if request.Marker != nil {
glog.Fatalf("Marker not implemented")
}

var elbs []*elbv2.LoadBalancer
for _, elb := range m.LoadBalancers {
match := false

if len(request.LoadBalancerArns) > 0 {
for _, name := range request.LoadBalancerArns {
if aws.StringValue(elb.description.LoadBalancerArn) == aws.StringValue(name) {
match = true
}
}
} else {
match = true
}

if match {
elbs = append(elbs, &elb.description)
}
}

return &elbv2.DescribeLoadBalancersOutput{
LoadBalancers: elbs,
}, nil
}

func (m *MockELBV2) DescribeLoadBalancersPages(request *elbv2.DescribeLoadBalancersInput, callback func(p *elbv2.DescribeLoadBalancersOutput, lastPage bool) (shouldContinue bool)) error {
// For the mock, we just send everything in one page
page, err := m.DescribeLoadBalancers(request)
if err != nil {
return err
}

callback(page, false)

return nil
}

func (m *MockELBV2) DescribeTargetGroups(request *elbv2.DescribeTargetGroupsInput) (*elbv2.DescribeTargetGroupsOutput, error) {
m.mutex.Lock()
defer m.mutex.Unlock()

glog.V(2).Infof("DescribeTargetGroups %v", request)

if request.PageSize != nil {
glog.Warningf("PageSize not implemented")
}
if request.Marker != nil {
glog.Fatalf("Marker not implemented")
}

var tgs []*elbv2.TargetGroup
for _, tg := range m.TargetGroups {
match := false

if len(request.TargetGroupArns) > 0 {
for _, name := range request.TargetGroupArns {
if aws.StringValue(tg.description.TargetGroupArn) == aws.StringValue(name) {
match = true
}
}
} else {
match = true
}

if match {
tgs = append(tgs, &tg.description)
}
}

return &elbv2.DescribeTargetGroupsOutput{
TargetGroups: tgs,
}, nil
}

func (m *MockELBV2) DescribeTargetGroupsPages(request *elbv2.DescribeTargetGroupsInput, callback func(p *elbv2.DescribeTargetGroupsOutput, lastPage bool) (shouldContinue bool)) error {
page, err := m.DescribeTargetGroups(request)
if err != nil {
return err
}

callback(page, false)

return nil
}
1 change: 1 addition & 0 deletions hack/.packages
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ k8s.io/kops/channels/pkg/cmd
k8s.io/kops/cloudmock/aws/mockautoscaling
k8s.io/kops/cloudmock/aws/mockec2
k8s.io/kops/cloudmock/aws/mockelb
k8s.io/kops/cloudmock/aws/mockelbv2
k8s.io/kops/cloudmock/aws/mockiam
k8s.io/kops/cloudmock/aws/mockroute53
k8s.io/kops/cmd/kops
Expand Down
1 change: 1 addition & 0 deletions pkg/resources/aws/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ go_library(
"//vendor/github.com/aws/aws-sdk-go/service/cloudformation:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/service/ec2:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/service/elb:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/service/elbv2:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/service/iam:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/service/route53:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
Expand Down
Loading