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
e86c3de6
Commit
e86c3de6
authored
Nov 13, 2015
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #16633 from brendandburns/aws2
Auto commit by PR queue bot
parents
dfb9ed20
64aa189b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
6 deletions
+43
-6
aws.go
pkg/cloudprovider/providers/aws/aws.go
+18
-0
aws_test.go
pkg/cloudprovider/providers/aws/aws_test.go
+25
-6
No files found.
pkg/cloudprovider/providers/aws/aws.go
View file @
e86c3de6
...
...
@@ -618,6 +618,24 @@ func (aws *AWSCloud) Routes() (cloudprovider.Routes, bool) {
// NodeAddresses is an implementation of Instances.NodeAddresses.
func
(
aws
*
AWSCloud
)
NodeAddresses
(
name
string
)
([]
api
.
NodeAddress
,
error
)
{
self
,
err
:=
aws
.
getSelfAWSInstance
()
if
err
!=
nil
{
return
nil
,
err
}
if
self
.
nodeName
==
name
||
len
(
name
)
==
0
{
internalIP
,
err
:=
aws
.
metadata
.
GetMetadata
(
"local-ipv4"
)
if
err
!=
nil
{
return
nil
,
err
}
externalIP
,
err
:=
aws
.
metadata
.
GetMetadata
(
"public-ipv4"
)
if
err
!=
nil
{
return
nil
,
err
}
return
[]
api
.
NodeAddress
{
{
Type
:
api
.
NodeInternalIP
,
Address
:
internalIP
},
{
Type
:
api
.
NodeExternalIP
,
Address
:
externalIP
},
},
nil
}
instance
,
err
:=
aws
.
getInstanceByNodeName
(
name
)
if
err
!=
nil
{
return
nil
,
err
...
...
pkg/cloudprovider/providers/aws/aws_test.go
View file @
e86c3de6
...
...
@@ -111,6 +111,8 @@ type FakeAWSServices struct {
privateDnsName
string
networkInterfacesMacs
[]
string
networkInterfacesVpcIDs
[]
string
internalIP
string
externalIP
string
ec2
*
FakeEC2
elb
*
FakeELB
...
...
@@ -323,6 +325,10 @@ func (self *FakeMetadata) GetMetadata(key string) (string, error) {
return
self
.
aws
.
instanceId
,
nil
}
else
if
key
==
"local-hostname"
{
return
self
.
aws
.
privateDnsName
,
nil
}
else
if
key
==
"local-ipv4"
{
return
self
.
aws
.
internalIP
,
nil
}
else
if
key
==
"public-ipv4"
{
return
self
.
aws
.
externalIP
,
nil
}
else
if
strings
.
HasPrefix
(
key
,
networkInterfacesPrefix
)
{
if
key
==
networkInterfacesPrefix
{
return
strings
.
Join
(
self
.
aws
.
networkInterfacesMacs
,
"/
\n
"
)
+
"/
\n
"
,
nil
...
...
@@ -467,12 +473,13 @@ func (a *FakeASG) DescribeAutoScalingGroups(*autoscaling.DescribeAutoScalingGrou
panic
(
"Not implemented"
)
}
func
mockInstancesResp
(
instances
[]
*
ec2
.
Instance
)
*
AWSCloud
{
func
mockInstancesResp
(
instances
[]
*
ec2
.
Instance
)
(
*
AWSCloud
,
*
FakeAWSServices
)
{
awsServices
:=
NewFakeAWSServices
()
.
withInstances
(
instances
)
return
&
AWSCloud
{
ec2
:
awsServices
.
ec2
,
availabilityZone
:
awsServices
.
availabilityZone
,
}
metadata
:
&
FakeMetadata
{
aws
:
awsServices
},
},
awsServices
}
func
mockAvailabilityZone
(
region
string
,
availabilityZone
string
)
*
AWSCloud
{
...
...
@@ -544,7 +551,7 @@ func TestList(t *testing.T) {
instance3
.
State
=
&
state3
instances
:=
[]
*
ec2
.
Instance
{
&
instance0
,
&
instance1
,
&
instance2
,
&
instance3
}
aws
:=
mockInstancesResp
(
instances
)
aws
,
_
:=
mockInstancesResp
(
instances
)
table
:=
[]
struct
{
input
string
...
...
@@ -604,19 +611,19 @@ func TestNodeAddresses(t *testing.T) {
instances
:=
[]
*
ec2
.
Instance
{
&
instance0
,
&
instance1
}
aws1
:=
mockInstancesResp
([]
*
ec2
.
Instance
{})
aws1
,
_
:=
mockInstancesResp
([]
*
ec2
.
Instance
{})
_
,
err1
:=
aws1
.
NodeAddresses
(
"instance-mismatch.ec2.internal"
)
if
err1
==
nil
{
t
.
Errorf
(
"Should error when no instance found"
)
}
aws2
:=
mockInstancesResp
(
instances
)
aws2
,
_
:=
mockInstancesResp
(
instances
)
_
,
err2
:=
aws2
.
NodeAddresses
(
"instance-same.ec2.internal"
)
if
err2
==
nil
{
t
.
Errorf
(
"Should error when multiple instances found"
)
}
aws3
:=
mockInstancesResp
(
instances
[
0
:
1
])
aws3
,
_
:=
mockInstancesResp
(
instances
[
0
:
1
])
addrs3
,
err3
:=
aws3
.
NodeAddresses
(
"instance-same.ec2.internal"
)
if
err3
!=
nil
{
t
.
Errorf
(
"Should not error when instance found"
)
...
...
@@ -627,6 +634,18 @@ func TestNodeAddresses(t *testing.T) {
testHasNodeAddress
(
t
,
addrs3
,
api
.
NodeInternalIP
,
"192.168.0.1"
)
testHasNodeAddress
(
t
,
addrs3
,
api
.
NodeLegacyHostIP
,
"192.168.0.1"
)
testHasNodeAddress
(
t
,
addrs3
,
api
.
NodeExternalIP
,
"1.2.3.4"
)
aws4
,
fakeServices
:=
mockInstancesResp
([]
*
ec2
.
Instance
{})
fakeServices
.
externalIP
=
"2.3.4.5"
fakeServices
.
internalIP
=
"192.168.0.2"
aws4
.
selfAWSInstance
=
&
awsInstance
{
nodeName
:
fakeServices
.
instanceId
}
addrs4
,
err4
:=
aws4
.
NodeAddresses
(
fakeServices
.
instanceId
)
if
err4
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err4
)
}
testHasNodeAddress
(
t
,
addrs4
,
api
.
NodeInternalIP
,
"192.168.0.2"
)
testHasNodeAddress
(
t
,
addrs4
,
api
.
NodeExternalIP
,
"2.3.4.5"
)
}
func
TestGetRegion
(
t
*
testing
.
T
)
{
...
...
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