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
5cd5ae8d
Commit
5cd5ae8d
authored
Jun 08, 2016
by
Jan Safranek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add GCE attacher unit tests.
parent
2b342c1e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
19 deletions
+34
-19
gce.go
pkg/cloudprovider/providers/gce/gce.go
+3
-0
attacher.go
pkg/volume/gce_pd/attacher.go
+25
-18
attacher_test.go
pkg/volume/gce_pd/attacher_test.go
+0
-0
gce_util.go
pkg/volume/gce_pd/gce_util.go
+6
-1
No files found.
pkg/cloudprovider/providers/gce/gce.go
View file @
5cd5ae8d
...
@@ -110,6 +110,9 @@ type Disks interface {
...
@@ -110,6 +110,9 @@ type Disks interface {
// is used when instanceID is empty string.
// is used when instanceID is empty string.
DetachDisk
(
devicePath
,
instanceID
string
)
error
DetachDisk
(
devicePath
,
instanceID
string
)
error
// DiskIsAttached checks if a disk is attached to the given node.
DiskIsAttached
(
diskName
,
instanceID
string
)
(
bool
,
error
)
// CreateDisk creates a new PD with given properties. Tags are serialized
// CreateDisk creates a new PD with given properties. Tags are serialized
// as JSON into Description field.
// as JSON into Description field.
CreateDisk
(
name
string
,
zone
string
,
sizeGb
int64
,
tags
map
[
string
]
string
)
error
CreateDisk
(
name
string
,
zone
string
,
sizeGb
int64
,
tags
map
[
string
]
string
)
error
...
...
pkg/volume/gce_pd/attacher.go
View file @
5cd5ae8d
...
@@ -25,6 +25,7 @@ import (
...
@@ -25,6 +25,7 @@ import (
"time"
"time"
"github.com/golang/glog"
"github.com/golang/glog"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce"
"k8s.io/kubernetes/pkg/util/exec"
"k8s.io/kubernetes/pkg/util/exec"
"k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/util/sets"
"k8s.io/kubernetes/pkg/util/sets"
...
@@ -32,7 +33,8 @@ import (
...
@@ -32,7 +33,8 @@ import (
)
)
type
gcePersistentDiskAttacher
struct
{
type
gcePersistentDiskAttacher
struct
{
host
volume
.
VolumeHost
host
volume
.
VolumeHost
gceDisks
gce
.
Disks
}
}
var
_
volume
.
Attacher
=
&
gcePersistentDiskAttacher
{}
var
_
volume
.
Attacher
=
&
gcePersistentDiskAttacher
{}
...
@@ -40,7 +42,15 @@ var _ volume.Attacher = &gcePersistentDiskAttacher{}
...
@@ -40,7 +42,15 @@ var _ volume.Attacher = &gcePersistentDiskAttacher{}
var
_
volume
.
AttachableVolumePlugin
=
&
gcePersistentDiskPlugin
{}
var
_
volume
.
AttachableVolumePlugin
=
&
gcePersistentDiskPlugin
{}
func
(
plugin
*
gcePersistentDiskPlugin
)
NewAttacher
()
(
volume
.
Attacher
,
error
)
{
func
(
plugin
*
gcePersistentDiskPlugin
)
NewAttacher
()
(
volume
.
Attacher
,
error
)
{
return
&
gcePersistentDiskAttacher
{
host
:
plugin
.
host
},
nil
gceCloud
,
err
:=
getCloudProvider
(
plugin
.
host
.
GetCloudProvider
())
if
err
!=
nil
{
return
nil
,
err
}
return
&
gcePersistentDiskAttacher
{
host
:
plugin
.
host
,
gceDisks
:
gceCloud
,
},
nil
}
}
func
(
plugin
*
gcePersistentDiskPlugin
)
GetDeviceName
(
spec
*
volume
.
Spec
)
(
string
,
error
)
{
func
(
plugin
*
gcePersistentDiskPlugin
)
GetDeviceName
(
spec
*
volume
.
Spec
)
(
string
,
error
)
{
...
@@ -63,12 +73,7 @@ func (attacher *gcePersistentDiskAttacher) Attach(spec *volume.Spec, hostName st
...
@@ -63,12 +73,7 @@ func (attacher *gcePersistentDiskAttacher) Attach(spec *volume.Spec, hostName st
volumeSource
,
readOnly
:=
getVolumeSource
(
spec
)
volumeSource
,
readOnly
:=
getVolumeSource
(
spec
)
pdName
:=
volumeSource
.
PDName
pdName
:=
volumeSource
.
PDName
gceCloud
,
err
:=
getCloudProvider
(
attacher
.
host
.
GetCloudProvider
())
attached
,
err
:=
attacher
.
gceDisks
.
DiskIsAttached
(
pdName
,
hostName
)
if
err
!=
nil
{
return
err
}
attached
,
err
:=
gceCloud
.
DiskIsAttached
(
pdName
,
hostName
)
if
err
!=
nil
{
if
err
!=
nil
{
// Log error and continue with attach
// Log error and continue with attach
glog
.
Errorf
(
glog
.
Errorf
(
...
@@ -82,7 +87,7 @@ func (attacher *gcePersistentDiskAttacher) Attach(spec *volume.Spec, hostName st
...
@@ -82,7 +87,7 @@ func (attacher *gcePersistentDiskAttacher) Attach(spec *volume.Spec, hostName st
return
nil
return
nil
}
}
if
err
=
gceCloud
.
AttachDisk
(
pdName
,
hostName
,
readOnly
);
err
!=
nil
{
if
err
=
attacher
.
gceDisks
.
AttachDisk
(
pdName
,
hostName
,
readOnly
);
err
!=
nil
{
glog
.
Errorf
(
"Error attaching PD %q to node %q: %+v"
,
pdName
,
hostName
,
err
)
glog
.
Errorf
(
"Error attaching PD %q to node %q: %+v"
,
pdName
,
hostName
,
err
)
return
err
return
err
}
}
...
@@ -166,13 +171,20 @@ func (attacher *gcePersistentDiskAttacher) MountDevice(spec *volume.Spec, device
...
@@ -166,13 +171,20 @@ func (attacher *gcePersistentDiskAttacher) MountDevice(spec *volume.Spec, device
}
}
type
gcePersistentDiskDetacher
struct
{
type
gcePersistentDiskDetacher
struct
{
host
volume
.
VolumeHost
gceDisks
gce
.
Disks
}
}
var
_
volume
.
Detacher
=
&
gcePersistentDiskDetacher
{}
var
_
volume
.
Detacher
=
&
gcePersistentDiskDetacher
{}
func
(
plugin
*
gcePersistentDiskPlugin
)
NewDetacher
()
(
volume
.
Detacher
,
error
)
{
func
(
plugin
*
gcePersistentDiskPlugin
)
NewDetacher
()
(
volume
.
Detacher
,
error
)
{
return
&
gcePersistentDiskDetacher
{
host
:
plugin
.
host
},
nil
gceCloud
,
err
:=
getCloudProvider
(
plugin
.
host
.
GetCloudProvider
())
if
err
!=
nil
{
return
nil
,
err
}
return
&
gcePersistentDiskDetacher
{
gceDisks
:
gceCloud
,
},
nil
}
}
// Detach checks with the GCE cloud provider if the specified volume is already
// Detach checks with the GCE cloud provider if the specified volume is already
...
@@ -185,12 +197,7 @@ func (plugin *gcePersistentDiskPlugin) NewDetacher() (volume.Detacher, error) {
...
@@ -185,12 +197,7 @@ func (plugin *gcePersistentDiskPlugin) NewDetacher() (volume.Detacher, error) {
func
(
detacher
*
gcePersistentDiskDetacher
)
Detach
(
deviceMountPath
string
,
hostName
string
)
error
{
func
(
detacher
*
gcePersistentDiskDetacher
)
Detach
(
deviceMountPath
string
,
hostName
string
)
error
{
pdName
:=
path
.
Base
(
deviceMountPath
)
pdName
:=
path
.
Base
(
deviceMountPath
)
gceCloud
,
err
:=
getCloudProvider
(
detacher
.
host
.
GetCloudProvider
())
attached
,
err
:=
detacher
.
gceDisks
.
DiskIsAttached
(
pdName
,
hostName
)
if
err
!=
nil
{
return
err
}
attached
,
err
:=
gceCloud
.
DiskIsAttached
(
pdName
,
hostName
)
if
err
!=
nil
{
if
err
!=
nil
{
// Log error and continue with detach
// Log error and continue with detach
glog
.
Errorf
(
glog
.
Errorf
(
...
@@ -204,7 +211,7 @@ func (detacher *gcePersistentDiskDetacher) Detach(deviceMountPath string, hostNa
...
@@ -204,7 +211,7 @@ func (detacher *gcePersistentDiskDetacher) Detach(deviceMountPath string, hostNa
return
nil
return
nil
}
}
if
err
=
gceCloud
.
DetachDisk
(
pdName
,
hostName
);
err
!=
nil
{
if
err
=
detacher
.
gceDisks
.
DetachDisk
(
pdName
,
hostName
);
err
!=
nil
{
glog
.
Errorf
(
"Error detaching PD %q from node %q: %v"
,
pdName
,
hostName
,
err
)
glog
.
Errorf
(
"Error detaching PD %q from node %q: %v"
,
pdName
,
hostName
,
err
)
return
err
return
err
}
}
...
...
pkg/volume/gce_pd/attacher_test.go
0 → 100644
View file @
5cd5ae8d
This diff is collapsed.
Click to expand it.
pkg/volume/gce_pd/gce_util.go
View file @
5cd5ae8d
...
@@ -43,7 +43,12 @@ const (
...
@@ -43,7 +43,12 @@ const (
maxChecks
=
60
maxChecks
=
60
maxRetries
=
10
maxRetries
=
10
checkSleepDuration
=
time
.
Second
checkSleepDuration
=
time
.
Second
errorSleepDuration
=
5
*
time
.
Second
)
// These variables are modified only in unit tests and should be constant
// otherwise.
var
(
errorSleepDuration
time
.
Duration
=
5
*
time
.
Second
)
)
type
GCEDiskUtil
struct
{}
type
GCEDiskUtil
struct
{}
...
...
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