Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
80bf32ce
Commit
80bf32ce
authored
Oct 12, 2015
by
Dawn Chen
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14879 from tpounds/aws-cloud-cleanup
AWS Cloud Provider Cleanup
parents
376438b6
5d5013a7
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
82 deletions
+7
-82
aws.go
pkg/cloudprovider/providers/aws/aws.go
+5
-71
aws_test.go
pkg/cloudprovider/providers/aws/aws_test.go
+2
-11
No files found.
pkg/cloudprovider/providers/aws/aws.go
View file @
80bf32ce
...
@@ -91,8 +91,6 @@ type EC2 interface {
...
@@ -91,8 +91,6 @@ type EC2 interface {
AuthorizeSecurityGroupIngress
(
*
ec2
.
AuthorizeSecurityGroupIngressInput
)
(
*
ec2
.
AuthorizeSecurityGroupIngressOutput
,
error
)
AuthorizeSecurityGroupIngress
(
*
ec2
.
AuthorizeSecurityGroupIngressInput
)
(
*
ec2
.
AuthorizeSecurityGroupIngressOutput
,
error
)
RevokeSecurityGroupIngress
(
*
ec2
.
RevokeSecurityGroupIngressInput
)
(
*
ec2
.
RevokeSecurityGroupIngressOutput
,
error
)
RevokeSecurityGroupIngress
(
*
ec2
.
RevokeSecurityGroupIngressInput
)
(
*
ec2
.
RevokeSecurityGroupIngressOutput
,
error
)
DescribeVPCs
(
*
ec2
.
DescribeVpcsInput
)
([]
*
ec2
.
Vpc
,
error
)
DescribeSubnets
(
*
ec2
.
DescribeSubnetsInput
)
([]
*
ec2
.
Subnet
,
error
)
DescribeSubnets
(
*
ec2
.
DescribeSubnetsInput
)
([]
*
ec2
.
Subnet
,
error
)
CreateTags
(
*
ec2
.
CreateTagsInput
)
(
*
ec2
.
CreateTagsOutput
,
error
)
CreateTags
(
*
ec2
.
CreateTagsInput
)
(
*
ec2
.
CreateTagsOutput
,
error
)
...
@@ -172,7 +170,6 @@ type InstanceGroupInfo interface {
...
@@ -172,7 +170,6 @@ type InstanceGroupInfo interface {
// AWSCloud is an implementation of Interface, TCPLoadBalancer and Instances for Amazon Web Services.
// AWSCloud is an implementation of Interface, TCPLoadBalancer and Instances for Amazon Web Services.
type
AWSCloud
struct
{
type
AWSCloud
struct
{
awsServices
AWSServices
ec2
EC2
ec2
EC2
elb
ELB
elb
ELB
asg
ASG
asg
ASG
...
@@ -378,15 +375,6 @@ func (s *awsSdkEC2) DeleteVolume(volumeID string) (resp *ec2.DeleteVolumeOutput,
...
@@ -378,15 +375,6 @@ func (s *awsSdkEC2) DeleteVolume(volumeID string) (resp *ec2.DeleteVolumeOutput,
return
s
.
ec2
.
DeleteVolume
(
&
request
)
return
s
.
ec2
.
DeleteVolume
(
&
request
)
}
}
func
(
s
*
awsSdkEC2
)
DescribeVPCs
(
request
*
ec2
.
DescribeVpcsInput
)
([]
*
ec2
.
Vpc
,
error
)
{
// VPCs are not paged
response
,
err
:=
s
.
ec2
.
DescribeVpcs
(
request
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"error listing AWS VPCs: %v"
,
err
)
}
return
response
.
Vpcs
,
nil
}
func
(
s
*
awsSdkEC2
)
DescribeSubnets
(
request
*
ec2
.
DescribeSubnetsInput
)
([]
*
ec2
.
Subnet
,
error
)
{
func
(
s
*
awsSdkEC2
)
DescribeSubnets
(
request
*
ec2
.
DescribeSubnetsInput
)
([]
*
ec2
.
Subnet
,
error
)
{
// Subnets are not paged
// Subnets are not paged
response
,
err
:=
s
.
ec2
.
DescribeSubnets
(
request
)
response
,
err
:=
s
.
ec2
.
DescribeSubnets
(
request
)
...
@@ -544,7 +532,6 @@ func newAWSCloud(config io.Reader, awsServices AWSServices) (*AWSCloud, error) {
...
@@ -544,7 +532,6 @@ func newAWSCloud(config io.Reader, awsServices AWSServices) (*AWSCloud, error) {
}
}
awsCloud
:=
&
AWSCloud
{
awsCloud
:=
&
AWSCloud
{
awsServices
:
awsServices
,
ec2
:
ec2
,
ec2
:
ec2
,
elb
:
elb
,
elb
:
elb
,
asg
:
asg
,
asg
:
asg
,
...
@@ -757,10 +744,6 @@ func (aws *AWSCloud) List(filter string) ([]string, error) {
...
@@ -757,10 +744,6 @@ func (aws *AWSCloud) List(filter string) ([]string, error) {
// GetZone implements Zones.GetZone
// GetZone implements Zones.GetZone
func
(
self
*
AWSCloud
)
GetZone
()
(
cloudprovider
.
Zone
,
error
)
{
func
(
self
*
AWSCloud
)
GetZone
()
(
cloudprovider
.
Zone
,
error
)
{
if
self
.
availabilityZone
==
""
{
// Should be unreachable
panic
(
"availabilityZone not set"
)
}
return
cloudprovider
.
Zone
{
return
cloudprovider
.
Zone
{
FailureDomain
:
self
.
availabilityZone
,
FailureDomain
:
self
.
availabilityZone
,
Region
:
self
.
region
,
Region
:
self
.
region
,
...
@@ -1258,35 +1241,6 @@ func (self *AWSCloud) findVPCID() (string, error) {
...
@@ -1258,35 +1241,6 @@ func (self *AWSCloud) findVPCID() (string, error) {
return
""
,
fmt
.
Errorf
(
"Could not find VPC ID in instance metadata"
)
return
""
,
fmt
.
Errorf
(
"Could not find VPC ID in instance metadata"
)
}
}
// Find the VPC which self is attached to.
func
(
self
*
AWSCloud
)
findVPC
()
(
*
ec2
.
Vpc
,
error
)
{
request
:=
&
ec2
.
DescribeVpcsInput
{}
// find by vpcID from metadata
vpcID
,
err
:=
self
.
findVPCID
()
if
err
!=
nil
{
return
nil
,
err
}
filters
:=
[]
*
ec2
.
Filter
{
newEc2Filter
(
"vpc-id"
,
vpcID
)}
// Don't bother adding the filterTags as we know this VPC is valid for this instance from findVPCID above.
// This is important as sharing a single regional VPC with multiple per-AZ clusters is a common deployment.
request
.
Filters
=
filters
vpcs
,
err
:=
self
.
ec2
.
DescribeVPCs
(
request
)
if
err
!=
nil
{
glog
.
Error
(
"error listing VPCs"
,
err
)
return
nil
,
err
}
if
len
(
vpcs
)
==
0
{
return
nil
,
nil
}
if
len
(
vpcs
)
==
1
{
return
vpcs
[
0
],
nil
}
return
nil
,
fmt
.
Errorf
(
"Found multiple matching VPCs for vpcID = %s"
,
vpcID
)
}
// Retrieves the specified security group from the AWS API, or returns nil if not found
// Retrieves the specified security group from the AWS API, or returns nil if not found
func
(
s
*
AWSCloud
)
findSecurityGroup
(
securityGroupId
string
)
(
*
ec2
.
SecurityGroup
,
error
)
{
func
(
s
*
AWSCloud
)
findSecurityGroup
(
securityGroupId
string
)
(
*
ec2
.
SecurityGroup
,
error
)
{
describeSecurityGroupsRequest
:=
&
ec2
.
DescribeSecurityGroupsInput
{
describeSecurityGroupsRequest
:=
&
ec2
.
DescribeSecurityGroupsInput
{
...
@@ -1574,13 +1528,13 @@ func (s *AWSCloud) createTags(request *ec2.CreateTagsInput) (*ec2.CreateTagsOutp
...
@@ -1574,13 +1528,13 @@ func (s *AWSCloud) createTags(request *ec2.CreateTagsInput) (*ec2.CreateTagsOutp
}
}
}
}
func
(
s
*
AWSCloud
)
listSubnetIDsinVPC
(
vpc
*
ec2
.
Vpc
)
([]
string
,
error
)
{
func
(
s
*
AWSCloud
)
listSubnetIDsinVPC
(
vpc
Id
string
)
([]
string
,
error
)
{
subnetIds
:=
[]
string
{}
subnetIds
:=
[]
string
{}
request
:=
&
ec2
.
DescribeSubnetsInput
{}
request
:=
&
ec2
.
DescribeSubnetsInput
{}
filters
:=
[]
*
ec2
.
Filter
{}
filters
:=
[]
*
ec2
.
Filter
{}
filters
=
append
(
filters
,
newEc2Filter
(
"vpc-id"
,
orEmpty
(
vpc
.
VpcId
)
))
filters
=
append
(
filters
,
newEc2Filter
(
"vpc-id"
,
vpcId
))
// Note, this will only return subnets tagged with the cluster identifier for this Kubernetes cluster.
// Note, this will only return subnets tagged with the cluster identifier for this Kubernetes cluster.
// In the case where an AZ has public & private subnets per AWS best practices, the deployment should ensure
// In the case where an AZ has public & private subnets per AWS best practices, the deployment should ensure
// only the public subnet (where the ELB will go) is so tagged.
// only the public subnet (where the ELB will go) is so tagged.
...
@@ -1631,17 +1585,13 @@ func (s *AWSCloud) EnsureTCPLoadBalancer(name, region string, publicIP net.IP, p
...
@@ -1631,17 +1585,13 @@ func (s *AWSCloud) EnsureTCPLoadBalancer(name, region string, publicIP net.IP, p
return
nil
,
err
return
nil
,
err
}
}
vpc
,
err
:=
s
.
findVPC
()
vpc
Id
,
err
:=
s
.
findVPCID
()
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Error
(
"error finding VPC"
,
err
)
return
nil
,
err
return
nil
,
err
}
}
if
vpc
==
nil
{
return
nil
,
fmt
.
Errorf
(
"Unable to find VPC"
)
}
// Construct list of configured subnets
// Construct list of configured subnets
subnetIDs
,
err
:=
s
.
listSubnetIDsinVPC
(
vpc
)
subnetIDs
,
err
:=
s
.
listSubnetIDsinVPC
(
vpc
Id
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Error
(
"error listing subnets in VPC"
,
err
)
glog
.
Error
(
"error listing subnets in VPC"
,
err
)
return
nil
,
err
return
nil
,
err
...
@@ -1652,7 +1602,7 @@ func (s *AWSCloud) EnsureTCPLoadBalancer(name, region string, publicIP net.IP, p
...
@@ -1652,7 +1602,7 @@ func (s *AWSCloud) EnsureTCPLoadBalancer(name, region string, publicIP net.IP, p
{
{
sgName
:=
"k8s-elb-"
+
name
sgName
:=
"k8s-elb-"
+
name
sgDescription
:=
"Security group for Kubernetes ELB "
+
name
sgDescription
:=
"Security group for Kubernetes ELB "
+
name
securityGroupID
,
err
=
s
.
ensureSecurityGroup
(
sgName
,
sgDescription
,
orEmpty
(
vpc
.
VpcId
)
)
securityGroupID
,
err
=
s
.
ensureSecurityGroup
(
sgName
,
sgDescription
,
vpcId
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Error
(
"Error creating load balancer security group: "
,
err
)
glog
.
Error
(
"Error creating load balancer security group: "
,
err
)
return
nil
,
err
return
nil
,
err
...
@@ -2021,22 +1971,6 @@ func (s *AWSCloud) UpdateTCPLoadBalancer(name, region string, hosts []string) er
...
@@ -2021,22 +1971,6 @@ func (s *AWSCloud) UpdateTCPLoadBalancer(name, region string, hosts []string) er
return
nil
return
nil
}
}
// TODO: Make efficient
func
(
a
*
AWSCloud
)
getInstancesByIds
(
ids
[]
string
)
([]
*
ec2
.
Instance
,
error
)
{
instances
:=
[]
*
ec2
.
Instance
{}
for
_
,
id
:=
range
ids
{
instance
,
err
:=
a
.
getInstanceById
(
id
)
if
err
!=
nil
{
return
nil
,
err
}
if
instance
==
nil
{
return
nil
,
fmt
.
Errorf
(
"unable to find instance "
+
id
)
}
instances
=
append
(
instances
,
instance
)
}
return
instances
,
nil
}
// Returns the instance with the specified ID
// Returns the instance with the specified ID
func
(
a
*
AWSCloud
)
getInstanceById
(
instanceID
string
)
(
*
ec2
.
Instance
,
error
)
{
func
(
a
*
AWSCloud
)
getInstanceById
(
instanceID
string
)
(
*
ec2
.
Instance
,
error
)
{
request
:=
&
ec2
.
DescribeInstancesInput
{
request
:=
&
ec2
.
DescribeInstancesInput
{
...
...
pkg/cloudprovider/providers/aws/aws_test.go
View file @
80bf32ce
...
@@ -383,10 +383,6 @@ func (ec2 *FakeEC2) RevokeSecurityGroupIngress(*ec2.RevokeSecurityGroupIngressIn
...
@@ -383,10 +383,6 @@ func (ec2 *FakeEC2) RevokeSecurityGroupIngress(*ec2.RevokeSecurityGroupIngressIn
panic
(
"Not implemented"
)
panic
(
"Not implemented"
)
}
}
func
(
ec2
*
FakeEC2
)
DescribeVPCs
(
*
ec2
.
DescribeVpcsInput
)
([]
*
ec2
.
Vpc
,
error
)
{
panic
(
"Not implemented"
)
}
func
(
ec2
*
FakeEC2
)
DescribeSubnets
(
request
*
ec2
.
DescribeSubnetsInput
)
([]
*
ec2
.
Subnet
,
error
)
{
func
(
ec2
*
FakeEC2
)
DescribeSubnets
(
request
*
ec2
.
DescribeSubnetsInput
)
([]
*
ec2
.
Subnet
,
error
)
{
ec2
.
DescribeSubnetsInput
=
request
ec2
.
DescribeSubnetsInput
=
request
return
ec2
.
Subnets
,
nil
return
ec2
.
Subnets
,
nil
...
@@ -474,7 +470,6 @@ func (a *FakeASG) DescribeAutoScalingGroups(*autoscaling.DescribeAutoScalingGrou
...
@@ -474,7 +470,6 @@ func (a *FakeASG) DescribeAutoScalingGroups(*autoscaling.DescribeAutoScalingGrou
func
mockInstancesResp
(
instances
[]
*
ec2
.
Instance
)
*
AWSCloud
{
func
mockInstancesResp
(
instances
[]
*
ec2
.
Instance
)
*
AWSCloud
{
awsServices
:=
NewFakeAWSServices
()
.
withInstances
(
instances
)
awsServices
:=
NewFakeAWSServices
()
.
withInstances
(
instances
)
return
&
AWSCloud
{
return
&
AWSCloud
{
awsServices
:
awsServices
,
ec2
:
awsServices
.
ec2
,
ec2
:
awsServices
.
ec2
,
availabilityZone
:
awsServices
.
availabilityZone
,
availabilityZone
:
awsServices
.
availabilityZone
,
}
}
...
@@ -483,7 +478,6 @@ func mockInstancesResp(instances []*ec2.Instance) *AWSCloud {
...
@@ -483,7 +478,6 @@ func mockInstancesResp(instances []*ec2.Instance) *AWSCloud {
func
mockAvailabilityZone
(
region
string
,
availabilityZone
string
)
*
AWSCloud
{
func
mockAvailabilityZone
(
region
string
,
availabilityZone
string
)
*
AWSCloud
{
awsServices
:=
NewFakeAWSServices
()
.
withAz
(
availabilityZone
)
awsServices
:=
NewFakeAWSServices
()
.
withAz
(
availabilityZone
)
return
&
AWSCloud
{
return
&
AWSCloud
{
awsServices
:
awsServices
,
ec2
:
awsServices
.
ec2
,
ec2
:
awsServices
.
ec2
,
availabilityZone
:
awsServices
.
availabilityZone
,
availabilityZone
:
awsServices
.
availabilityZone
,
region
:
region
,
region
:
region
,
...
@@ -730,9 +724,6 @@ func TestSubnetIDsinVPC(t *testing.T) {
...
@@ -730,9 +724,6 @@ func TestSubnetIDsinVPC(t *testing.T) {
}
}
vpcID
:=
"vpc-deadbeef"
vpcID
:=
"vpc-deadbeef"
vpc
:=
&
ec2
.
Vpc
{
VpcId
:
&
vpcID
,
}
// test with 3 subnets from 3 different AZs
// test with 3 subnets from 3 different AZs
subnets
:=
make
(
map
[
int
]
map
[
string
]
string
)
subnets
:=
make
(
map
[
int
]
map
[
string
]
string
)
...
@@ -747,7 +738,7 @@ func TestSubnetIDsinVPC(t *testing.T) {
...
@@ -747,7 +738,7 @@ func TestSubnetIDsinVPC(t *testing.T) {
subnets
[
2
][
"az"
]
=
"af-south-1c"
subnets
[
2
][
"az"
]
=
"af-south-1c"
awsServices
.
ec2
.
Subnets
=
constructSubnets
(
subnets
)
awsServices
.
ec2
.
Subnets
=
constructSubnets
(
subnets
)
result
,
err
:=
c
.
listSubnetIDsinVPC
(
vpc
)
result
,
err
:=
c
.
listSubnetIDsinVPC
(
vpc
ID
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Error listing subnets: %v"
,
err
)
t
.
Errorf
(
"Error listing subnets: %v"
,
err
)
return
return
...
@@ -777,7 +768,7 @@ func TestSubnetIDsinVPC(t *testing.T) {
...
@@ -777,7 +768,7 @@ func TestSubnetIDsinVPC(t *testing.T) {
subnets
[
3
][
"az"
]
=
"af-south-1c"
subnets
[
3
][
"az"
]
=
"af-south-1c"
awsServices
.
ec2
.
Subnets
=
constructSubnets
(
subnets
)
awsServices
.
ec2
.
Subnets
=
constructSubnets
(
subnets
)
result
,
err
=
c
.
listSubnetIDsinVPC
(
vpc
)
result
,
err
=
c
.
listSubnetIDsinVPC
(
vpc
ID
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Error listing subnets: %v"
,
err
)
t
.
Errorf
(
"Error listing subnets: %v"
,
err
)
return
return
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment