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
ba63590e
Commit
ba63590e
authored
Jun 21, 2016
by
Jan Safranek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add AWS volume plugin attach tests.
parent
a8fecd0c
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
21 deletions
+30
-21
attacher.go
pkg/volume/aws_ebs/attacher.go
+27
-18
attacher_test.go
pkg/volume/aws_ebs/attacher_test.go
+0
-0
attacher_test.go
pkg/volume/gce_pd/attacher_test.go
+3
-3
No files found.
pkg/volume/aws_ebs/attacher.go
View file @
ba63590e
...
...
@@ -24,13 +24,15 @@ import (
"time"
"github.com/golang/glog"
"k8s.io/kubernetes/pkg/cloudprovider/providers/aws"
"k8s.io/kubernetes/pkg/util/exec"
"k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/volume"
)
type
awsElasticBlockStoreAttacher
struct
{
host
volume
.
VolumeHost
host
volume
.
VolumeHost
awsVolumes
aws
.
Volumes
}
var
_
volume
.
Attacher
=
&
awsElasticBlockStoreAttacher
{}
...
...
@@ -38,7 +40,15 @@ var _ volume.Attacher = &awsElasticBlockStoreAttacher{}
var
_
volume
.
AttachableVolumePlugin
=
&
awsElasticBlockStorePlugin
{}
func
(
plugin
*
awsElasticBlockStorePlugin
)
NewAttacher
()
(
volume
.
Attacher
,
error
)
{
return
&
awsElasticBlockStoreAttacher
{
host
:
plugin
.
host
},
nil
awsCloud
,
err
:=
getCloudProvider
(
plugin
.
host
.
GetCloudProvider
())
if
err
!=
nil
{
return
nil
,
err
}
return
&
awsElasticBlockStoreAttacher
{
host
:
plugin
.
host
,
awsVolumes
:
awsCloud
,
},
nil
}
func
(
attacher
*
awsElasticBlockStoreAttacher
)
Attach
(
spec
*
volume
.
Spec
,
hostName
string
)
(
string
,
error
)
{
...
...
@@ -49,14 +59,9 @@ func (attacher *awsElasticBlockStoreAttacher) Attach(spec *volume.Spec, hostName
volumeID
:=
volumeSource
.
VolumeID
awsCloud
,
err
:=
getCloudProvider
(
attacher
.
host
.
GetCloudProvider
())
if
err
!=
nil
{
return
""
,
err
}
// awsCloud.AttachDisk checks if disk is already attached to node and
// succeeds in that case, so no need to do that separately.
devicePath
,
err
:=
a
wsCloud
.
AttachDisk
(
volumeID
,
hostName
,
readOnly
)
devicePath
,
err
:=
a
ttacher
.
awsVolumes
.
AttachDisk
(
volumeID
,
hostName
,
readOnly
)
if
err
!=
nil
{
glog
.
Errorf
(
"Error attaching volume %q: %+v"
,
volumeID
,
err
)
return
""
,
err
...
...
@@ -156,23 +161,28 @@ func (attacher *awsElasticBlockStoreAttacher) MountDevice(spec *volume.Spec, dev
}
type
awsElasticBlockStoreDetacher
struct
{
host
volume
.
VolumeHost
mounter
mount
.
Interface
awsVolumes
aws
.
Volumes
}
var
_
volume
.
Detacher
=
&
awsElasticBlockStoreDetacher
{}
func
(
plugin
*
awsElasticBlockStorePlugin
)
NewDetacher
()
(
volume
.
Detacher
,
error
)
{
return
&
awsElasticBlockStoreDetacher
{
host
:
plugin
.
host
},
nil
awsCloud
,
err
:=
getCloudProvider
(
plugin
.
host
.
GetCloudProvider
())
if
err
!=
nil
{
return
nil
,
err
}
return
&
awsElasticBlockStoreDetacher
{
mounter
:
plugin
.
host
.
GetMounter
(),
awsVolumes
:
awsCloud
,
},
nil
}
func
(
detacher
*
awsElasticBlockStoreDetacher
)
Detach
(
deviceMountPath
string
,
hostName
string
)
error
{
volumeID
:=
path
.
Base
(
deviceMountPath
)
awsCloud
,
err
:=
getCloudProvider
(
detacher
.
host
.
GetCloudProvider
())
if
err
!=
nil
{
return
err
}
attached
,
err
:=
awsCloud
.
DiskIsAttached
(
volumeID
,
hostName
)
attached
,
err
:=
detacher
.
awsVolumes
.
DiskIsAttached
(
volumeID
,
hostName
)
if
err
!=
nil
{
// Log error and continue with detach
glog
.
Errorf
(
...
...
@@ -186,7 +196,7 @@ func (detacher *awsElasticBlockStoreDetacher) Detach(deviceMountPath string, hos
return
nil
}
if
_
,
err
=
awsCloud
.
DetachDisk
(
volumeID
,
hostName
);
err
!=
nil
{
if
_
,
err
=
detacher
.
awsVolumes
.
DetachDisk
(
volumeID
,
hostName
);
err
!=
nil
{
glog
.
Errorf
(
"Error detaching volumeID %q: %v"
,
volumeID
,
err
)
return
err
}
...
...
@@ -215,9 +225,8 @@ func (detacher *awsElasticBlockStoreDetacher) WaitForDetach(devicePath string, t
}
func
(
detacher
*
awsElasticBlockStoreDetacher
)
UnmountDevice
(
deviceMountPath
string
)
error
{
mounter
:=
detacher
.
host
.
GetMounter
()
volume
:=
path
.
Base
(
deviceMountPath
)
if
err
:=
unmountPDAndRemoveGlobalPath
(
deviceMountPath
,
mounter
);
err
!=
nil
{
if
err
:=
unmountPDAndRemoveGlobalPath
(
deviceMountPath
,
detacher
.
mounter
);
err
!=
nil
{
glog
.
Errorf
(
"Error unmounting %q: %v"
,
volume
,
err
)
}
...
...
pkg/volume/aws_ebs/attacher_test.go
0 → 100644
View file @
ba63590e
This diff is collapsed.
Click to expand it.
pkg/volume/gce_pd/attacher_test.go
View file @
ba63590e
...
...
@@ -31,7 +31,7 @@ import (
func
TestGetDeviceName_Volume
(
t
*
testing
.
T
)
{
plugin
:=
newPlugin
()
name
:=
"my-pd-volume"
spec
:=
createVSpec
(
name
,
false
)
spec
:=
createV
ol
Spec
(
name
,
false
)
deviceName
,
err
:=
plugin
.
GetVolumeName
(
spec
)
if
err
!=
nil
{
...
...
@@ -75,7 +75,7 @@ func TestAttachDetach(t *testing.T) {
diskName
:=
"disk"
instanceID
:=
"instance"
readOnly
:=
false
spec
:=
createVSpec
(
diskName
,
readOnly
)
spec
:=
createV
ol
Spec
(
diskName
,
readOnly
)
attachError
:=
errors
.
New
(
"Fake attach error"
)
detachError
:=
errors
.
New
(
"Fake detach error"
)
diskCheckError
:=
errors
.
New
(
"Fake DiskIsAttached error"
)
...
...
@@ -222,7 +222,7 @@ func newDetacher(testcase *testcase) *gcePersistentDiskDetacher {
}
}
func
createVSpec
(
name
string
,
readOnly
bool
)
*
volume
.
Spec
{
func
createV
ol
Spec
(
name
string
,
readOnly
bool
)
*
volume
.
Spec
{
return
&
volume
.
Spec
{
Volume
:
&
api
.
Volume
{
VolumeSource
:
api
.
VolumeSource
{
...
...
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