Skip to content
Merged
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
  •  
  •  
  •  
60 changes: 30 additions & 30 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
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
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.28.0-rc.0
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
575 changes: 66 additions & 509 deletions go.sum

Large diffs are not rendered by default.

29 changes: 13 additions & 16 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 @@ -41,10 +42,7 @@ 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
}
resizeStatus := pvc.Status.AllocatedResourceStatuses[v1.ResourceStorage]

var allocatedSize *resource.Quantity
t, ok := pvc.Status.AllocatedResources[v1.ResourceStorage]
Expand All @@ -57,13 +55,13 @@ func (ctrl *resizeController) expandAndRecover(pvc *v1.PersistentVolumeClaim, pv
// 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.
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
}
Expand All @@ -90,32 +88,31 @@ func (ctrl *resizeController) expandAndRecover(pvc *v1.PersistentVolumeClaim, pv
// safe to do so.
// 4. While expansion 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.
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
// It is impossible for ResizeStatus to be empty and allocatedSize to be not nil but somehow
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the comment here is different from the other PR kubernetes/kubernetes#116335. Should this be empty or ""?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty and "" are same thing right? the main thing is - corresponding intree code doesn't ever actually gets executed because all volume plugins that support volume expansion are actually now migrated to CSI.

// if we do end up in this state, it is safest to resume expansion to last recorded size in
// allocatedSize variable.
if pvc.Status.ResizeStatus == nil && allocatedSize != nil {
if resizeStatus == "" && allocatedSize != nil {
newSize = *allocatedSize
} else {
newSize = pvcSpecSize
Expand Down
56 changes: 31 additions & 25 deletions pkg/controller/expand_and_recover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package controller

import (
"context"
"testing"
"time"

"github.com/kubernetes-csi/external-resizer/pkg/csi"
"github.com/kubernetes-csi/external-resizer/pkg/features"
"github.com/kubernetes-csi/external-resizer/pkg/resizer"
Expand All @@ -12,8 +15,6 @@ import (
utilfeature "k8s.io/apiserver/pkg/util/feature"
"k8s.io/client-go/util/workqueue"
featuregatetesting "k8s.io/component-base/featuregate/testing"
"testing"
"time"
)

func TestExpandAndRecover(t *testing.T) {
Expand All @@ -25,81 +26,81 @@ func TestExpandAndRecover(t *testing.T) {
disableNodeExpansion bool
disableControllerExpansion bool
// expectations of test
expectedResizeStatus v1.PersistentVolumeClaimResizeStatus
expectedResizeStatus v1.ClaimResourceStatus
expectedAllocatedSize resource.Quantity
expectResizeCall bool
}{
{
name: "pvc.spec.size > pv.spec.size, resize_status=node_expansion_inprogress",
pvc: getTestPVC("test-vol0", "2G", "1G", "", v1.PersistentVolumeClaimNoExpansionInProgress),
pvc: getTestPVC("test-vol0", "2G", "1G", "", ""),
pv: createPV(1, "claim01", defaultNS, "test-uid", &fsVolumeMode),
expectedResizeStatus: v1.PersistentVolumeClaimNodeExpansionPending,
expectedResizeStatus: v1.PersistentVolumeClaimNodeResizePending,
expectedAllocatedSize: resource.MustParse("2G"),
expectResizeCall: true,
},
{
name: "pvc.spec.size = pv.spec.size, resize_status=no_expansion_inprogress",
pvc: getTestPVC("test-vol0", "1G", "1G", "", v1.PersistentVolumeClaimNoExpansionInProgress),
pvc: getTestPVC("test-vol0", "1G", "1G", "", ""),
pv: createPV(1, "claim01", defaultNS, "test-uid", &fsVolumeMode),
expectedResizeStatus: v1.PersistentVolumeClaimNodeExpansionPending,
expectedResizeStatus: v1.PersistentVolumeClaimNodeResizePending,
expectedAllocatedSize: resource.MustParse("1G"),
expectResizeCall: true,
},
{
name: "pvc.spec.size > pv.spec.size, resize_status=controller_expansion_failed",
pvc: getTestPVC("test-vol0", "5G" /*specSize*/, "3G" /*statusSize*/, "10G" /*allocatedSize*/, v1.PersistentVolumeClaimControllerExpansionFailed),
pvc: getTestPVC("test-vol0", "5G" /*specSize*/, "3G" /*statusSize*/, "10G" /*allocatedSize*/, v1.PersistentVolumeClaimControllerResizeFailed),
pv: createPV(3, "claim01", defaultNS, "test-uid", &fsVolumeMode),
expectedResizeStatus: v1.PersistentVolumeClaimNodeExpansionPending,
expectedResizeStatus: v1.PersistentVolumeClaimNodeResizePending,
expectedAllocatedSize: resource.MustParse("5G"),
expectResizeCall: true,
},
{
name: "pvc.spec.size = pv.spec.size, resize_status=node_expansion_failed, disable_controller_expansion=true",
pvc: getTestPVC("test-vol0", "5G" /*specSize*/, "3G" /*statusSize*/, "10G" /*allocatedSize*/, v1.PersistentVolumeClaimNodeExpansionFailed),
pvc: getTestPVC("test-vol0", "5G" /*specSize*/, "3G" /*statusSize*/, "10G" /*allocatedSize*/, v1.PersistentVolumeClaimNodeResizeFailed),
pv: createPV(10, "claim01", defaultNS, "test-uid", &fsVolumeMode),
disableControllerExpansion: true,
expectedResizeStatus: v1.PersistentVolumeClaimNodeExpansionPending,
expectedResizeStatus: v1.PersistentVolumeClaimNodeResizePending,
expectedAllocatedSize: resource.MustParse("5G"),
expectResizeCall: true,
},
{
name: "pvc.spec.size = pv.spec.size, resize_status=node_expansion_pending",
pvc: getTestPVC("test-vol0", "1G", "1G", "1G", v1.PersistentVolumeClaimNodeExpansionPending),
pvc: getTestPVC("test-vol0", "1G", "1G", "1G", v1.PersistentVolumeClaimNodeResizePending),
pv: createPV(1, "claim01", defaultNS, "test-uid", &fsVolumeMode),
expectedResizeStatus: v1.PersistentVolumeClaimNodeExpansionPending,
expectedResizeStatus: v1.PersistentVolumeClaimNodeResizePending,
expectedAllocatedSize: resource.MustParse("1G"),
expectResizeCall: false,
},
{
name: "pvc.spec.size > pv.spec.size, disable_node_expansion=true, resize_status=no_expansion_inprogress",
pvc: getTestPVC("test-vol0", "2G", "1G", "", v1.PersistentVolumeClaimNoExpansionInProgress),
pvc: getTestPVC("test-vol0", "2G", "1G", "", ""),
pv: createPV(1, "claim01", defaultNS, "test-uid", &fsVolumeMode),
disableNodeExpansion: true,
expectedResizeStatus: v1.PersistentVolumeClaimNoExpansionInProgress,
expectedResizeStatus: "",
expectedAllocatedSize: resource.MustParse("2G"),
expectResizeCall: true,
},
{
name: "pv.spec.size >= pvc.spec.size, resize_status=node_expansion_failed",
pvc: getTestPVC("test-vol0", "2G", "1G", "2G", v1.PersistentVolumeClaimNodeExpansionFailed),
pvc: getTestPVC("test-vol0", "2G", "1G", "2G", v1.PersistentVolumeClaimNodeResizeFailed),
pv: createPV(2, "claim01", defaultNS, "test-uid", &fsVolumeMode),
expectedResizeStatus: v1.PersistentVolumeClaimNodeExpansionPending,
expectedResizeStatus: v1.PersistentVolumeClaimNodeResizePending,
expectedAllocatedSize: resource.MustParse("2G"),
expectResizeCall: true,
},
{
name: "pvc.spec.size > pv.spec.size, resize_status-node_expansion_pending",
pvc: getTestPVC("test-vol0", "10G", "1G", "3G", v1.PersistentVolumeClaimNodeExpansionPending),
pvc: getTestPVC("test-vol0", "10G", "1G", "3G", v1.PersistentVolumeClaimNodeResizePending),
pv: createPV(3, "claim01", defaultNS, "test-uid", &fsVolumeMode),
expectedResizeStatus: v1.PersistentVolumeClaimNodeExpansionPending,
expectedResizeStatus: v1.PersistentVolumeClaimNodeResizePending,
expectedAllocatedSize: resource.MustParse("3G"),
expectResizeCall: false,
},
{
name: "pvc.spec.size > pv.spec.size, resize_status-node_expansion_inprogress",
pvc: getTestPVC("test-vol0", "10G", "1G", "3G", v1.PersistentVolumeClaimNodeExpansionInProgress),
pvc: getTestPVC("test-vol0", "10G", "1G", "3G", v1.PersistentVolumeClaimNodeResizeInProgress),
pv: createPV(3, "claim01", defaultNS, "test-uid", &fsVolumeMode),
expectedResizeStatus: v1.PersistentVolumeClaimNodeExpansionInProgress,
expectedResizeStatus: v1.PersistentVolumeClaimNodeResizeInProgress,
expectedAllocatedSize: resource.MustParse("3G"),
expectResizeCall: false,
},
Expand Down Expand Up @@ -134,8 +135,11 @@ func TestExpandAndRecover(t *testing.T) {
if test.expectResizeCall != resizeCalled {
t.Fatalf("expansion failed: expected resize called %t, got %t", test.expectResizeCall, resizeCalled)
}
if *pvc.Status.ResizeStatus != test.expectedResizeStatus {
t.Fatalf("expected resize status to be %s, got %s", test.expectedResizeStatus, *pvc.Status.ResizeStatus)

actualResizeStatus := pvc.Status.AllocatedResourceStatuses[v1.ResourceStorage]

if actualResizeStatus != test.expectedResizeStatus {
t.Fatalf("expected resize status to be %s, got %s", test.expectedResizeStatus, actualResizeStatus)
}

actualAllocatedSize := pvc.Status.AllocatedResources.Storage()
Expand All @@ -148,7 +152,7 @@ func TestExpandAndRecover(t *testing.T) {
}
}

func getTestPVC(volumeName string, specSize, statusSize, allocatedSize string, resizeStatus v1.PersistentVolumeClaimResizeStatus) *v1.PersistentVolumeClaim {
func getTestPVC(volumeName string, specSize, statusSize, allocatedSize string, resizeStatus v1.ClaimResourceStatus) *v1.PersistentVolumeClaim {
pvc := &v1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: "claim01",
Expand All @@ -171,7 +175,9 @@ func getTestPVC(volumeName string, specSize, statusSize, allocatedSize string, r
pvc.Status.AllocatedResources = v1.ResourceList{v1.ResourceStorage: resource.MustParse(allocatedSize)}
}
if len(resizeStatus) > 0 {
pvc.Status.ResizeStatus = &resizeStatus
pvc.Status.AllocatedResourceStatuses = map[v1.ResourceName]v1.ClaimResourceStatus{
v1.ResourceStorage: resizeStatus,
}
}
return pvc
}
Loading