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
cc81742e
Commit
cc81742e
authored
Mar 05, 2015
by
Justin Santa Barbara
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement EC2 filter in tests
parent
ce908368
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
8 deletions
+47
-8
aws.go
pkg/cloudprovider/aws/aws.go
+37
-4
aws_test.go
pkg/cloudprovider/aws/aws_test.go
+10
-4
No files found.
pkg/cloudprovider/aws/aws.go
View file @
cc81742e
...
@@ -30,8 +30,10 @@ import (
...
@@ -30,8 +30,10 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
)
)
// Abstraction over EC2, to allow mocking/other implementations
type
EC2
interface
{
type
EC2
interface
{
Instances
(
instIds
[]
string
,
filter
*
ec2
.
Filter
)
(
resp
*
ec2
.
InstancesResp
,
err
error
)
// Query EC2 for instances matching the filter
Instances
(
instIds
[]
string
,
filter
*
ec2InstanceFilter
)
(
resp
*
ec2
.
InstancesResp
,
err
error
)
}
}
// 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.
...
@@ -46,6 +48,37 @@ type AWSCloudConfig struct {
...
@@ -46,6 +48,37 @@ type AWSCloudConfig struct {
}
}
}
}
// Similar to ec2.Filter, but the filter values can be read from tests
// (ec2.Filter only has private members)
type
ec2InstanceFilter
struct
{
PrivateDNSName
string
}
// True if the passed instance matches the filter
func
(
f
*
ec2InstanceFilter
)
Matches
(
instance
ec2
.
Instance
)
bool
{
if
f
.
PrivateDNSName
!=
""
&&
instance
.
PrivateDNSName
!=
f
.
PrivateDNSName
{
return
false
}
return
true
}
// goamzEC2 is an implementation of the EC2 interface, backed by goamz
type
GoamzEC2
struct
{
ec2
*
ec2
.
EC2
}
// Implementation of EC2.Instances
func
(
self
*
GoamzEC2
)
Instances
(
instanceIds
[]
string
,
filter
*
ec2InstanceFilter
)
(
resp
*
ec2
.
InstancesResp
,
err
error
)
{
var
goamzFilter
*
ec2
.
Filter
if
filter
!=
nil
{
goamzFilter
=
ec2
.
NewFilter
()
if
filter
.
PrivateDNSName
!=
""
{
goamzFilter
.
Add
(
"private-dns-name"
,
filter
.
PrivateDNSName
)
}
}
return
self
.
ec2
.
Instances
(
instanceIds
,
goamzFilter
)
}
type
AuthFunc
func
()
(
auth
aws
.
Auth
,
err
error
)
type
AuthFunc
func
()
(
auth
aws
.
Auth
,
err
error
)
func
init
()
{
func
init
()
{
...
@@ -96,7 +129,7 @@ func newAWSCloud(config io.Reader, authFunc AuthFunc) (*AWSCloud, error) {
...
@@ -96,7 +129,7 @@ func newAWSCloud(config io.Reader, authFunc AuthFunc) (*AWSCloud, error) {
ec2
:=
ec2
.
New
(
auth
,
region
)
ec2
:=
ec2
.
New
(
auth
,
region
)
return
&
AWSCloud
{
return
&
AWSCloud
{
ec2
:
ec2
,
ec2
:
&
GoamzEC2
{
ec2
:
ec2
}
,
cfg
:
cfg
,
cfg
:
cfg
,
},
nil
},
nil
}
}
...
@@ -144,8 +177,8 @@ func (aws *AWSCloud) ExternalID(name string) (string, error) {
...
@@ -144,8 +177,8 @@ func (aws *AWSCloud) ExternalID(name string) (string, error) {
// Return the instances matching the relevant private dns name.
// Return the instances matching the relevant private dns name.
func
(
aws
*
AWSCloud
)
getInstancesByDnsName
(
name
string
)
(
*
ec2
.
Instance
,
error
)
{
func
(
aws
*
AWSCloud
)
getInstancesByDnsName
(
name
string
)
(
*
ec2
.
Instance
,
error
)
{
f
:=
ec2
.
NewFilter
()
f
:=
&
ec2InstanceFilter
{}
f
.
Add
(
"private-dns-name"
,
name
)
f
.
PrivateDNSName
=
name
resp
,
err
:=
aws
.
ec2
.
Instances
(
nil
,
f
)
resp
,
err
:=
aws
.
ec2
.
Instances
(
nil
,
f
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/cloudprovider/aws/aws_test.go
View file @
cc81742e
...
@@ -76,20 +76,26 @@ func TestNewAWSCloud(t *testing.T) {
...
@@ -76,20 +76,26 @@ func TestNewAWSCloud(t *testing.T) {
}
}
type
FakeEC2
struct
{
type
FakeEC2
struct
{
instances
func
(
instanceIds
[]
string
,
filter
*
ec2
.
Filter
)
(
resp
*
ec2
.
InstancesResp
,
err
error
)
instances
func
(
instanceIds
[]
string
,
filter
*
ec2
Instance
Filter
)
(
resp
*
ec2
.
InstancesResp
,
err
error
)
}
}
func
(
ec2
*
FakeEC2
)
Instances
(
instanceIds
[]
string
,
filter
*
ec2
.
Filter
)
(
resp
*
ec2
.
InstancesResp
,
err
error
)
{
func
(
ec2
*
FakeEC2
)
Instances
(
instanceIds
[]
string
,
filter
*
ec2
Instance
Filter
)
(
resp
*
ec2
.
InstancesResp
,
err
error
)
{
return
ec2
.
instances
(
instanceIds
,
filter
)
return
ec2
.
instances
(
instanceIds
,
filter
)
}
}
func
mockInstancesResp
(
instances
[]
ec2
.
Instance
)
(
aws
*
AWSCloud
)
{
func
mockInstancesResp
(
instances
[]
ec2
.
Instance
)
(
aws
*
AWSCloud
)
{
return
&
AWSCloud
{
return
&
AWSCloud
{
&
FakeEC2
{
&
FakeEC2
{
func
(
instanceIds
[]
string
,
filter
*
ec2
.
Filter
)
(
resp
*
ec2
.
InstancesResp
,
err
error
)
{
func
(
instanceIds
[]
string
,
filter
*
ec2InstanceFilter
)
(
resp
*
ec2
.
InstancesResp
,
err
error
)
{
matches
:=
[]
ec2
.
Instance
{}
for
_
,
instance
:=
range
instances
{
if
filter
==
nil
||
filter
.
Matches
(
instance
)
{
matches
=
append
(
matches
,
instance
)
}
}
return
&
ec2
.
InstancesResp
{
""
,
return
&
ec2
.
InstancesResp
{
""
,
[]
ec2
.
Reservation
{
[]
ec2
.
Reservation
{
{
""
,
""
,
""
,
nil
,
instanc
es
}}},
nil
{
""
,
""
,
""
,
nil
,
match
es
}}},
nil
}},
}},
nil
}
nil
}
}
}
...
...
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