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
529cd711
Commit
529cd711
authored
Mar 03, 2019
by
Hemant Kumar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move resize function parameters to a new ResizeOptions type
This enables us to pass CSI volume phase
parent
63eb25eb
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
155 additions
and
63 deletions
+155
-63
aws_ebs.go
pkg/volume/awsebs/aws_ebs.go
+2
-2
azure_dd.go
pkg/volume/azure_dd/azure_dd.go
+2
-2
cinder.go
pkg/volume/cinder/cinder.go
+2
-2
expander.go
pkg/volume/csi/expander.go
+36
-6
expander-defaults.go
pkg/volume/flexvolume/expander-defaults.go
+3
-3
expander.go
pkg/volume/flexvolume/expander.go
+9
-9
gce_pd.go
pkg/volume/gcepd/gce_pd.go
+2
-2
plugins.go
pkg/volume/plugins.go
+26
-2
rbd.go
pkg/volume/rbd/rbd.go
+2
-2
testing.go
pkg/volume/testing/testing.go
+1
-1
operation_generator.go
pkg/volume/util/operationexecutor/operation_generator.go
+70
-32
No files found.
pkg/volume/awsebs/aws_ebs.go
View file @
529cd711
...
@@ -317,8 +317,8 @@ func (plugin *awsElasticBlockStorePlugin) ExpandVolumeDevice(
...
@@ -317,8 +317,8 @@ func (plugin *awsElasticBlockStorePlugin) ExpandVolumeDevice(
return
awsVolume
.
ResizeDisk
(
volumeID
,
oldSize
,
newSize
)
return
awsVolume
.
ResizeDisk
(
volumeID
,
oldSize
,
newSize
)
}
}
func
(
plugin
*
awsElasticBlockStorePlugin
)
NodeExpand
(
spec
*
volume
.
Spec
,
devicePath
,
deviceMountPath
string
,
_
,
_
resource
.
Quantity
)
(
bool
,
error
)
{
func
(
plugin
*
awsElasticBlockStorePlugin
)
NodeExpand
(
resizeOptions
volume
.
NodeResizeOptions
)
(
bool
,
error
)
{
_
,
err
:=
util
.
GenericResizeFS
(
plugin
.
host
,
plugin
.
GetPluginName
(),
devicePath
,
d
eviceMountPath
)
_
,
err
:=
util
.
GenericResizeFS
(
plugin
.
host
,
plugin
.
GetPluginName
(),
resizeOptions
.
DevicePath
,
resizeOptions
.
D
eviceMountPath
)
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
err
return
false
,
err
}
}
...
...
pkg/volume/azure_dd/azure_dd.go
View file @
529cd711
...
@@ -312,8 +312,8 @@ func (plugin *azureDataDiskPlugin) ExpandVolumeDevice(
...
@@ -312,8 +312,8 @@ func (plugin *azureDataDiskPlugin) ExpandVolumeDevice(
return
diskController
.
ResizeDisk
(
spec
.
PersistentVolume
.
Spec
.
AzureDisk
.
DataDiskURI
,
oldSize
,
newSize
)
return
diskController
.
ResizeDisk
(
spec
.
PersistentVolume
.
Spec
.
AzureDisk
.
DataDiskURI
,
oldSize
,
newSize
)
}
}
func
(
plugin
*
azureDataDiskPlugin
)
NodeExpand
(
spec
*
volume
.
Spec
,
devicePath
,
deviceMountPath
string
,
_
,
_
resource
.
Quantity
)
(
bool
,
error
)
{
func
(
plugin
*
azureDataDiskPlugin
)
NodeExpand
(
resizeOptions
volume
.
NodeResizeOptions
)
(
bool
,
error
)
{
_
,
err
:=
util
.
GenericResizeFS
(
plugin
.
host
,
plugin
.
GetPluginName
(),
devicePath
,
d
eviceMountPath
)
_
,
err
:=
util
.
GenericResizeFS
(
plugin
.
host
,
plugin
.
GetPluginName
(),
resizeOptions
.
DevicePath
,
resizeOptions
.
D
eviceMountPath
)
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
err
return
false
,
err
}
}
...
...
pkg/volume/cinder/cinder.go
View file @
529cd711
...
@@ -304,8 +304,8 @@ func (plugin *cinderPlugin) ExpandVolumeDevice(spec *volume.Spec, newSize resour
...
@@ -304,8 +304,8 @@ func (plugin *cinderPlugin) ExpandVolumeDevice(spec *volume.Spec, newSize resour
return
expandedSize
,
nil
return
expandedSize
,
nil
}
}
func
(
plugin
*
cinderPlugin
)
NodeExpand
(
spec
*
volume
.
Spec
,
devicePath
,
deviceMountPath
string
,
_
,
_
resource
.
Quantity
)
(
bool
,
error
)
{
func
(
plugin
*
cinderPlugin
)
NodeExpand
(
resizeOptions
volume
.
NodeResizeOptions
)
(
bool
,
error
)
{
_
,
err
:=
util
.
GenericResizeFS
(
plugin
.
host
,
plugin
.
GetPluginName
(),
devicePath
,
d
eviceMountPath
)
_
,
err
:=
util
.
GenericResizeFS
(
plugin
.
host
,
plugin
.
GetPluginName
(),
resizeOptions
.
DevicePath
,
resizeOptions
.
D
eviceMountPath
)
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
err
return
false
,
err
}
}
...
...
pkg/volume/csi/expander.go
View file @
529cd711
...
@@ -21,21 +21,28 @@ import (
...
@@ -21,21 +21,28 @@ import (
"errors"
"errors"
"fmt"
"fmt"
"k8s.io/apimachinery/pkg/api/resourc
e"
utilfeature
"k8s.io/apiserver/pkg/util/featur
e"
"k8s.io/klog"
"k8s.io/klog"
"k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume"
)
)
var
_
volume
.
NodeExpandableVolumePlugin
=
&
csiPlugin
{}
func
(
c
*
csiPlugin
)
RequiresFSResize
()
bool
{
func
(
c
*
csiPlugin
)
RequiresFSResize
()
bool
{
// We could check plugin's node capability but we instead are going to rely on
// We could check plugin's node capability but we instead are going to rely on
// NodeExpand to do the right thing and return early if plugin does not have
// NodeExpand to do the right thing and return early if plugin does not have
// node expansion capability.
// node expansion capability.
if
!
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
ExpandCSIVolumes
)
{
klog
.
V
(
4
)
.
Infof
(
"Resizing is not enabled for this CSI volume"
)
return
false
}
return
true
return
true
}
}
func
(
c
*
csiPlugin
)
NodeExpand
(
spec
*
volume
.
Spec
,
devicePath
,
deviceMountPath
string
,
newSize
,
oldSize
resource
.
Quantity
)
(
bool
,
error
)
{
func
(
c
*
csiPlugin
)
NodeExpand
(
resizeOptions
volume
.
NodeResizeOptions
)
(
bool
,
error
)
{
klog
.
V
(
4
)
.
Infof
(
log
(
"Expander.NodeExpand(%s)"
,
d
eviceMountPath
))
klog
.
V
(
4
)
.
Infof
(
log
(
"Expander.NodeExpand(%s)"
,
resizeOptions
.
D
eviceMountPath
))
pvSource
,
err
:=
getCSISourceFromSpec
(
s
pec
)
pvSource
,
err
:=
getCSISourceFromSpec
(
resizeOptions
.
VolumeS
pec
)
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
err
return
false
,
err
}
}
...
@@ -50,7 +57,7 @@ func (c *csiPlugin) NodeExpand(spec *volume.Spec, devicePath, deviceMountPath st
...
@@ -50,7 +57,7 @@ func (c *csiPlugin) NodeExpand(spec *volume.Spec, devicePath, deviceMountPath st
return
false
,
err
return
false
,
err
}
}
csiSource
,
err
:=
getCSISourceFromSpec
(
s
pec
)
csiSource
,
err
:=
getCSISourceFromSpec
(
resizeOptions
.
VolumeS
pec
)
if
err
!=
nil
{
if
err
!=
nil
{
klog
.
Error
(
log
(
"Expander.NodeExpand failed to get CSI persistent source: %v"
,
err
))
klog
.
Error
(
log
(
"Expander.NodeExpand failed to get CSI persistent source: %v"
,
err
))
return
false
,
err
return
false
,
err
...
@@ -62,5 +69,28 @@ func (c *csiPlugin) NodeExpand(spec *volume.Spec, devicePath, deviceMountPath st
...
@@ -62,5 +69,28 @@ func (c *csiPlugin) NodeExpand(spec *volume.Spec, devicePath, deviceMountPath st
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
fmt
.
Errorf
(
"Expander.NodeExpand failed to check if node supports expansion : %v"
,
err
)
return
false
,
fmt
.
Errorf
(
"Expander.NodeExpand failed to check if node supports expansion : %v"
,
err
)
}
}
return
false
,
nil
if
!
nodeExpandSet
{
return
false
,
fmt
.
Errorf
(
"Expander.NodeExpand found CSI plugin %s to not support node expansion"
,
c
.
GetPluginName
())
}
// Check whether "STAGE_UNSTAGE_VOLUME" is set
stageUnstageSet
,
err
:=
csiClient
.
NodeSupportsStageUnstage
(
ctx
)
if
err
!=
nil
{
return
false
,
fmt
.
Errorf
(
"Expander.NodeExpand failed to check if plugins supports stage_unstage %v"
,
err
)
}
// if plugin does not support STAGE_UNSTAGE but CSI volume path is staged
// it must mean this was placeholder staging performed by k8s and not CSI staging
// in which case we should return from here so as volume can be node published
// before we can resize
if
!
stageUnstageSet
&&
resizeOptions
.
CSIVolumePhase
==
volume
.
CSIVolumeStaged
{
return
false
,
nil
}
_
,
err
=
csiClient
.
NodeExpandVolume
(
ctx
,
csiSource
.
VolumeHandle
,
resizeOptions
.
DeviceMountPath
,
resizeOptions
.
NewSize
)
if
err
!=
nil
{
return
false
,
fmt
.
Errorf
(
"Expander.NodeExpand failed to expand the volume : %v"
,
err
)
}
return
true
,
nil
}
}
pkg/volume/flexvolume/expander-defaults.go
View file @
529cd711
...
@@ -38,9 +38,9 @@ func (e *expanderDefaults) ExpandVolumeDevice(spec *volume.Spec, newSize resourc
...
@@ -38,9 +38,9 @@ func (e *expanderDefaults) ExpandVolumeDevice(spec *volume.Spec, newSize resourc
// the defaults for NodeExpand return a generic resize indicator that will trigger the operation executor to go ahead with
// the defaults for NodeExpand return a generic resize indicator that will trigger the operation executor to go ahead with
// generic filesystem resize
// generic filesystem resize
func
(
e
*
expanderDefaults
)
NodeExpand
(
spec
*
volume
.
Spec
,
devicePath
,
deviceMountPath
string
,
_
,
_
resource
.
Quantity
)
(
bool
,
error
)
{
func
(
e
*
expanderDefaults
)
NodeExpand
(
rsOpt
volume
.
NodeResizeOptions
)
(
bool
,
error
)
{
klog
.
Warning
(
logPrefix
(
e
.
plugin
),
"using default filesystem resize for volume "
,
spec
.
Name
(),
", at "
,
d
evicePath
)
klog
.
Warning
(
logPrefix
(
e
.
plugin
),
"using default filesystem resize for volume "
,
rsOpt
.
VolumeSpec
.
Name
(),
", at "
,
rsOpt
.
D
evicePath
)
_
,
err
:=
util
.
GenericResizeFS
(
e
.
plugin
.
host
,
e
.
plugin
.
GetPluginName
(),
devicePath
,
d
eviceMountPath
)
_
,
err
:=
util
.
GenericResizeFS
(
e
.
plugin
.
host
,
e
.
plugin
.
GetPluginName
(),
rsOpt
.
DevicePath
,
rsOpt
.
D
eviceMountPath
)
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
err
return
false
,
err
}
}
...
...
pkg/volume/flexvolume/expander.go
View file @
529cd711
...
@@ -43,26 +43,26 @@ func (plugin *flexVolumePlugin) ExpandVolumeDevice(spec *volume.Spec, newSize re
...
@@ -43,26 +43,26 @@ func (plugin *flexVolumePlugin) ExpandVolumeDevice(spec *volume.Spec, newSize re
return
newSize
,
err
return
newSize
,
err
}
}
func
(
plugin
*
flexVolumePlugin
)
NodeExpand
(
spec
*
volume
.
Spec
,
devicePath
,
deviceMountPath
string
,
newSize
,
oldSize
resource
.
Quantity
)
(
bool
,
error
)
{
func
(
plugin
*
flexVolumePlugin
)
NodeExpand
(
rsOpt
volume
.
NodeResizeOptions
)
(
bool
,
error
)
{
// This method is called after we spec.PersistentVolume.Spec.Capacity
// This method is called after we spec.PersistentVolume.Spec.Capacity
// has been updated to the new size. The underlying driver thus sees
// has been updated to the new size. The underlying driver thus sees
// the _new_ (requested) size and can find out the _current_ size from
// the _new_ (requested) size and can find out the _current_ size from
// its underlying storage implementation
// its underlying storage implementation
if
s
pec
.
PersistentVolume
==
nil
{
if
rsOpt
.
VolumeS
pec
.
PersistentVolume
==
nil
{
return
false
,
fmt
.
Errorf
(
"PersistentVolume not found for spec: %s"
,
s
pec
.
Name
())
return
false
,
fmt
.
Errorf
(
"PersistentVolume not found for spec: %s"
,
rsOpt
.
VolumeS
pec
.
Name
())
}
}
call
:=
plugin
.
NewDriverCall
(
expandFSCmd
)
call
:=
plugin
.
NewDriverCall
(
expandFSCmd
)
call
.
AppendSpec
(
s
pec
,
plugin
.
host
,
nil
)
call
.
AppendSpec
(
rsOpt
.
VolumeS
pec
,
plugin
.
host
,
nil
)
call
.
Append
(
d
evicePath
)
call
.
Append
(
rsOpt
.
D
evicePath
)
call
.
Append
(
d
eviceMountPath
)
call
.
Append
(
rsOpt
.
D
eviceMountPath
)
call
.
Append
(
strconv
.
FormatInt
(
n
ewSize
.
Value
(),
10
))
call
.
Append
(
strconv
.
FormatInt
(
rsOpt
.
N
ewSize
.
Value
(),
10
))
call
.
Append
(
strconv
.
FormatInt
(
o
ldSize
.
Value
(),
10
))
call
.
Append
(
strconv
.
FormatInt
(
rsOpt
.
O
ldSize
.
Value
(),
10
))
_
,
err
:=
call
.
Run
()
_
,
err
:=
call
.
Run
()
if
isCmdNotSupportedErr
(
err
)
{
if
isCmdNotSupportedErr
(
err
)
{
return
newExpanderDefaults
(
plugin
)
.
NodeExpand
(
spec
,
devicePath
,
deviceMountPath
,
newSize
,
oldSize
)
return
newExpanderDefaults
(
plugin
)
.
NodeExpand
(
rsOpt
)
}
}
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
err
return
false
,
err
...
...
pkg/volume/gcepd/gce_pd.go
View file @
529cd711
...
@@ -290,8 +290,8 @@ func (plugin *gcePersistentDiskPlugin) ExpandVolumeDevice(
...
@@ -290,8 +290,8 @@ func (plugin *gcePersistentDiskPlugin) ExpandVolumeDevice(
return
updatedQuantity
,
nil
return
updatedQuantity
,
nil
}
}
func
(
plugin
*
gcePersistentDiskPlugin
)
NodeExpand
(
spec
*
volume
.
Spec
,
devicePath
,
deviceMountPath
string
,
_
,
_
resource
.
Quantity
)
(
bool
,
error
)
{
func
(
plugin
*
gcePersistentDiskPlugin
)
NodeExpand
(
resizeOptions
volume
.
NodeResizeOptions
)
(
bool
,
error
)
{
_
,
err
:=
util
.
GenericResizeFS
(
plugin
.
host
,
plugin
.
GetPluginName
(),
devicePath
,
d
eviceMountPath
)
_
,
err
:=
util
.
GenericResizeFS
(
plugin
.
host
,
plugin
.
GetPluginName
(),
resizeOptions
.
DevicePath
,
resizeOptions
.
D
eviceMountPath
)
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
err
return
false
,
err
}
}
...
...
pkg/volume/plugins.go
View file @
529cd711
...
@@ -46,6 +46,9 @@ type ProbeEvent struct {
...
@@ -46,6 +46,9 @@ type ProbeEvent struct {
Op
ProbeOperation
// The operation to the plugin
Op
ProbeOperation
// The operation to the plugin
}
}
// CSIVolumePhaseType stores information about CSI volume path.
type
CSIVolumePhaseType
string
const
(
const
(
// Common parameter which can be specified in StorageClass to specify the desired FSType
// Common parameter which can be specified in StorageClass to specify the desired FSType
// Provisioners SHOULD implement support for this if they are block device based
// Provisioners SHOULD implement support for this if they are block device based
...
@@ -55,6 +58,8 @@ const (
...
@@ -55,6 +58,8 @@ const (
ProbeAddOrUpdate
ProbeOperation
=
1
<<
iota
ProbeAddOrUpdate
ProbeOperation
=
1
<<
iota
ProbeRemove
ProbeRemove
CSIVolumeStaged
CSIVolumePhaseType
=
"staged"
CSIVolumePublished
CSIVolumePhaseType
=
"published"
)
)
// VolumeOptions contains option information about a volume.
// VolumeOptions contains option information about a volume.
...
@@ -85,6 +90,26 @@ type VolumeOptions struct {
...
@@ -85,6 +90,26 @@ type VolumeOptions struct {
Parameters
map
[
string
]
string
Parameters
map
[
string
]
string
}
}
// NodeResizeOptions contain options to be passed for node expansion.
type
NodeResizeOptions
struct
{
VolumeSpec
*
Spec
// DevicePath - location of actual device on the node. In case of CSI
// this just could be volumeID
DevicePath
string
// DeviceMountPath location where device is mounted on the node. If volume type
// is attachable - this would be global mount path otherwise
// it would be location where volume was mounted for the pod
DeviceMountPath
string
NewSize
resource
.
Quantity
OldSize
resource
.
Quantity
// CSIVolumePhase contains volume phase on the node
CSIVolumePhase
CSIVolumePhaseType
}
type
DynamicPluginProber
interface
{
type
DynamicPluginProber
interface
{
Init
()
error
Init
()
error
...
@@ -232,8 +257,7 @@ type NodeExpandableVolumePlugin interface {
...
@@ -232,8 +257,7 @@ type NodeExpandableVolumePlugin interface {
VolumePlugin
VolumePlugin
RequiresFSResize
()
bool
RequiresFSResize
()
bool
// NodeExpand expands volume on given deviceMountPath and returns true if resize is successful.
// NodeExpand expands volume on given deviceMountPath and returns true if resize is successful.
// devicePath can be set to empty string if unavailable.
NodeExpand
(
resizeOptions
NodeResizeOptions
)
(
bool
,
error
)
NodeExpand
(
spec
*
Spec
,
devicePath
,
deviceMountPath
string
,
newSize
,
oldSize
resource
.
Quantity
)
(
bool
,
error
)
}
}
// VolumePluginWithAttachLimits is an extended interface of VolumePlugin that restricts number of
// VolumePluginWithAttachLimits is an extended interface of VolumePlugin that restricts number of
...
...
pkg/volume/rbd/rbd.go
View file @
529cd711
...
@@ -201,8 +201,8 @@ func (plugin *rbdPlugin) ExpandVolumeDevice(spec *volume.Spec, newSize resource.
...
@@ -201,8 +201,8 @@ func (plugin *rbdPlugin) ExpandVolumeDevice(spec *volume.Spec, newSize resource.
}
}
}
}
func
(
plugin
*
rbdPlugin
)
NodeExpand
(
spec
*
volume
.
Spec
,
devicePath
,
deviceMountPath
string
,
_
,
_
resource
.
Quantity
)
(
bool
,
error
)
{
func
(
plugin
*
rbdPlugin
)
NodeExpand
(
resizeOptions
volume
.
NodeResizeOptions
)
(
bool
,
error
)
{
_
,
err
:=
volutil
.
GenericResizeFS
(
plugin
.
host
,
plugin
.
GetPluginName
(),
devicePath
,
d
eviceMountPath
)
_
,
err
:=
volutil
.
GenericResizeFS
(
plugin
.
host
,
plugin
.
GetPluginName
(),
resizeOptions
.
DevicePath
,
resizeOptions
.
D
eviceMountPath
)
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
err
return
false
,
err
}
}
...
...
pkg/volume/testing/testing.go
View file @
529cd711
...
@@ -537,7 +537,7 @@ func (plugin *FakeVolumePlugin) RequiresFSResize() bool {
...
@@ -537,7 +537,7 @@ func (plugin *FakeVolumePlugin) RequiresFSResize() bool {
return
true
return
true
}
}
func
(
plugin
*
FakeVolumePlugin
)
NodeExpand
(
spec
*
Spec
,
devicePath
,
deviceMountPath
string
,
_
,
_
resource
.
Quantity
)
(
bool
,
error
)
{
func
(
plugin
*
FakeVolumePlugin
)
NodeExpand
(
resizeOptions
NodeResizeOptions
)
(
bool
,
error
)
{
return
true
,
nil
return
true
,
nil
}
}
...
...
pkg/volume/util/operationexecutor/operation_generator.go
View file @
529cd711
...
@@ -597,8 +597,12 @@ func (og *operationGenerator) GenerateMountVolumeFunc(
...
@@ -597,8 +597,12 @@ func (og *operationGenerator) GenerateMountVolumeFunc(
klog
.
Infof
(
volumeToMount
.
GenerateMsgDetailed
(
"MountVolume.WaitForAttach succeeded"
,
fmt
.
Sprintf
(
"DevicePath %q"
,
devicePath
)))
klog
.
Infof
(
volumeToMount
.
GenerateMsgDetailed
(
"MountVolume.WaitForAttach succeeded"
,
fmt
.
Sprintf
(
"DevicePath %q"
,
devicePath
)))
}
}
var
resizeDone
bool
var
resizeDone
bool
var
resizeError
error
var
resizeError
error
resizeOptions
:=
volume
.
NodeResizeOptions
{
DevicePath
:
devicePath
,
}
if
volumeDeviceMounter
!=
nil
{
if
volumeDeviceMounter
!=
nil
{
deviceMountPath
,
err
:=
deviceMountPath
,
err
:=
...
@@ -628,9 +632,12 @@ func (og *operationGenerator) GenerateMountVolumeFunc(
...
@@ -628,9 +632,12 @@ func (og *operationGenerator) GenerateMountVolumeFunc(
return
volumeToMount
.
GenerateError
(
"MountVolume.MarkDeviceAsMounted failed"
,
markDeviceMountedErr
)
return
volumeToMount
.
GenerateError
(
"MountVolume.MarkDeviceAsMounted failed"
,
markDeviceMountedErr
)
}
}
resizeOptions
.
DeviceMountPath
=
deviceMountPath
resizeOptions
.
CSIVolumePhase
=
volume
.
CSIVolumeStaged
// resizeFileSystem will resize the file system if user has requested a resize of
// resizeFileSystem will resize the file system if user has requested a resize of
// underlying persistent volume and is allowed to do so.
// underlying persistent volume and is allowed to do so.
resizeDone
,
resizeError
=
og
.
resizeFileSystem
(
volumeToMount
,
devicePath
,
deviceMountPath
,
volumePluginName
)
resizeDone
,
resizeError
=
og
.
resizeFileSystem
(
volumeToMount
,
resizeOptions
,
volumePluginName
)
if
resizeError
!=
nil
{
if
resizeError
!=
nil
{
return
volumeToMount
.
GenerateError
(
"MountVolume.MountDevice failed while expanding volume"
,
resizeError
)
return
volumeToMount
.
GenerateError
(
"MountVolume.MountDevice failed while expanding volume"
,
resizeError
)
...
@@ -659,9 +666,11 @@ func (og *operationGenerator) GenerateMountVolumeFunc(
...
@@ -659,9 +666,11 @@ func (og *operationGenerator) GenerateMountVolumeFunc(
verbosity
=
klog
.
Level
(
4
)
verbosity
=
klog
.
Level
(
4
)
}
}
klog
.
V
(
verbosity
)
.
Infof
(
detailedMsg
)
klog
.
V
(
verbosity
)
.
Infof
(
detailedMsg
)
resizeOptions
.
DeviceMountPath
=
volumeMounter
.
GetPath
()
resizeOptions
.
CSIVolumePhase
=
volume
.
CSIVolumePublished
if
!
resizeDone
{
if
!
resizeDone
{
resizeDone
,
resizeError
=
og
.
resizeFileSystem
(
volumeToMount
,
""
,
volumeMounter
.
GetPath
()
,
volumePluginName
)
resizeDone
,
resizeError
=
og
.
resizeFileSystem
(
volumeToMount
,
resizeOptions
,
volumePluginName
)
if
resizeError
!=
nil
{
if
resizeError
!=
nil
{
return
volumeToMount
.
GenerateError
(
"MountVolume.Setup failed while expanding volume"
,
resizeError
)
return
volumeToMount
.
GenerateError
(
"MountVolume.Setup failed while expanding volume"
,
resizeError
)
}
}
...
@@ -698,7 +707,7 @@ func (og *operationGenerator) GenerateMountVolumeFunc(
...
@@ -698,7 +707,7 @@ func (og *operationGenerator) GenerateMountVolumeFunc(
}
}
}
}
func
(
og
*
operationGenerator
)
resizeFileSystem
(
volumeToMount
VolumeToMount
,
devicePath
,
deviceMountPath
,
pluginName
string
)
(
bool
,
error
)
{
func
(
og
*
operationGenerator
)
resizeFileSystem
(
volumeToMount
VolumeToMount
,
rsOpts
volume
.
NodeResizeOptions
,
pluginName
string
)
(
bool
,
error
)
{
if
!
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
ExpandPersistentVolumes
)
{
if
!
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
ExpandPersistentVolumes
)
{
klog
.
V
(
4
)
.
Infof
(
"Resizing is not enabled for this volume %s"
,
volumeToMount
.
VolumeName
)
klog
.
V
(
4
)
.
Infof
(
"Resizing is not enabled for this volume %s"
,
volumeToMount
.
VolumeName
)
return
true
,
nil
return
true
,
nil
...
@@ -730,7 +739,10 @@ func (og *operationGenerator) resizeFileSystem(volumeToMount VolumeToMount, devi
...
@@ -730,7 +739,10 @@ func (og *operationGenerator) resizeFileSystem(volumeToMount VolumeToMount, devi
og
.
recorder
.
Eventf
(
volumeToMount
.
Pod
,
v1
.
EventTypeWarning
,
kevents
.
FileSystemResizeFailed
,
simpleMsg
)
og
.
recorder
.
Eventf
(
volumeToMount
.
Pod
,
v1
.
EventTypeWarning
,
kevents
.
FileSystemResizeFailed
,
simpleMsg
)
return
true
,
nil
return
true
,
nil
}
}
resizeDone
,
resizeErr
:=
expandableVolumePlugin
.
NodeExpand
(
volumeToMount
.
VolumeSpec
,
devicePath
,
deviceMountPath
,
pvSpecCap
,
pvcStatusCap
)
rsOpts
.
VolumeSpec
=
volumeToMount
.
VolumeSpec
rsOpts
.
NewSize
=
pvSpecCap
rsOpts
.
OldSize
=
pvcStatusCap
resizeDone
,
resizeErr
:=
expandableVolumePlugin
.
NodeExpand
(
rsOpts
)
if
resizeErr
!=
nil
{
if
resizeErr
!=
nil
{
return
false
,
fmt
.
Errorf
(
"MountVolume.resizeFileSystem failed : %v"
,
resizeErr
)
return
false
,
fmt
.
Errorf
(
"MountVolume.resizeFileSystem failed : %v"
,
resizeErr
)
}
}
...
@@ -1459,41 +1471,67 @@ func (og *operationGenerator) GenerateExpandVolumeFSWithoutUnmountingFunc(
...
@@ -1459,41 +1471,67 @@ func (og *operationGenerator) GenerateExpandVolumeFSWithoutUnmountingFunc(
return
volumetypes
.
GeneratedOperations
{},
volumeToMount
.
GenerateErrorDetailed
(
"VolumeFSResize.FindPluginBySpec failed"
,
err
)
return
volumetypes
.
GeneratedOperations
{},
volumeToMount
.
GenerateErrorDetailed
(
"VolumeFSResize.FindPluginBySpec failed"
,
err
)
}
}
attachableVolumePlugin
,
err
:=
fsResizeFunc
:=
func
()
(
error
,
error
)
{
og
.
volumePluginMgr
.
FindAttachablePluginBySpec
(
volumeToMount
.
VolumeSpec
)
var
resizeDone
bool
if
err
!=
nil
||
attachableVolumePlugin
==
nil
{
resizeOptions
:=
volume
.
NodeResizeOptions
{
if
attachableVolumePlugin
==
nil
{
VolumeSpec
:
volumeToMount
.
VolumeSpec
,
err
=
fmt
.
Errorf
(
"AttachableVolumePlugin is nil"
)
}
return
volumetypes
.
GeneratedOperations
{},
volumeToMount
.
GenerateErrorDetailed
(
"VolumeFSResize.FindAttachablePluginBySpec failed"
,
err
)
}
volumeAttacher
,
err
:=
attachableVolumePlugin
.
NewAttacher
()
if
err
!=
nil
||
volumeAttacher
==
nil
{
if
volumeAttacher
==
nil
{
err
=
fmt
.
Errorf
(
"VolumeAttacher is nil"
)
}
}
return
volumetypes
.
GeneratedOperations
{},
volumeToMount
.
GenerateErrorDetailed
(
"VolumeFSResize.NewAttacher failed"
,
err
)
}
deviceMountPath
,
err
:=
volumeAttacher
.
GetDeviceMountPath
(
volumeToMount
.
VolumeSpec
)
attachableVolumePlugin
,
_
:=
if
err
!=
nil
{
og
.
volumePluginMgr
.
FindAttachablePluginBySpec
(
volumeToMount
.
VolumeSpec
)
return
volumetypes
.
GeneratedOperations
{},
volumeToMount
.
GenerateErrorDetailed
(
"VolumeFSResize.GetDeviceMountPath failed"
,
err
)
}
fsResizeFunc
:=
func
()
(
error
,
error
)
{
if
attachableVolumePlugin
!=
nil
{
_
,
resizeError
:=
og
.
resizeFileSystem
(
volumeToMount
,
volumeToMount
.
DevicePath
,
deviceMountPath
,
volumePlugin
.
GetPluginName
())
volumeAttacher
,
_
:=
attachableVolumePlugin
.
NewAttacher
()
if
volumeAttacher
!=
nil
{
resizeOptions
.
CSIVolumePhase
=
volume
.
CSIVolumeStaged
resizeOptions
.
DevicePath
=
volumeToMount
.
DevicePath
dmp
,
err
:=
volumeAttacher
.
GetDeviceMountPath
(
volumeToMount
.
VolumeSpec
)
if
err
!=
nil
{
return
volumeToMount
.
GenerateError
(
"VolumeFSResize.GetDeviceMountPath failed"
,
err
)
}
resizeOptions
.
DeviceMountPath
=
dmp
resizeDone
,
err
=
og
.
resizeFileSystem
(
volumeToMount
,
resizeOptions
,
volumePlugin
.
GetPluginName
())
if
err
!=
nil
{
return
volumeToMount
.
GenerateError
(
"VolumeFSResize.resizeFileSystem failed"
,
err
)
}
if
resizeDone
{
markFSResizedErr
:=
actualStateOfWorld
.
MarkVolumeAsResized
(
volumeToMount
.
PodName
,
volumeToMount
.
VolumeName
)
if
markFSResizedErr
!=
nil
{
// On failure, return error. Caller will log and retry.
return
volumeToMount
.
GenerateError
(
"VolumeFSResize.MarkVolumeAsResized failed"
,
markFSResizedErr
)
}
return
nil
,
nil
}
}
}
// if we are here that means volume plugin does not support attach interface
volumeMounter
,
newMounterErr
:=
volumePlugin
.
NewMounter
(
volumeToMount
.
VolumeSpec
,
volumeToMount
.
Pod
,
volume
.
VolumeOptions
{})
if
newMounterErr
!=
nil
{
return
volumeToMount
.
GenerateError
(
"VolumeFSResize.NewMounter initialization failed"
,
newMounterErr
)
}
if
resizeError
!=
nil
{
resizeOptions
.
DeviceMountPath
=
volumeMounter
.
GetPath
()
return
volumeToMount
.
GenerateError
(
"VolumeFSResize.resizeFileSystem failed"
,
resizeError
)
resizeOptions
.
CSIVolumePhase
=
volume
.
CSIVolumePublished
resizeDone
,
err
=
og
.
resizeFileSystem
(
volumeToMount
,
resizeOptions
,
volumePlugin
.
GetPluginName
())
if
err
!=
nil
{
return
volumeToMount
.
GenerateError
(
"VolumeFSResize.resizeFileSystem failed"
,
err
)
}
}
markFSResizedErr
:=
actualStateOfWorld
.
MarkVolumeAsResized
(
volumeToMount
.
PodName
,
volumeToMount
.
VolumeName
)
if
resizeDone
{
if
markFSResizedErr
!=
nil
{
markFSResizedErr
:=
actualStateOfWorld
.
MarkVolumeAsResized
(
volumeToMount
.
PodName
,
volumeToMount
.
VolumeName
)
// On failure, return error. Caller will log and retry.
if
markFSResizedErr
!=
nil
{
return
volumeToMount
.
GenerateError
(
"VolumeFSResize.MarkVolumeAsResized failed"
,
markFSResizedErr
)
// On failure, return error. Caller will log and retry.
return
volumeToMount
.
GenerateError
(
"VolumeFSResize.MarkVolumeAsResized failed"
,
markFSResizedErr
)
}
return
nil
,
nil
}
}
return
nil
,
nil
// This is a placeholder error - we should NEVER reach here.
err
:=
fmt
.
Errorf
(
"volume resizing failed for unknown reason"
)
return
volumeToMount
.
GenerateError
(
"VolumeFSResize.resizeFileSystem failed to resize volume"
,
err
)
}
}
eventRecorderFunc
:=
func
(
err
*
error
)
{
eventRecorderFunc
:=
func
(
err
*
error
)
{
if
*
err
!=
nil
{
if
*
err
!=
nil
{
og
.
recorder
.
Eventf
(
volumeToMount
.
Pod
,
v1
.
EventTypeWarning
,
kevents
.
VolumeResizeFailed
,
(
*
err
)
.
Error
())
og
.
recorder
.
Eventf
(
volumeToMount
.
Pod
,
v1
.
EventTypeWarning
,
kevents
.
VolumeResizeFailed
,
(
*
err
)
.
Error
())
...
...
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