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
498dc418
Commit
498dc418
authored
Apr 13, 2016
by
Daniel Smith
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #23122 from screeley44/volmount_errors
Return more useful error information when a persistent volume fails to mount
parents
4983a8fd
36970dee
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
32 deletions
+31
-32
volumes.go
pkg/kubelet/volumes.go
+31
-32
No files found.
pkg/kubelet/volumes.go
View file @
498dc418
...
@@ -34,8 +34,6 @@ import (
...
@@ -34,8 +34,6 @@ import (
"k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume"
)
)
var
errUnsupportedVolumeType
=
fmt
.
Errorf
(
"unsupported volume type"
)
// This just exports required functions from kubelet proper, for use by volume
// This just exports required functions from kubelet proper, for use by volume
// plugins.
// plugins.
type
volumeHost
struct
{
type
volumeHost
struct
{
...
@@ -58,6 +56,9 @@ func (vh *volumeHost) GetKubeClient() clientset.Interface {
...
@@ -58,6 +56,9 @@ func (vh *volumeHost) GetKubeClient() clientset.Interface {
return
vh
.
kubelet
.
kubeClient
return
vh
.
kubelet
.
kubeClient
}
}
// NewWrapperMounter attempts to create a volume mounter
// from a volume Spec, pod and volume options.
// Returns a new volume Mounter or an error.
func
(
vh
*
volumeHost
)
NewWrapperMounter
(
volName
string
,
spec
volume
.
Spec
,
pod
*
api
.
Pod
,
opts
volume
.
VolumeOptions
)
(
volume
.
Mounter
,
error
)
{
func
(
vh
*
volumeHost
)
NewWrapperMounter
(
volName
string
,
spec
volume
.
Spec
,
pod
*
api
.
Pod
,
opts
volume
.
VolumeOptions
)
(
volume
.
Mounter
,
error
)
{
// The name of wrapper volume is set to "wrapped_{wrapped_volume_name}"
// The name of wrapper volume is set to "wrapped_{wrapped_volume_name}"
wrapperVolumeName
:=
"wrapped_"
+
volName
wrapperVolumeName
:=
"wrapped_"
+
volName
...
@@ -65,13 +66,12 @@ func (vh *volumeHost) NewWrapperMounter(volName string, spec volume.Spec, pod *a
...
@@ -65,13 +66,12 @@ func (vh *volumeHost) NewWrapperMounter(volName string, spec volume.Spec, pod *a
spec
.
Volume
.
Name
=
wrapperVolumeName
spec
.
Volume
.
Name
=
wrapperVolumeName
}
}
b
,
err
:=
vh
.
kubelet
.
newVolumeMounterFromPlugins
(
&
spec
,
pod
,
opts
)
return
vh
.
kubelet
.
newVolumeMounterFromPlugins
(
&
spec
,
pod
,
opts
)
if
err
==
nil
&&
b
==
nil
{
return
nil
,
errUnsupportedVolumeType
}
return
b
,
nil
}
}
// NewWrapperUnmounter attempts to create a volume unmounter
// from a volume name and pod uid.
// Returns a new volume Unmounter or an error.
func
(
vh
*
volumeHost
)
NewWrapperUnmounter
(
volName
string
,
spec
volume
.
Spec
,
podUID
types
.
UID
)
(
volume
.
Unmounter
,
error
)
{
func
(
vh
*
volumeHost
)
NewWrapperUnmounter
(
volName
string
,
spec
volume
.
Spec
,
podUID
types
.
UID
)
(
volume
.
Unmounter
,
error
)
{
// The name of wrapper volume is set to "wrapped_{wrapped_volume_name}"
// The name of wrapper volume is set to "wrapped_{wrapped_volume_name}"
wrapperVolumeName
:=
"wrapped_"
+
volName
wrapperVolumeName
:=
"wrapped_"
+
volName
...
@@ -83,15 +83,8 @@ func (vh *volumeHost) NewWrapperUnmounter(volName string, spec volume.Spec, podU
...
@@ -83,15 +83,8 @@ func (vh *volumeHost) NewWrapperUnmounter(volName string, spec volume.Spec, podU
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
if
plugin
==
nil
{
// Not found but not an error
return
plugin
.
NewUnmounter
(
spec
.
Name
(),
podUID
)
return
nil
,
nil
}
c
,
err
:=
plugin
.
NewUnmounter
(
spec
.
Name
(),
podUID
)
if
err
==
nil
&&
c
==
nil
{
return
nil
,
errUnsupportedVolumeType
}
return
c
,
nil
}
}
func
(
vh
*
volumeHost
)
GetCloudProvider
()
cloudprovider
.
Interface
{
func
(
vh
*
volumeHost
)
GetCloudProvider
()
cloudprovider
.
Interface
{
...
@@ -141,9 +134,6 @@ func (kl *Kubelet) mountExternalVolumes(pod *api.Pod) (kubecontainer.VolumeMap,
...
@@ -141,9 +134,6 @@ func (kl *Kubelet) mountExternalVolumes(pod *api.Pod) (kubecontainer.VolumeMap,
glog
.
Errorf
(
"Could not create volume mounter for pod %s: %v"
,
pod
.
UID
,
err
)
glog
.
Errorf
(
"Could not create volume mounter for pod %s: %v"
,
pod
.
UID
,
err
)
return
nil
,
err
return
nil
,
err
}
}
if
mounter
==
nil
{
return
nil
,
errUnsupportedVolumeType
}
// some volumes require attachment before mounter's setup.
// some volumes require attachment before mounter's setup.
// The plugin can be nil, but non-nil errors are legitimate errors.
// The plugin can be nil, but non-nil errors are legitimate errors.
...
@@ -254,10 +244,6 @@ func (kl *Kubelet) getPodVolumesFromDisk() map[string]cleanerTuple {
...
@@ -254,10 +244,6 @@ func (kl *Kubelet) getPodVolumesFromDisk() map[string]cleanerTuple {
glog
.
Errorf
(
"Could not create volume unmounter for %s: %v"
,
volume
.
Name
,
err
)
glog
.
Errorf
(
"Could not create volume unmounter for %s: %v"
,
volume
.
Name
,
err
)
continue
continue
}
}
if
unmounter
==
nil
{
glog
.
Errorf
(
"Could not create volume unmounter for %s: %v"
,
volume
.
Name
,
errUnsupportedVolumeType
)
continue
}
tuple
:=
cleanerTuple
{
Unmounter
:
unmounter
}
tuple
:=
cleanerTuple
{
Unmounter
:
unmounter
}
detacher
,
err
:=
kl
.
newVolumeDetacherFromPlugins
(
volume
.
Kind
,
volume
.
Name
,
podUID
)
detacher
,
err
:=
kl
.
newVolumeDetacherFromPlugins
(
volume
.
Kind
,
volume
.
Name
,
podUID
)
...
@@ -275,23 +261,29 @@ func (kl *Kubelet) getPodVolumesFromDisk() map[string]cleanerTuple {
...
@@ -275,23 +261,29 @@ func (kl *Kubelet) getPodVolumesFromDisk() map[string]cleanerTuple {
return
currentVolumes
return
currentVolumes
}
}
// newVolumeMounterFromPlugins attempts to find a plugin by volume spec, pod
// and volume options and then creates a Mounter.
// Returns a valid Unmounter or an error.
func
(
kl
*
Kubelet
)
newVolumeMounterFromPlugins
(
spec
*
volume
.
Spec
,
pod
*
api
.
Pod
,
opts
volume
.
VolumeOptions
)
(
volume
.
Mounter
,
error
)
{
func
(
kl
*
Kubelet
)
newVolumeMounterFromPlugins
(
spec
*
volume
.
Spec
,
pod
*
api
.
Pod
,
opts
volume
.
VolumeOptions
)
(
volume
.
Mounter
,
error
)
{
plugin
,
err
:=
kl
.
volumePluginMgr
.
FindPluginBySpec
(
spec
)
plugin
,
err
:=
kl
.
volumePluginMgr
.
FindPluginBySpec
(
spec
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"can't use volume plugins for %s: %v"
,
spec
.
Name
(),
err
)
return
nil
,
fmt
.
Errorf
(
"can't use volume plugins for %s: %v"
,
spec
.
Name
(),
err
)
}
}
if
plugin
==
nil
{
// Not found but not an error
return
nil
,
nil
}
physicalMounter
,
err
:=
plugin
.
NewMounter
(
spec
,
pod
,
opts
)
physicalMounter
,
err
:=
plugin
.
NewMounter
(
spec
,
pod
,
opts
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to instantiate
volume physicalMounter for %s: %v"
,
spec
.
Name
(),
err
)
return
nil
,
fmt
.
Errorf
(
"failed to instantiate
mounter for volume: %s using plugin: %s with a root cause: %v"
,
spec
.
Name
(),
plugin
.
Name
(),
err
)
}
}
glog
.
V
(
10
)
.
Infof
(
"Used volume plugin %q to mount %s"
,
plugin
.
Name
(),
spec
.
Name
())
glog
.
V
(
10
)
.
Infof
(
"Used volume plugin %q to mount %s"
,
plugin
.
Name
(),
spec
.
Name
())
return
physicalMounter
,
nil
return
physicalMounter
,
nil
}
}
// newVolumeAttacherFromPlugins attempts to find a plugin from a volume spec
// and then create an Attacher.
// Returns:
// - an attacher if one exists
// - an error if no plugin was found for the volume
// or the attacher failed to instantiate
// - nil if there is no appropriate attacher for this volume
func
(
kl
*
Kubelet
)
newVolumeAttacherFromPlugins
(
spec
*
volume
.
Spec
,
pod
*
api
.
Pod
,
opts
volume
.
VolumeOptions
)
(
volume
.
Attacher
,
error
)
{
func
(
kl
*
Kubelet
)
newVolumeAttacherFromPlugins
(
spec
*
volume
.
Spec
,
pod
*
api
.
Pod
,
opts
volume
.
VolumeOptions
)
(
volume
.
Attacher
,
error
)
{
plugin
,
err
:=
kl
.
volumePluginMgr
.
FindAttachablePluginBySpec
(
spec
)
plugin
,
err
:=
kl
.
volumePluginMgr
.
FindAttachablePluginBySpec
(
spec
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -310,6 +302,9 @@ func (kl *Kubelet) newVolumeAttacherFromPlugins(spec *volume.Spec, pod *api.Pod,
...
@@ -310,6 +302,9 @@ func (kl *Kubelet) newVolumeAttacherFromPlugins(spec *volume.Spec, pod *api.Pod,
return
attacher
,
nil
return
attacher
,
nil
}
}
// newVolumeUnmounterFromPlugins attempts to find a plugin by name and then
// create an Unmounter.
// Returns a valid Unmounter or an error.
func
(
kl
*
Kubelet
)
newVolumeUnmounterFromPlugins
(
kind
string
,
name
string
,
podUID
types
.
UID
)
(
volume
.
Unmounter
,
error
)
{
func
(
kl
*
Kubelet
)
newVolumeUnmounterFromPlugins
(
kind
string
,
name
string
,
podUID
types
.
UID
)
(
volume
.
Unmounter
,
error
)
{
plugName
:=
strings
.
UnescapeQualifiedNameForDisk
(
kind
)
plugName
:=
strings
.
UnescapeQualifiedNameForDisk
(
kind
)
plugin
,
err
:=
kl
.
volumePluginMgr
.
FindPluginByName
(
plugName
)
plugin
,
err
:=
kl
.
volumePluginMgr
.
FindPluginByName
(
plugName
)
...
@@ -317,10 +312,7 @@ func (kl *Kubelet) newVolumeUnmounterFromPlugins(kind string, name string, podUI
...
@@ -317,10 +312,7 @@ func (kl *Kubelet) newVolumeUnmounterFromPlugins(kind string, name string, podUI
// TODO: Maybe we should launch a cleanup of this dir?
// TODO: Maybe we should launch a cleanup of this dir?
return
nil
,
fmt
.
Errorf
(
"can't use volume plugins for %s/%s: %v"
,
podUID
,
kind
,
err
)
return
nil
,
fmt
.
Errorf
(
"can't use volume plugins for %s/%s: %v"
,
podUID
,
kind
,
err
)
}
}
if
plugin
==
nil
{
// Not found but not an error.
return
nil
,
nil
}
unmounter
,
err
:=
plugin
.
NewUnmounter
(
name
,
podUID
)
unmounter
,
err
:=
plugin
.
NewUnmounter
(
name
,
podUID
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to instantiate volume plugin for %s/%s: %v"
,
podUID
,
kind
,
err
)
return
nil
,
fmt
.
Errorf
(
"failed to instantiate volume plugin for %s/%s: %v"
,
podUID
,
kind
,
err
)
...
@@ -329,6 +321,13 @@ func (kl *Kubelet) newVolumeUnmounterFromPlugins(kind string, name string, podUI
...
@@ -329,6 +321,13 @@ func (kl *Kubelet) newVolumeUnmounterFromPlugins(kind string, name string, podUI
return
unmounter
,
nil
return
unmounter
,
nil
}
}
// newVolumeDetacherFromPlugins attempts to find a plugin by a name and then
// create a Detacher.
// Returns:
// - a detacher if one exists
// - an error if no plugin was found for the volume
// or the detacher failed to instantiate
// - nil if there is no appropriate detacher for this volume
func
(
kl
*
Kubelet
)
newVolumeDetacherFromPlugins
(
kind
string
,
name
string
,
podUID
types
.
UID
)
(
volume
.
Detacher
,
error
)
{
func
(
kl
*
Kubelet
)
newVolumeDetacherFromPlugins
(
kind
string
,
name
string
,
podUID
types
.
UID
)
(
volume
.
Detacher
,
error
)
{
plugName
:=
strings
.
UnescapeQualifiedNameForDisk
(
kind
)
plugName
:=
strings
.
UnescapeQualifiedNameForDisk
(
kind
)
plugin
,
err
:=
kl
.
volumePluginMgr
.
FindAttachablePluginByName
(
plugName
)
plugin
,
err
:=
kl
.
volumePluginMgr
.
FindAttachablePluginByName
(
plugName
)
...
...
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