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
d72f88bf
Commit
d72f88bf
authored
Jun 16, 2016
by
saadali
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modify Attach method to return device path
parent
926bb4cc
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
60 additions
and
47 deletions
+60
-47
attacher.go
pkg/volume/aws_ebs/attacher.go
+9
-19
attacher.go
pkg/volume/cinder/attacher.go
+15
-10
attacher.go
pkg/volume/gce_pd/attacher.go
+8
-9
attacher_test.go
pkg/volume/gce_pd/attacher_test.go
+21
-4
testing.go
pkg/volume/testing/testing.go
+2
-2
operation_executor.go
pkg/volume/util/operationexecutor/operation_executor.go
+1
-1
volume.go
pkg/volume/volume.go
+4
-2
No files found.
pkg/volume/aws_ebs/attacher.go
View file @
d72f88bf
...
@@ -41,38 +41,28 @@ func (plugin *awsElasticBlockStorePlugin) NewAttacher() (volume.Attacher, error)
...
@@ -41,38 +41,28 @@ func (plugin *awsElasticBlockStorePlugin) NewAttacher() (volume.Attacher, error)
return
&
awsElasticBlockStoreAttacher
{
host
:
plugin
.
host
},
nil
return
&
awsElasticBlockStoreAttacher
{
host
:
plugin
.
host
},
nil
}
}
func
(
attacher
*
awsElasticBlockStoreAttacher
)
Attach
(
spec
*
volume
.
Spec
,
hostName
string
)
error
{
func
(
attacher
*
awsElasticBlockStoreAttacher
)
Attach
(
spec
*
volume
.
Spec
,
hostName
string
)
(
string
,
error
)
{
volumeSource
,
readOnly
,
err
:=
getVolumeSource
(
spec
)
volumeSource
,
readOnly
,
err
:=
getVolumeSource
(
spec
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
""
,
err
}
}
volumeID
:=
volumeSource
.
VolumeID
volumeID
:=
volumeSource
.
VolumeID
awsCloud
,
err
:=
getCloudProvider
(
attacher
.
host
.
GetCloudProvider
())
awsCloud
,
err
:=
getCloudProvider
(
attacher
.
host
.
GetCloudProvider
())
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
""
,
err
}
}
attached
,
err
:=
awsCloud
.
DiskIsAttached
(
volumeID
,
hostName
)
// awsCloud.AttachDisk checks if disk is already attached to node and
// succeeds in that case, so no need to do that separately.
devicePath
,
err
:=
awsCloud
.
AttachDisk
(
volumeID
,
hostName
,
readOnly
)
if
err
!=
nil
{
if
err
!=
nil
{
// Log error and continue with attach
glog
.
Errorf
(
"Error checking if volume (%q) is already attached to current node (%q). Will continue and try attach anyway. err=%v"
,
volumeID
,
hostName
,
err
)
}
if
err
==
nil
&&
attached
{
// Volume is already attached to node.
glog
.
Infof
(
"Attach operation is successful. volume %q is already attached to node %q."
,
volumeID
,
hostName
)
return
nil
}
if
_
,
err
=
awsCloud
.
AttachDisk
(
volumeID
,
hostName
,
readOnly
);
err
!=
nil
{
glog
.
Errorf
(
"Error attaching volume %q: %+v"
,
volumeID
,
err
)
glog
.
Errorf
(
"Error attaching volume %q: %+v"
,
volumeID
,
err
)
return
err
return
""
,
err
}
}
return
nil
return
devicePath
,
nil
}
}
func
(
attacher
*
awsElasticBlockStoreAttacher
)
WaitForAttach
(
spec
*
volume
.
Spec
,
timeout
time
.
Duration
)
(
string
,
error
)
{
func
(
attacher
*
awsElasticBlockStoreAttacher
)
WaitForAttach
(
spec
*
volume
.
Spec
,
timeout
time
.
Duration
)
(
string
,
error
)
{
...
...
pkg/volume/cinder/attacher.go
View file @
d72f88bf
...
@@ -45,25 +45,25 @@ func (plugin *cinderPlugin) NewAttacher() (volume.Attacher, error) {
...
@@ -45,25 +45,25 @@ func (plugin *cinderPlugin) NewAttacher() (volume.Attacher, error) {
return
&
cinderDiskAttacher
{
host
:
plugin
.
host
},
nil
return
&
cinderDiskAttacher
{
host
:
plugin
.
host
},
nil
}
}
func
(
attacher
*
cinderDiskAttacher
)
Attach
(
spec
*
volume
.
Spec
,
hostName
string
)
error
{
func
(
attacher
*
cinderDiskAttacher
)
Attach
(
spec
*
volume
.
Spec
,
hostName
string
)
(
string
,
error
)
{
volumeSource
,
_
,
err
:=
getVolumeSource
(
spec
)
volumeSource
,
_
,
err
:=
getVolumeSource
(
spec
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
""
,
err
}
}
volumeID
:=
volumeSource
.
VolumeID
volumeID
:=
volumeSource
.
VolumeID
cloud
,
err
:=
getCloudProvider
(
attacher
.
host
.
GetCloudProvider
())
cloud
,
err
:=
getCloudProvider
(
attacher
.
host
.
GetCloudProvider
())
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
""
,
err
}
}
instances
,
res
:=
cloud
.
Instances
()
instances
,
res
:=
cloud
.
Instances
()
if
!
res
{
if
!
res
{
return
fmt
.
Errorf
(
"failed to list openstack instances"
)
return
""
,
fmt
.
Errorf
(
"failed to list openstack instances"
)
}
}
instanceid
,
err
:=
instances
.
InstanceID
(
hostName
)
instanceid
,
err
:=
instances
.
InstanceID
(
hostName
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
""
,
err
}
}
if
ind
:=
strings
.
LastIndex
(
instanceid
,
"/"
);
ind
>=
0
{
if
ind
:=
strings
.
LastIndex
(
instanceid
,
"/"
);
ind
>=
0
{
instanceid
=
instanceid
[(
ind
+
1
)
:
]
instanceid
=
instanceid
[(
ind
+
1
)
:
]
...
@@ -79,15 +79,20 @@ func (attacher *cinderDiskAttacher) Attach(spec *volume.Spec, hostName string) e
...
@@ -79,15 +79,20 @@ func (attacher *cinderDiskAttacher) Attach(spec *volume.Spec, hostName string) e
if
err
==
nil
&&
attached
{
if
err
==
nil
&&
attached
{
// Volume is already attached to node.
// Volume is already attached to node.
glog
.
Infof
(
"Attach operation is successful. volume %q is already attached to node %q."
,
volumeID
,
instanceid
)
glog
.
Infof
(
"Attach operation is successful. volume %q is already attached to node %q."
,
volumeID
,
instanceid
)
return
nil
}
else
{
_
,
err
=
cloud
.
AttachDisk
(
instanceid
,
volumeID
)
if
err
!=
nil
{
glog
.
Infof
(
"attach volume %q to instance %q gets %v"
,
volumeID
,
instanceid
,
err
)
}
}
}
_
,
err
=
cloud
.
AttachDisk
(
instanceid
,
volumeID
)
glog
.
Infof
(
"attached volume %q to instance %q"
,
volumeID
,
instanceid
)
devicePath
,
err
:=
cloud
.
GetAttachmentDiskPath
(
instanceid
,
volumeID
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Infof
(
"attach volume %q to instance %q gets %v"
,
volumeID
,
instanceid
,
err
)
return
""
,
err
}
}
glog
.
Infof
(
"attached volume %q to instance %q"
,
volumeID
,
instanceid
)
return
err
return
devicePath
,
err
}
}
func
(
attacher
*
cinderDiskAttacher
)
WaitForAttach
(
spec
*
volume
.
Spec
,
timeout
time
.
Duration
)
(
string
,
error
)
{
func
(
attacher
*
cinderDiskAttacher
)
WaitForAttach
(
spec
*
volume
.
Spec
,
timeout
time
.
Duration
)
(
string
,
error
)
{
...
...
pkg/volume/gce_pd/attacher.go
View file @
d72f88bf
...
@@ -60,10 +60,10 @@ func (plugin *gcePersistentDiskPlugin) NewAttacher() (volume.Attacher, error) {
...
@@ -60,10 +60,10 @@ func (plugin *gcePersistentDiskPlugin) NewAttacher() (volume.Attacher, error) {
// Callers are responsible for retryinging on failure.
// Callers are responsible for retryinging on failure.
// Callers are responsible for thread safety between concurrent attach and
// Callers are responsible for thread safety between concurrent attach and
// detach operations.
// detach operations.
func
(
attacher
*
gcePersistentDiskAttacher
)
Attach
(
spec
*
volume
.
Spec
,
hostName
string
)
error
{
func
(
attacher
*
gcePersistentDiskAttacher
)
Attach
(
spec
*
volume
.
Spec
,
hostName
string
)
(
string
,
error
)
{
volumeSource
,
readOnly
,
err
:=
getVolumeSource
(
spec
)
volumeSource
,
readOnly
,
err
:=
getVolumeSource
(
spec
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
""
,
err
}
}
pdName
:=
volumeSource
.
PDName
pdName
:=
volumeSource
.
PDName
...
@@ -79,15 +79,14 @@ func (attacher *gcePersistentDiskAttacher) Attach(spec *volume.Spec, hostName st
...
@@ -79,15 +79,14 @@ func (attacher *gcePersistentDiskAttacher) Attach(spec *volume.Spec, hostName st
if
err
==
nil
&&
attached
{
if
err
==
nil
&&
attached
{
// Volume is already attached to node.
// Volume is already attached to node.
glog
.
Infof
(
"Attach operation is successful. PD %q is already attached to node %q."
,
pdName
,
hostName
)
glog
.
Infof
(
"Attach operation is successful. PD %q is already attached to node %q."
,
pdName
,
hostName
)
return
nil
}
else
{
}
if
err
:=
attacher
.
gceDisks
.
AttachDisk
(
pdName
,
hostName
,
readOnly
);
err
!=
nil
{
glog
.
Errorf
(
"Error attaching PD %q to node %q: %+v"
,
pdName
,
hostName
,
err
)
if
err
=
attacher
.
gceDisks
.
AttachDisk
(
pdName
,
hostName
,
readOnly
);
err
!=
nil
{
return
""
,
err
glog
.
Errorf
(
"Error attaching PD %q to node %q: %+v"
,
pdName
,
hostName
,
err
)
}
return
err
}
}
return
nil
return
path
.
Join
(
diskByIdPath
,
diskGooglePrefix
+
pdName
),
nil
}
}
func
(
attacher
*
gcePersistentDiskAttacher
)
WaitForAttach
(
spec
*
volume
.
Spec
,
timeout
time
.
Duration
)
(
string
,
error
)
{
func
(
attacher
*
gcePersistentDiskAttacher
)
WaitForAttach
(
spec
*
volume
.
Spec
,
timeout
time
.
Duration
)
(
string
,
error
)
{
...
...
pkg/volume/gce_pd/attacher_test.go
View file @
d72f88bf
...
@@ -18,6 +18,7 @@ package gce_pd
...
@@ -18,6 +18,7 @@ package gce_pd
import
(
import
(
"errors"
"errors"
"fmt"
"testing"
"testing"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
...
@@ -86,7 +87,11 @@ func TestAttachDetach(t *testing.T) {
...
@@ -86,7 +87,11 @@ func TestAttachDetach(t *testing.T) {
attach
:
attachCall
{
diskName
,
instanceID
,
readOnly
,
nil
},
attach
:
attachCall
{
diskName
,
instanceID
,
readOnly
,
nil
},
test
:
func
(
testcase
*
testcase
)
error
{
test
:
func
(
testcase
*
testcase
)
error
{
attacher
:=
newAttacher
(
testcase
)
attacher
:=
newAttacher
(
testcase
)
return
attacher
.
Attach
(
spec
,
instanceID
)
devicePath
,
err
:=
attacher
.
Attach
(
spec
,
instanceID
)
if
devicePath
!=
"/dev/disk/by-id/google-disk"
{
return
fmt
.
Errorf
(
"devicePath incorrect. Expected<
\"
/dev/disk/by-id/google-disk
\"
> Actual: <%q>"
,
devicePath
)
}
return
err
},
},
},
},
...
@@ -96,7 +101,11 @@ func TestAttachDetach(t *testing.T) {
...
@@ -96,7 +101,11 @@ func TestAttachDetach(t *testing.T) {
diskIsAttached
:
diskIsAttachedCall
{
diskName
,
instanceID
,
true
,
nil
},
diskIsAttached
:
diskIsAttachedCall
{
diskName
,
instanceID
,
true
,
nil
},
test
:
func
(
testcase
*
testcase
)
error
{
test
:
func
(
testcase
*
testcase
)
error
{
attacher
:=
newAttacher
(
testcase
)
attacher
:=
newAttacher
(
testcase
)
return
attacher
.
Attach
(
spec
,
instanceID
)
devicePath
,
err
:=
attacher
.
Attach
(
spec
,
instanceID
)
if
devicePath
!=
"/dev/disk/by-id/google-disk"
{
return
fmt
.
Errorf
(
"devicePath incorrect. Expected<
\"
/dev/disk/by-id/google-disk
\"
> Actual: <%q>"
,
devicePath
)
}
return
err
},
},
},
},
...
@@ -107,7 +116,11 @@ func TestAttachDetach(t *testing.T) {
...
@@ -107,7 +116,11 @@ func TestAttachDetach(t *testing.T) {
attach
:
attachCall
{
diskName
,
instanceID
,
readOnly
,
nil
},
attach
:
attachCall
{
diskName
,
instanceID
,
readOnly
,
nil
},
test
:
func
(
testcase
*
testcase
)
error
{
test
:
func
(
testcase
*
testcase
)
error
{
attacher
:=
newAttacher
(
testcase
)
attacher
:=
newAttacher
(
testcase
)
return
attacher
.
Attach
(
spec
,
instanceID
)
devicePath
,
err
:=
attacher
.
Attach
(
spec
,
instanceID
)
if
devicePath
!=
"/dev/disk/by-id/google-disk"
{
return
fmt
.
Errorf
(
"devicePath incorrect. Expected<
\"
/dev/disk/by-id/google-disk
\"
> Actual: <%q>"
,
devicePath
)
}
return
err
},
},
},
},
...
@@ -118,7 +131,11 @@ func TestAttachDetach(t *testing.T) {
...
@@ -118,7 +131,11 @@ func TestAttachDetach(t *testing.T) {
attach
:
attachCall
{
diskName
,
instanceID
,
readOnly
,
attachError
},
attach
:
attachCall
{
diskName
,
instanceID
,
readOnly
,
attachError
},
test
:
func
(
testcase
*
testcase
)
error
{
test
:
func
(
testcase
*
testcase
)
error
{
attacher
:=
newAttacher
(
testcase
)
attacher
:=
newAttacher
(
testcase
)
return
attacher
.
Attach
(
spec
,
instanceID
)
devicePath
,
err
:=
attacher
.
Attach
(
spec
,
instanceID
)
if
devicePath
!=
""
{
return
fmt
.
Errorf
(
"devicePath incorrect. Expected<
\"\"
> Actual: <%q>"
,
devicePath
)
}
return
err
},
},
expectedReturn
:
attachError
,
expectedReturn
:
attachError
,
},
},
...
...
pkg/volume/testing/testing.go
View file @
d72f88bf
...
@@ -358,11 +358,11 @@ func (fv *FakeVolume) TearDownAt(dir string) error {
...
@@ -358,11 +358,11 @@ func (fv *FakeVolume) TearDownAt(dir string) error {
return
os
.
RemoveAll
(
dir
)
return
os
.
RemoveAll
(
dir
)
}
}
func
(
fv
*
FakeVolume
)
Attach
(
spec
*
Spec
,
hostName
string
)
error
{
func
(
fv
*
FakeVolume
)
Attach
(
spec
*
Spec
,
hostName
string
)
(
string
,
error
)
{
fv
.
Lock
()
fv
.
Lock
()
defer
fv
.
Unlock
()
defer
fv
.
Unlock
()
fv
.
AttachCallCount
++
fv
.
AttachCallCount
++
return
nil
return
""
,
nil
}
}
func
(
fv
*
FakeVolume
)
GetAttachCallCount
()
int
{
func
(
fv
*
FakeVolume
)
GetAttachCallCount
()
int
{
...
...
pkg/volume/util/operationexecutor/operation_executor.go
View file @
d72f88bf
...
@@ -385,7 +385,7 @@ func (oe *operationExecutor) generateAttachVolumeFunc(
...
@@ -385,7 +385,7 @@ func (oe *operationExecutor) generateAttachVolumeFunc(
return
func
()
error
{
return
func
()
error
{
// Execute attach
// Execute attach
attachErr
:=
volumeAttacher
.
Attach
(
_
,
attachErr
:=
volumeAttacher
.
Attach
(
volumeToAttach
.
VolumeSpec
,
volumeToAttach
.
NodeName
)
volumeToAttach
.
VolumeSpec
,
volumeToAttach
.
NodeName
)
if
attachErr
!=
nil
{
if
attachErr
!=
nil
{
...
...
pkg/volume/volume.go
View file @
d72f88bf
...
@@ -134,8 +134,10 @@ type Deleter interface {
...
@@ -134,8 +134,10 @@ type Deleter interface {
// Attacher can attach a volume to a node.
// Attacher can attach a volume to a node.
type
Attacher
interface
{
type
Attacher
interface
{
// Attach the volume specified by the given spec to the given host
// Attaches the volume specified by the given spec to the given host.
Attach
(
spec
*
Spec
,
hostName
string
)
error
// On success, returns the device path where the device was attache don the
// node.
Attach
(
spec
*
Spec
,
hostName
string
)
(
string
,
error
)
// WaitForAttach blocks until the device is attached to this
// WaitForAttach blocks until the device is attached to this
// node. If it successfully attaches, the path to the device
// node. If it successfully attaches, the path to the device
...
...
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