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
55c4140a
Commit
55c4140a
authored
Oct 07, 2015
by
Justin Santa Barbara
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
AWS: Refactor interfaces to take a single request arg
Cleaning up some of the older code that tried to abstract the AWS SDK, from when the AWS SDK was less consistent (pre aws-sdk-go).
parent
c095e35f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
21 deletions
+22
-21
aws.go
pkg/cloudprovider/providers/aws/aws.go
+20
-19
aws_test.go
pkg/cloudprovider/providers/aws/aws_test.go
+2
-2
No files found.
pkg/cloudprovider/providers/aws/aws.go
View file @
55c4140a
...
@@ -74,7 +74,7 @@ type EC2 interface {
...
@@ -74,7 +74,7 @@ type EC2 interface {
DescribeInstances
(
request
*
ec2
.
DescribeInstancesInput
)
([]
*
ec2
.
Instance
,
error
)
DescribeInstances
(
request
*
ec2
.
DescribeInstancesInput
)
([]
*
ec2
.
Instance
,
error
)
// Attach a volume to an instance
// Attach a volume to an instance
AttachVolume
(
volumeID
,
instanceId
,
mountDevice
string
)
(
resp
*
ec2
.
VolumeAttachment
,
err
error
)
AttachVolume
(
*
ec2
.
AttachVolumeInput
)
(
*
ec2
.
VolumeAttachment
,
error
)
// Detach a volume from an instance it is attached to
// Detach a volume from an instance it is attached to
DetachVolume
(
request
*
ec2
.
DetachVolumeInput
)
(
resp
*
ec2
.
VolumeAttachment
,
err
error
)
DetachVolume
(
request
*
ec2
.
DetachVolumeInput
)
(
resp
*
ec2
.
VolumeAttachment
,
err
error
)
// Lists volumes
// Lists volumes
...
@@ -82,7 +82,7 @@ type EC2 interface {
...
@@ -82,7 +82,7 @@ type EC2 interface {
// Create an EBS volume
// Create an EBS volume
CreateVolume
(
request
*
ec2
.
CreateVolumeInput
)
(
resp
*
ec2
.
Volume
,
err
error
)
CreateVolume
(
request
*
ec2
.
CreateVolumeInput
)
(
resp
*
ec2
.
Volume
,
err
error
)
// Delete an EBS volume
// Delete an EBS volume
DeleteVolume
(
volumeID
string
)
(
resp
*
ec2
.
DeleteVolumeOutput
,
err
error
)
DeleteVolume
(
*
ec2
.
DeleteVolumeInput
)
(
*
ec2
.
DeleteVolumeOutput
,
error
)
DescribeSecurityGroups
(
request
*
ec2
.
DescribeSecurityGroupsInput
)
([]
*
ec2
.
SecurityGroup
,
error
)
DescribeSecurityGroups
(
request
*
ec2
.
DescribeSecurityGroupsInput
)
([]
*
ec2
.
SecurityGroup
,
error
)
...
@@ -347,13 +347,8 @@ func (s *awsSdkEC2) DescribeSecurityGroups(request *ec2.DescribeSecurityGroupsIn
...
@@ -347,13 +347,8 @@ func (s *awsSdkEC2) DescribeSecurityGroups(request *ec2.DescribeSecurityGroupsIn
return
response
.
SecurityGroups
,
nil
return
response
.
SecurityGroups
,
nil
}
}
func
(
s
*
awsSdkEC2
)
AttachVolume
(
volumeID
,
instanceId
,
device
string
)
(
resp
*
ec2
.
VolumeAttachment
,
err
error
)
{
func
(
s
*
awsSdkEC2
)
AttachVolume
(
request
*
ec2
.
AttachVolumeInput
)
(
*
ec2
.
VolumeAttachment
,
error
)
{
request
:=
ec2
.
AttachVolumeInput
{
return
s
.
ec2
.
AttachVolume
(
request
)
Device
:
&
device
,
InstanceId
:
&
instanceId
,
VolumeId
:
&
volumeID
,
}
return
s
.
ec2
.
AttachVolume
(
&
request
)
}
}
func
(
s
*
awsSdkEC2
)
DetachVolume
(
request
*
ec2
.
DetachVolumeInput
)
(
*
ec2
.
VolumeAttachment
,
error
)
{
func
(
s
*
awsSdkEC2
)
DetachVolume
(
request
*
ec2
.
DetachVolumeInput
)
(
*
ec2
.
VolumeAttachment
,
error
)
{
...
@@ -388,9 +383,8 @@ func (s *awsSdkEC2) CreateVolume(request *ec2.CreateVolumeInput) (resp *ec2.Volu
...
@@ -388,9 +383,8 @@ func (s *awsSdkEC2) CreateVolume(request *ec2.CreateVolumeInput) (resp *ec2.Volu
return
s
.
ec2
.
CreateVolume
(
request
)
return
s
.
ec2
.
CreateVolume
(
request
)
}
}
func
(
s
*
awsSdkEC2
)
DeleteVolume
(
volumeID
string
)
(
resp
*
ec2
.
DeleteVolumeOutput
,
err
error
)
{
func
(
s
*
awsSdkEC2
)
DeleteVolume
(
request
*
ec2
.
DeleteVolumeInput
)
(
*
ec2
.
DeleteVolumeOutput
,
error
)
{
request
:=
ec2
.
DeleteVolumeInput
{
VolumeId
:
&
volumeID
}
return
s
.
ec2
.
DeleteVolume
(
request
)
return
s
.
ec2
.
DeleteVolume
(
&
request
)
}
}
func
(
s
*
awsSdkEC2
)
DescribeSubnets
(
request
*
ec2
.
DescribeSubnetsInput
)
([]
*
ec2
.
Subnet
,
error
)
{
func
(
s
*
awsSdkEC2
)
DescribeSubnets
(
request
*
ec2
.
DescribeSubnetsInput
)
([]
*
ec2
.
Subnet
,
error
)
{
...
@@ -1032,8 +1026,9 @@ func (self *awsDisk) waitForAttachmentStatus(status string) error {
...
@@ -1032,8 +1026,9 @@ func (self *awsDisk) waitForAttachmentStatus(status string) error {
}
}
// Deletes the EBS disk
// Deletes the EBS disk
func
(
self
*
awsDisk
)
delete
()
error
{
func
(
self
*
awsDisk
)
deleteVolume
()
error
{
_
,
err
:=
self
.
ec2
.
DeleteVolume
(
self
.
awsID
)
request
:=
&
ec2
.
DeleteVolumeInput
{
VolumeId
:
aws
.
String
(
self
.
awsID
)}
_
,
err
:=
self
.
ec2
.
DeleteVolume
(
request
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"error delete EBS volumes: %v"
,
err
)
return
fmt
.
Errorf
(
"error delete EBS volumes: %v"
,
err
)
}
}
...
@@ -1088,13 +1083,13 @@ func (aws *AWSCloud) getAwsInstance(nodeName string) (*awsInstance, error) {
...
@@ -1088,13 +1083,13 @@ func (aws *AWSCloud) getAwsInstance(nodeName string) (*awsInstance, error) {
}
}
// Implements Volumes.AttachDisk
// Implements Volumes.AttachDisk
func
(
aws
*
AWSCloud
)
AttachDisk
(
instanceName
string
,
diskName
string
,
readOnly
bool
)
(
string
,
error
)
{
func
(
c
*
AWSCloud
)
AttachDisk
(
instanceName
string
,
diskName
string
,
readOnly
bool
)
(
string
,
error
)
{
disk
,
err
:=
newAWSDisk
(
aws
,
diskName
)
disk
,
err
:=
newAWSDisk
(
c
,
diskName
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
awsInstance
,
err
:=
aws
.
getAwsInstance
(
instanceName
)
awsInstance
,
err
:=
c
.
getAwsInstance
(
instanceName
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
...
@@ -1127,7 +1122,13 @@ func (aws *AWSCloud) AttachDisk(instanceName string, diskName string, readOnly b
...
@@ -1127,7 +1122,13 @@ func (aws *AWSCloud) AttachDisk(instanceName string, diskName string, readOnly b
}()
}()
if
!
alreadyAttached
{
if
!
alreadyAttached
{
attachResponse
,
err
:=
aws
.
ec2
.
AttachVolume
(
disk
.
awsID
,
awsInstance
.
awsID
,
ec2Device
)
request
:=
&
ec2
.
AttachVolumeInput
{
Device
:
aws
.
String
(
ec2Device
),
InstanceId
:
aws
.
String
(
awsInstance
.
awsID
),
VolumeId
:
aws
.
String
(
disk
.
awsID
),
}
attachResponse
,
err
:=
c
.
ec2
.
AttachVolume
(
request
)
if
err
!=
nil
{
if
err
!=
nil
{
// TODO: Check if the volume was concurrently attached?
// TODO: Check if the volume was concurrently attached?
return
""
,
fmt
.
Errorf
(
"Error attaching EBS volume: %v"
,
err
)
return
""
,
fmt
.
Errorf
(
"Error attaching EBS volume: %v"
,
err
)
...
@@ -1224,7 +1225,7 @@ func (aws *AWSCloud) DeleteVolume(volumeName string) error {
...
@@ -1224,7 +1225,7 @@ func (aws *AWSCloud) DeleteVolume(volumeName string) error {
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
return
awsDisk
.
delete
()
return
awsDisk
.
delete
Volume
()
}
}
func
(
v
*
AWSCloud
)
Configure
(
name
string
,
spec
*
api
.
NodeSpec
)
error
{
func
(
v
*
AWSCloud
)
Configure
(
name
string
,
spec
*
api
.
NodeSpec
)
error
{
...
...
pkg/cloudprovider/providers/aws/aws_test.go
View file @
55c4140a
...
@@ -343,7 +343,7 @@ func (self *FakeMetadata) GetMetadata(key string) (string, error) {
...
@@ -343,7 +343,7 @@ func (self *FakeMetadata) GetMetadata(key string) (string, error) {
}
}
}
}
func
(
ec2
*
FakeEC2
)
AttachVolume
(
volumeID
,
instanceId
,
mountDevice
string
)
(
resp
*
ec2
.
VolumeAttachment
,
err
error
)
{
func
(
ec2
*
FakeEC2
)
AttachVolume
(
request
*
ec2
.
AttachVolumeInput
)
(
resp
*
ec2
.
VolumeAttachment
,
err
error
)
{
panic
(
"Not implemented"
)
panic
(
"Not implemented"
)
}
}
...
@@ -359,7 +359,7 @@ func (ec2 *FakeEC2) CreateVolume(request *ec2.CreateVolumeInput) (resp *ec2.Volu
...
@@ -359,7 +359,7 @@ func (ec2 *FakeEC2) CreateVolume(request *ec2.CreateVolumeInput) (resp *ec2.Volu
panic
(
"Not implemented"
)
panic
(
"Not implemented"
)
}
}
func
(
ec2
*
FakeEC2
)
DeleteVolume
(
volumeID
string
)
(
resp
*
ec2
.
DeleteVolumeOutput
,
err
error
)
{
func
(
ec2
*
FakeEC2
)
DeleteVolume
(
request
*
ec2
.
DeleteVolumeInput
)
(
resp
*
ec2
.
DeleteVolumeOutput
,
err
error
)
{
panic
(
"Not implemented"
)
panic
(
"Not implemented"
)
}
}
...
...
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