Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
58 changes: 29 additions & 29 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,62 +7,62 @@ require (
github.com/google/gofuzz v1.2.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/kubernetes-csi/csi-lib-utils v0.13.0
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
golang.org/x/term v0.6.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/term v0.10.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/grpc v1.51.0
k8s.io/api v0.27.0
k8s.io/apimachinery v0.27.0
google.golang.org/grpc v1.54.0
k8s.io/api v0.28.0-rc.0
k8s.io/apimachinery v0.28.0-rc.0
k8s.io/apiserver v0.27.0
k8s.io/client-go v0.27.0
k8s.io/component-base v0.27.0
k8s.io/csi-translation-lib v0.27.0
k8s.io/klog/v2 v2.90.1
k8s.io/client-go v0.28.0-rc.0
k8s.io/component-base v0.28.0-rc.0
k8s.io/csi-translation-lib v0.28.0-rc.0
k8s.io/klog/v2 v2.100.1
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.1 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/spf13/cobra v1.6.0 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
google.golang.org/genproto v0.0.0-20220502173005-c8bf987b8c21 // indirect
google.golang.org/protobuf v1.28.1 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/kube-openapi v0.0.0-20230308215209-15aac26d736a // indirect
k8s.io/utils v0.0.0-20230209194617-a36077c30491 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
Expand Down
571 changes: 64 additions & 507 deletions go.sum

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions pkg/controller/expand_and_recover.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package controller

import (
"fmt"

"github.com/kubernetes-csi/external-resizer/pkg/util"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand All @@ -32,7 +33,7 @@ func (ctrl *resizeController) expandAndRecover(pvc *v1.PersistentVolumeClaim, pv
return pvc, pv, nil, false
}
// only used as a sentinel value when function returns without
// actually performing expansion on the volume.
// actually performing resize on the volume.
resizeNotCalled := false

// if we are here that already means pvc.Spec.Size > pvc.Status.Size
Expand All @@ -41,9 +42,9 @@ func (ctrl *resizeController) expandAndRecover(pvc *v1.PersistentVolumeClaim, pv
pvSize := pv.Spec.Capacity[v1.ResourceStorage]

newSize := pvcSpecSize
resizeStatus := v1.PersistentVolumeClaimNoExpansionInProgress
if pvc.Status.ResizeStatus != nil {
resizeStatus = *pvc.Status.ResizeStatus
var resizeStatus v1.ClaimResourceStatus
if status, ok := pvc.Status.AllocatedResourceStatuses[v1.ResourceStorage]; ok {
resizeStatus = status
}

var allocatedSize *resource.Quantity
Expand All @@ -53,24 +54,24 @@ func (ctrl *resizeController) expandAndRecover(pvc *v1.PersistentVolumeClaim, pv
}

if pvSize.Cmp(pvcSpecSize) < 0 {
// PV is smaller than user requested size. In general some control-plane volume expansion
// PV is smaller than user requested size. In general some control-plane volume resize
// is necessary at this point but if we were expanding the PVC before we should let
// previous operation finish before starting expansion to new user requested size.
// previous operation finish before starting resize to new user requested size.
switch resizeStatus {
case v1.PersistentVolumeClaimControllerExpansionInProgress,
v1.PersistentVolumeClaimNodeExpansionFailed:
case v1.PersistentVolumeClaimControllerResizeInProgress,
v1.PersistentVolumeClaimNodeResizeFailed:
if allocatedSize != nil {
newSize = *allocatedSize
}
case v1.PersistentVolumeClaimNodeExpansionPending,
v1.PersistentVolumeClaimNodeExpansionInProgress:
case v1.PersistentVolumeClaimNodeResizePending,
v1.PersistentVolumeClaimNodeResizeInProgress:
if allocatedSize != nil {
newSize = *allocatedSize
}
// If PV is already greater or equal to whatever newSize is, then we should
// let previously issued node expansion finish before starting new one.
// let previously issued node resize finish before starting new one.
// This case is essentially an optimization on previous case, generally it is safe
// to let volume plugin receive the expansion call (expansion calls are idempotent)
// to let volume plugin receive the resize call (resize calls are idempotent)
// but having this check here *avoids* unnecessary RPC calls to plugin.
if pvSize.Cmp(newSize) >= 0 {
return pvc, pv, nil, resizeNotCalled
Expand All @@ -80,42 +81,41 @@ func (ctrl *resizeController) expandAndRecover(pvc *v1.PersistentVolumeClaim, pv
}
} else {
// PV has already been expanded and hence we can be here for following reasons:
// 1. If expansion is pending on the node and this was just a spurious update event
// 1. If resize is pending on the node and this was just a spurious update event
// we don't need to do anything and let kubelet handle it.
// 2. It could be that - although we successfully expanded the volume, we failed to
// record our work in API objects, in which case - we should resume resizing operation
// and let API objects be updated.
// 3. Controller successfully expanded the volume, but expansion is failing on the node
// and before kubelet can retry failed node expansion - controller must verify if it is
// 3. Controller successfully expanded the volume, but resize is failing on the node
// and before kubelet can retry failed node resize - controller must verify if it is
// safe to do so.
// 4. While expansion was still pending on the node, user reduced the pvc size.
// 4. While resize was still pending on the node, user reduced the pvc size.
switch resizeStatus {
case v1.PersistentVolumeClaimNodeExpansionInProgress,
v1.PersistentVolumeClaimNodeExpansionPending:
case v1.PersistentVolumeClaimNodeResizeInProgress,
v1.PersistentVolumeClaimNodeResizePending:
// we don't need to do any work. We could be here because of a spurious update event.
// This is case #1
return pvc, pv, nil, resizeNotCalled
case v1.PersistentVolumeClaimNodeExpansionFailed:
case v1.PersistentVolumeClaimNodeResizeFailed:
// This is case#3, we need to reset the pvc status in such a way that kubelet can safely retry volume
// expansion.
// resize.
if ctrl.resizer.DriverSupportsControlPlaneExpansion() && allocatedSize != nil {
newSize = *allocatedSize
} else {
newSize = pvcSpecSize
}
case v1.PersistentVolumeClaimControllerExpansionInProgress,
v1.PersistentVolumeClaimControllerExpansionFailed,
v1.PersistentVolumeClaimNoExpansionInProgress:
case v1.PersistentVolumeClaimControllerResizeInProgress,
v1.PersistentVolumeClaimControllerResizeFailed:
// This is case#2 or it could also be case#4 when user manually shrunk the PVC
// after expanding it.
if allocatedSize != nil {
newSize = *allocatedSize
}
default:
// It is impossible for ResizeStatus to be nil and allocatedSize to be not nil but somehow
// if we do end up in this state, it is safest to resume expansion to last recorded size in
// It is impossible for ResizeStatus to be "" and allocatedSize to be not nil but somehow
// if we do end up in this state, it is safest to resume resize to last recorded size in
// allocatedSize variable.
if pvc.Status.ResizeStatus == nil && allocatedSize != nil {
if pvc.Status.AllocatedResourceStatuses[v1.ResourceStorage] == "" && allocatedSize != nil {
newSize = *allocatedSize
} else {
newSize = pvcSpecSize
Expand All @@ -129,10 +129,10 @@ func (ctrl *resizeController) expandAndRecover(pvc *v1.PersistentVolumeClaim, pv
}

// if pvc previously failed to expand because it can't be expanded when in-use
// we must not try expansion here
// we must not try resize here
if ctrl.usedPVCs.hasInUseErrors(pvc) && ctrl.usedPVCs.checkForUse(pvc) {
// Record an event to indicate that resizer is not expanding the pvc
msg := fmt.Sprintf("Unable to expand %s because CSI driver %s only supports offline expansion and volume is currently in-use", util.PVCKey(pvc), ctrl.resizer.Name())
msg := fmt.Sprintf("Unable to expand %s because CSI driver %s only supports offline resize and volume is currently in-use", util.PVCKey(pvc), ctrl.resizer.Name())
ctrl.eventRecorder.Event(pvc, v1.EventTypeWarning, util.VolumeResizeFailed, msg)
return pvc, pv, fmt.Errorf(msg), resizeNotCalled
}
Expand All @@ -141,10 +141,10 @@ func (ctrl *resizeController) expandAndRecover(pvc *v1.PersistentVolumeClaim, pv
ctrl.eventRecorder.Event(pvc, v1.EventTypeNormal, util.VolumeResizing,
fmt.Sprintf("External resizer is resizing volume %s", pv.Name))

// before trying expansion we will remove the PVC from map
// before trying resize we will remove the PVC from map
// that tracks PVCs which can't be expanded when in-use. If
// pvc indeed can not be expanded when in-use then it will be added
// back when expansion fails with in-use error.
// back when resize fails with in-use error.
ctrl.usedPVCs.removePVCWithInUseError(pvc)
pvc, pv, err = ctrl.callResizeOnPlugin(pvc, pv, newSize, pvcStatusSize)

Expand Down
Loading