mirror of
https://github.com/outbackdingo/kubernetes.git
synced 2026-01-27 18:19:28 +00:00
Add code for not expanding volume if it has NodeExpansionNotRequired annotation
This commit is contained in:
@@ -31,10 +31,6 @@ import (
|
||||
volumetypes "k8s.io/kubernetes/pkg/volume/util/types"
|
||||
)
|
||||
|
||||
var (
|
||||
NodeExpansionNotRequired = "volume.kubernetes.io/node-expansion-not-required"
|
||||
)
|
||||
|
||||
type NodeExpander struct {
|
||||
nodeResizeOperationOpts
|
||||
kubeClient clientset.Interface
|
||||
@@ -105,11 +101,15 @@ func (ne *NodeExpander) runPreCheck() bool {
|
||||
ne.pvcAlreadyUpdated = true
|
||||
}
|
||||
|
||||
// PVC is already expanded but we are still trying to expand the volume because
|
||||
// last recorded size in ASOW is older. This can happen for RWX volume types.
|
||||
// if the volume is already expanded, but volume is of type RWX and
|
||||
// pvc doesn't have annotation indicating that node expansion is not required
|
||||
// then we should allow node expansion to proceed, even if the volume is already expanded.
|
||||
//
|
||||
// This special cases is needed because, in case of RWX volumes, the volume expansion
|
||||
// should be performed on all nodes, even if the volume is already expanded.
|
||||
if ne.pvcAlreadyUpdated &&
|
||||
storage.ContainsAccessMode(ne.pvc.Spec.AccessModes, v1.ReadWriteMany) &&
|
||||
!metav1.HasAnnotation(ne.pvc.ObjectMeta, NodeExpansionNotRequired) {
|
||||
!metav1.HasAnnotation(ne.pvc.ObjectMeta, volumetypes.NodeExpansionNotRequired) {
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -162,6 +162,19 @@ func TestNodeExpander(t *testing.T) {
|
||||
expectFinalErrors: false,
|
||||
expectedStatusSize: resource.MustParse("2G"),
|
||||
},
|
||||
{
|
||||
name: "RWX volumes, pv.spec.cap = pvc.status.cap, resizeStatus='', desiredSize > actualSize, node-expansion-not-required",
|
||||
pvc: addAnnotation(addAccessMode(getTestPVC("test-vol0", "2G", "2G", "2G", nil), v1.ReadWriteMany), volumetypes.NodeExpansionNotRequired, "true"),
|
||||
pv: getTestPV("test-vol0", "2G"),
|
||||
recoverVolumeExpansionFailure: true,
|
||||
|
||||
expectedResizeStatus: "",
|
||||
expectedReturnValue: true,
|
||||
expectResizeCall: false,
|
||||
assumeResizeOpAsFinished: true,
|
||||
expectFinalErrors: false,
|
||||
expectedStatusSize: resource.MustParse("2G"),
|
||||
},
|
||||
{
|
||||
name: "pv.spec.cap > pvc.status.cap, resizeStatus=node_expansion_pending, featuregate=disabled",
|
||||
pvc: getTestPVC("test-vol0", "2G", "1G", "2G", &nodeResizePending),
|
||||
|
||||
@@ -563,6 +563,14 @@ func addAccessMode(pvc *v1.PersistentVolumeClaim, mode v1.PersistentVolumeAccess
|
||||
return pvc
|
||||
}
|
||||
|
||||
func addAnnotation(pvc *v1.PersistentVolumeClaim, key, value string) *v1.PersistentVolumeClaim {
|
||||
if pvc.Annotations == nil {
|
||||
pvc.Annotations = make(map[string]string)
|
||||
}
|
||||
pvc.Annotations[key] = value
|
||||
return pvc
|
||||
}
|
||||
|
||||
func getTestPV(volumeName string, specSize string) *v1.PersistentVolume {
|
||||
return &v1.PersistentVolume{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
|
||||
@@ -25,6 +25,10 @@ import (
|
||||
"k8s.io/mount-utils"
|
||||
)
|
||||
|
||||
var (
|
||||
NodeExpansionNotRequired = "volume.kubernetes.io/node-expansion-not-required"
|
||||
)
|
||||
|
||||
// UniquePodName defines the type to key pods off of
|
||||
type UniquePodName types.UID
|
||||
|
||||
|
||||
Reference in New Issue
Block a user