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
ee72fa4d
Commit
ee72fa4d
authored
Apr 02, 2015
by
Justin Santa Barbara
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tolerate volume being already-attached
parent
86ddc0f9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
13 deletions
+17
-13
aws.go
pkg/cloudprovider/aws/aws.go
+17
-13
No files found.
pkg/cloudprovider/aws/aws.go
View file @
ee72fa4d
...
@@ -640,10 +640,12 @@ func (self *awsInstance) getInfo() (*ec2.Instance, error) {
...
@@ -640,10 +640,12 @@ func (self *awsInstance) getInfo() (*ec2.Instance, error) {
return
&
resp
.
Reservations
[
0
]
.
Instances
[
0
],
nil
return
&
resp
.
Reservations
[
0
]
.
Instances
[
0
],
nil
}
}
func
(
self
*
awsInstance
)
assignMountDevice
(
volumeId
string
)
(
string
,
error
)
{
// Assigns an unused mount device for the specified volume.
// If the volume is already assigned, this will return the existing mount device and true
func
(
self
*
awsInstance
)
assignMountDevice
(
volumeId
string
)
(
mountDevice
string
,
alreadyAttached
bool
,
err
error
)
{
instanceType
:=
self
.
getInstanceType
()
instanceType
:=
self
.
getInstanceType
()
if
instanceType
==
nil
{
if
instanceType
==
nil
{
return
""
,
fmt
.
Errorf
(
"could not get instance type for instance: %s"
,
self
.
awsId
)
return
""
,
f
alse
,
f
mt
.
Errorf
(
"could not get instance type for instance: %s"
,
self
.
awsId
)
}
}
// We lock to prevent concurrent mounts from conflicting
// We lock to prevent concurrent mounts from conflicting
...
@@ -656,7 +658,7 @@ func (self *awsInstance) assignMountDevice(volumeId string) (string, error) {
...
@@ -656,7 +658,7 @@ func (self *awsInstance) assignMountDevice(volumeId string) (string, error) {
if
self
.
deviceMappings
==
nil
{
if
self
.
deviceMappings
==
nil
{
info
,
err
:=
self
.
getInfo
()
info
,
err
:=
self
.
getInfo
()
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
false
,
err
}
}
deviceMappings
:=
map
[
string
]
string
{}
deviceMappings
:=
map
[
string
]
string
{}
for
_
,
blockDevice
:=
range
info
.
BlockDevices
{
for
_
,
blockDevice
:=
range
info
.
BlockDevices
{
...
@@ -669,7 +671,7 @@ func (self *awsInstance) assignMountDevice(volumeId string) (string, error) {
...
@@ -669,7 +671,7 @@ func (self *awsInstance) assignMountDevice(volumeId string) (string, error) {
for
deviceName
,
mappingVolumeId
:=
range
self
.
deviceMappings
{
for
deviceName
,
mappingVolumeId
:=
range
self
.
deviceMappings
{
if
volumeId
==
mappingVolumeId
{
if
volumeId
==
mappingVolumeId
{
glog
.
Warningf
(
"Got assignment call for already-assigned volume: %s@%s"
,
deviceName
,
mappingVolumeId
)
glog
.
Warningf
(
"Got assignment call for already-assigned volume: %s@%s"
,
deviceName
,
mappingVolumeId
)
return
deviceName
,
nil
return
deviceName
,
true
,
nil
}
}
}
}
...
@@ -686,13 +688,13 @@ func (self *awsInstance) assignMountDevice(volumeId string) (string, error) {
...
@@ -686,13 +688,13 @@ func (self *awsInstance) assignMountDevice(volumeId string) (string, error) {
if
chosen
==
""
{
if
chosen
==
""
{
glog
.
Warningf
(
"Could not assign a mount device (all in use?). mappings=%v, valid=%v"
,
self
.
deviceMappings
,
valid
)
glog
.
Warningf
(
"Could not assign a mount device (all in use?). mappings=%v, valid=%v"
,
self
.
deviceMappings
,
valid
)
return
""
,
nil
return
""
,
false
,
nil
}
}
self
.
deviceMappings
[
chosen
]
=
volumeId
self
.
deviceMappings
[
chosen
]
=
volumeId
glog
.
V
(
2
)
.
Infof
(
"Assigned mount device %s -> volume %s"
,
chosen
,
volumeId
)
glog
.
V
(
2
)
.
Infof
(
"Assigned mount device %s -> volume %s"
,
chosen
,
volumeId
)
return
chosen
,
nil
return
chosen
,
false
,
nil
}
}
func
(
self
*
awsInstance
)
releaseMountDevice
(
volumeId
string
,
mountDevice
string
)
{
func
(
self
*
awsInstance
)
releaseMountDevice
(
volumeId
string
,
mountDevice
string
)
{
...
@@ -841,7 +843,7 @@ func (aws *AWSCloud) AttachDisk(instanceName string, diskName string, readOnly b
...
@@ -841,7 +843,7 @@ func (aws *AWSCloud) AttachDisk(instanceName string, diskName string, readOnly b
return
errors
.
New
(
"AWS volumes cannot be mounted read-only"
)
return
errors
.
New
(
"AWS volumes cannot be mounted read-only"
)
}
}
mountDevice
,
err
:=
awsInstance
.
assignMountDevice
(
disk
.
awsId
)
mountDevice
,
alreadyAttached
,
err
:=
awsInstance
.
assignMountDevice
(
disk
.
awsId
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -853,13 +855,15 @@ func (aws *AWSCloud) AttachDisk(instanceName string, diskName string, readOnly b
...
@@ -853,13 +855,15 @@ func (aws *AWSCloud) AttachDisk(instanceName string, diskName string, readOnly b
}
}
}()
}()
attachResponse
,
err
:=
aws
.
ec2
.
AttachVolume
(
disk
.
awsId
,
awsInstance
.
awsId
,
mountDevice
)
if
!
alreadyAttached
{
if
err
!=
nil
{
attachResponse
,
err
:=
aws
.
ec2
.
AttachVolume
(
disk
.
awsId
,
awsInstance
.
awsId
,
mountDevice
)
// TODO: Check if already attached?
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Error attaching EBS volume: %v"
,
err
)
// TODO: Check if already attached?
}
return
fmt
.
Errorf
(
"Error attaching EBS volume: %v"
,
err
)
}
glog
.
V
(
2
)
.
Info
(
"AttachVolume request returned %v"
,
attachResponse
)
glog
.
V
(
2
)
.
Info
(
"AttachVolume request returned %v"
,
attachResponse
)
}
err
=
disk
.
waitForAttachmentStatus
(
"attached"
)
err
=
disk
.
waitForAttachmentStatus
(
"attached"
)
if
err
!=
nil
{
if
err
!=
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