From 75c51b666e9b372d2ffd479bfc114eeda8f55a07 Mon Sep 17 00:00:00 2001 From: Rafael Mendez Date: Wed, 17 Jul 2024 19:03:40 +0000 Subject: [PATCH] Add extra-modify-metadata flag to external-resizer sidecar --- cmd/csi-resizer/main.go | 5 ++- pkg/controller/controller_test.go | 4 +- pkg/controller/expand_and_recover_test.go | 2 +- pkg/controller/resize_status_test.go | 2 +- pkg/csi/mock_client.go | 6 ++- pkg/modifier/csi_modifier.go | 15 ++++--- pkg/modifier/csi_modifier_test.go | 4 +- pkg/modifycontroller/controller.go | 47 ++++++++++++---------- pkg/modifycontroller/controller_test.go | 12 +++--- pkg/modifycontroller/modify_status_test.go | 24 +++++------ pkg/modifycontroller/modify_volume.go | 11 +++++ pkg/modifycontroller/modify_volume_test.go | 45 ++++++++++++++++++--- pkg/resizer/csi_resizer_test.go | 8 ++-- 13 files changed, 122 insertions(+), 63 deletions(-) diff --git a/cmd/csi-resizer/main.go b/cmd/csi-resizer/main.go index 26795ad61..a8066374b 100644 --- a/cmd/csi-resizer/main.go +++ b/cmd/csi-resizer/main.go @@ -60,6 +60,8 @@ var ( resyncPeriod = flag.Duration("resync-period", time.Minute*10, "Resync period for cache") workers = flag.Int("workers", 10, "Concurrency to process multiple resize requests") + extraModifyMetadata = flag.Bool("extra-modify-metadata", false, "If set, add pv/pvc metadata to plugin modify requests as parameters.") + csiAddress = flag.String("csi-address", "/run/csi/socket", "Address of the CSI driver socket.") timeout = flag.Duration("timeout", 10*time.Second, "Timeout for waiting for CSI driver socket.") @@ -188,6 +190,7 @@ func main() { *timeout, kubeClient, informerFactory, + *extraModifyMetadata, driverName) if err != nil { klog.ErrorS(err, "Failed to create CSI modifier") @@ -217,7 +220,7 @@ func main() { var mc modifycontroller.ModifyController // Add modify controller only if the feature gate is enabled if utilfeature.DefaultFeatureGate.Enabled(features.VolumeAttributesClass) { - mc = modifycontroller.NewModifyController(modifierName, csiModifier, kubeClient, *resyncPeriod, informerFactory, + mc = modifycontroller.NewModifyController(modifierName, csiModifier, kubeClient, *resyncPeriod, *extraModifyMetadata, informerFactory, workqueue.NewItemExponentialFailureRateLimiter(*retryIntervalStart, *retryIntervalMax)) } diff --git a/pkg/controller/controller_test.go b/pkg/controller/controller_test.go index 5615e4f0f..fb1e802b7 100644 --- a/pkg/controller/controller_test.go +++ b/pkg/controller/controller_test.go @@ -211,7 +211,7 @@ func TestController(t *testing.T) { disableVolumeInUseErrorHandler: true, }, } { - client := csi.NewMockClient("mock", test.NodeResize, true, false, true, true) + client := csi.NewMockClient("mock", test.NodeResize, true, false, true, true, false) driverName, _ := client.GetDriverName(context.TODO()) var expectedCap resource.Quantity @@ -380,7 +380,7 @@ func TestResizePVC(t *testing.T) { }, } { t.Run(test.Name, func(t *testing.T) { - client := csi.NewMockClient("mock", test.NodeResize, true, false, true, true) + client := csi.NewMockClient("mock", test.NodeResize, true, false, true, true, false) if test.expansionError != nil { client.SetExpansionError(test.expansionError) } diff --git a/pkg/controller/expand_and_recover_test.go b/pkg/controller/expand_and_recover_test.go index c9b6baf24..394148b2e 100644 --- a/pkg/controller/expand_and_recover_test.go +++ b/pkg/controller/expand_and_recover_test.go @@ -153,7 +153,7 @@ func TestExpandAndRecover(t *testing.T) { test := tests[i] t.Run(test.name, func(t *testing.T) { featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.RecoverVolumeExpansionFailure, true) - client := csi.NewMockClient("foo", !test.disableNodeExpansion, !test.disableControllerExpansion, false, true, true) + client := csi.NewMockClient("foo", !test.disableNodeExpansion, !test.disableControllerExpansion, false, true, true, false) driverName, _ := client.GetDriverName(context.TODO()) if test.expansionError != nil { client.SetExpansionError(test.expansionError) diff --git a/pkg/controller/resize_status_test.go b/pkg/controller/resize_status_test.go index b2aa8bb26..e3804471c 100644 --- a/pkg/controller/resize_status_test.go +++ b/pkg/controller/resize_status_test.go @@ -77,7 +77,7 @@ func TestResizeFunctions(t *testing.T) { tc := test t.Run(tc.name, func(t *testing.T) { featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.RecoverVolumeExpansionFailure, true) - client := csi.NewMockClient("foo", true, true, false, true, true) + client := csi.NewMockClient("foo", true, true, false, true, true, false) driverName, _ := client.GetDriverName(context.TODO()) pvc := test.pvc diff --git a/pkg/csi/mock_client.go b/pkg/csi/mock_client.go index 27c6524d4..c8644b83d 100644 --- a/pkg/csi/mock_client.go +++ b/pkg/csi/mock_client.go @@ -15,7 +15,9 @@ func NewMockClient( supportsControllerResize bool, supportsControllerModify bool, supportsPluginControllerService bool, - supportsControllerSingleNodeMultiWriter bool) *MockClient { + supportsControllerSingleNodeMultiWriter bool, + supportsExtraModifyMetada bool, +) *MockClient { return &MockClient{ name: name, supportsNodeResize: supportsNodeResize, @@ -23,6 +25,7 @@ func NewMockClient( supportsControllerModify: supportsControllerModify, supportsPluginControllerService: supportsPluginControllerService, supportsControllerSingleNodeMultiWriter: supportsControllerSingleNodeMultiWriter, + extraModifyMetadata: supportsExtraModifyMetada, } } @@ -40,6 +43,7 @@ type MockClient struct { checkMigratedLabel bool usedSecrets atomic.Pointer[map[string]string] usedCapability atomic.Pointer[csi.VolumeCapability] + extraModifyMetadata bool } func (c *MockClient) GetDriverName(context.Context) (string, error) { diff --git a/pkg/modifier/csi_modifier.go b/pkg/modifier/csi_modifier.go index 9eb17c7de..95592421f 100644 --- a/pkg/modifier/csi_modifier.go +++ b/pkg/modifier/csi_modifier.go @@ -33,6 +33,7 @@ func NewModifierFromClient( timeout time.Duration, k8sClient kubernetes.Interface, informerFactory informers.SharedInformerFactory, + extraModifyMetadata bool, driverName string) (Modifier, error) { _, err := supportsControllerModify(csiClient, timeout) @@ -41,18 +42,20 @@ func NewModifierFromClient( } return &csiModifier{ - name: driverName, - client: csiClient, - timeout: timeout, + name: driverName, + client: csiClient, + timeout: timeout, + extraModifyMetadata: extraModifyMetadata, k8sClient: k8sClient, }, nil } type csiModifier struct { - name string - client csi.Client - timeout time.Duration + name string + client csi.Client + timeout time.Duration + extraModifyMetadata bool k8sClient kubernetes.Interface } diff --git a/pkg/modifier/csi_modifier_test.go b/pkg/modifier/csi_modifier_test.go index fd62c3e58..de68df9f2 100644 --- a/pkg/modifier/csi_modifier_test.go +++ b/pkg/modifier/csi_modifier_test.go @@ -28,10 +28,10 @@ func TestNewModifier(t *testing.T) { SupportsControllerModify: false, }, } { - client := csi.NewMockClient("mock", false, false, c.SupportsControllerModify, false, false) + client := csi.NewMockClient("mock", false, false, c.SupportsControllerModify, false, false, false) driverName := "mock-driver" k8sClient, informerFactory := fakeK8s() - _, err := NewModifierFromClient(client, 0, k8sClient, informerFactory, driverName) + _, err := NewModifierFromClient(client, 0, k8sClient, informerFactory, false, driverName) if err != c.Error { t.Errorf("Case %d: Unexpected error: wanted %v, got %v", i, c.Error, err) } diff --git a/pkg/modifycontroller/controller.go b/pkg/modifycontroller/controller.go index dea9040a8..cae14c14e 100644 --- a/pkg/modifycontroller/controller.go +++ b/pkg/modifycontroller/controller.go @@ -47,17 +47,18 @@ type ModifyController interface { } type modifyController struct { - name string - modifier modifier.Modifier - kubeClient kubernetes.Interface - claimQueue workqueue.RateLimitingInterface - eventRecorder record.EventRecorder - pvLister corelisters.PersistentVolumeLister - pvListerSynced cache.InformerSynced - pvcLister corelisters.PersistentVolumeClaimLister - pvcListerSynced cache.InformerSynced - vacLister storagev1beta1listers.VolumeAttributesClassLister - vacListerSynced cache.InformerSynced + name string + modifier modifier.Modifier + kubeClient kubernetes.Interface + claimQueue workqueue.RateLimitingInterface + eventRecorder record.EventRecorder + pvLister corelisters.PersistentVolumeLister + pvListerSynced cache.InformerSynced + pvcLister corelisters.PersistentVolumeClaimLister + pvcListerSynced cache.InformerSynced + vacLister storagev1beta1listers.VolumeAttributesClassLister + vacListerSynced cache.InformerSynced + extraModifyMetadata bool // the key of the map is {PVC_NAMESPACE}/{PVC_NAME} uncertainPVCs map[string]v1.PersistentVolumeClaim } @@ -68,6 +69,7 @@ func NewModifyController( modifier modifier.Modifier, kubeClient kubernetes.Interface, resyncPeriod time.Duration, + extraModifyMetadata bool, informerFactory informers.SharedInformerFactory, pvcRateLimiter workqueue.RateLimiter) ModifyController { pvInformer := informerFactory.Core().V1().PersistentVolumes() @@ -83,17 +85,18 @@ func NewModifyController( pvcRateLimiter, fmt.Sprintf("%s-pvc", name)) ctrl := &modifyController{ - name: name, - modifier: modifier, - kubeClient: kubeClient, - pvListerSynced: pvInformer.Informer().HasSynced, - pvLister: pvInformer.Lister(), - pvcListerSynced: pvcInformer.Informer().HasSynced, - pvcLister: pvcInformer.Lister(), - vacListerSynced: vacInformer.Informer().HasSynced, - vacLister: vacInformer.Lister(), - claimQueue: claimQueue, - eventRecorder: eventRecorder, + name: name, + modifier: modifier, + kubeClient: kubeClient, + pvListerSynced: pvInformer.Informer().HasSynced, + pvLister: pvInformer.Lister(), + pvcListerSynced: pvcInformer.Informer().HasSynced, + pvcLister: pvcInformer.Lister(), + vacListerSynced: vacInformer.Informer().HasSynced, + vacLister: vacInformer.Lister(), + claimQueue: claimQueue, + eventRecorder: eventRecorder, + extraModifyMetadata: extraModifyMetadata, } // Add a resync period as the PVC's request modify can be modified again when we handling // a previous modify request of the same PVC. diff --git a/pkg/modifycontroller/controller_test.go b/pkg/modifycontroller/controller_test.go index 6c7900f75..ce9e95188 100644 --- a/pkg/modifycontroller/controller_test.go +++ b/pkg/modifycontroller/controller_test.go @@ -61,7 +61,7 @@ func TestController(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { // Setup - client := csi.NewMockClient("foo", true, true, true, true, true) + client := csi.NewMockClient("foo", true, true, true, true, true, false) driverName, _ := client.GetDriverName(context.TODO()) var initialObjects []runtime.Object @@ -78,7 +78,7 @@ func TestController(t *testing.T) { pvcInformer := informerFactory.Core().V1().PersistentVolumeClaims() vacInformer := informerFactory.Storage().V1beta1().VolumeAttributesClasses() - csiModifier, err := modifier.NewModifierFromClient(client, 15*time.Second, kubeClient, informerFactory, driverName) + csiModifier, err := modifier.NewModifierFromClient(client, 15*time.Second, kubeClient, informerFactory, false, driverName) if err != nil { t.Fatalf("Test %s: Unable to create modifier: %v", test.name, err) } @@ -86,7 +86,7 @@ func TestController(t *testing.T) { featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.VolumeAttributesClass, true) controller := NewModifyController(driverName, csiModifier, kubeClient, - time.Second, informerFactory, + time.Second, false, informerFactory, workqueue.DefaultControllerRateLimiter()) ctrlInstance, _ := controller.(*modifyController) @@ -154,7 +154,7 @@ func TestModifyPVC(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - client := csi.NewMockClient("mock", true, true, true, true, true) + client := csi.NewMockClient("mock", true, true, true, true, true, false) if test.modifyFailure { client.SetModifyFailed() } @@ -179,7 +179,7 @@ func TestModifyPVC(t *testing.T) { pvcInformer := informerFactory.Core().V1().PersistentVolumeClaims() vacInformer := informerFactory.Storage().V1beta1().VolumeAttributesClasses() - csiModifier, err := modifier.NewModifierFromClient(client, 15*time.Second, kubeClient, informerFactory, driverName) + csiModifier, err := modifier.NewModifierFromClient(client, 15*time.Second, kubeClient, informerFactory, false, driverName) if err != nil { t.Fatalf("Test %s: Unable to create modifier: %v", test.name, err) } @@ -187,7 +187,7 @@ func TestModifyPVC(t *testing.T) { featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.VolumeAttributesClass, true) controller := NewModifyController(driverName, csiModifier, kubeClient, - time.Second, informerFactory, + time.Second, false, informerFactory, workqueue.DefaultControllerRateLimiter()) ctrlInstance, _ := controller.(*modifyController) diff --git a/pkg/modifycontroller/modify_status_test.go b/pkg/modifycontroller/modify_status_test.go index 5a12071e3..bc34d4d37 100644 --- a/pkg/modifycontroller/modify_status_test.go +++ b/pkg/modifycontroller/modify_status_test.go @@ -102,7 +102,7 @@ func TestMarkControllerModifyVolumeStatus(t *testing.T) { tc := test t.Run(tc.name, func(t *testing.T) { featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.VolumeAttributesClass, true) - client := csi.NewMockClient("foo", true, true, true, true, true) + client := csi.NewMockClient("foo", true, true, true, true, true, false) driverName, _ := client.GetDriverName(context.TODO()) pvc := test.pvc @@ -112,13 +112,13 @@ func TestMarkControllerModifyVolumeStatus(t *testing.T) { kubeClient, informerFactory := fakeK8s(initialObjects) - csiModifier, err := modifier.NewModifierFromClient(client, 15*time.Second, kubeClient, informerFactory, driverName) + csiModifier, err := modifier.NewModifierFromClient(client, 15*time.Second, kubeClient, informerFactory, false, driverName) if err != nil { t.Fatalf("Test %s: Unable to create modifier: %v", test.name, err) } controller := NewModifyController(driverName, csiModifier, kubeClient, - time.Second, informerFactory, + time.Second, false, informerFactory, workqueue.DefaultControllerRateLimiter()) ctrlInstance, _ := controller.(*modifyController) @@ -162,7 +162,7 @@ func TestUpdateConditionBasedOnError(t *testing.T) { tc := test t.Run(tc.name, func(t *testing.T) { featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.VolumeAttributesClass, true) - client := csi.NewMockClient("foo", true, true, true, true, true) + client := csi.NewMockClient("foo", true, true, true, true, true, false) driverName, _ := client.GetDriverName(context.TODO()) pvc := test.pvc @@ -172,13 +172,13 @@ func TestUpdateConditionBasedOnError(t *testing.T) { kubeClient, informerFactory := fakeK8s(initialObjects) - csiModifier, err := modifier.NewModifierFromClient(client, 15*time.Second, kubeClient, informerFactory, driverName) + csiModifier, err := modifier.NewModifierFromClient(client, 15*time.Second, kubeClient, informerFactory, false, driverName) if err != nil { t.Fatalf("Test %s: Unable to create modifier: %v", test.name, err) } controller := NewModifyController(driverName, csiModifier, kubeClient, - time.Second, informerFactory, + time.Second, false, informerFactory, workqueue.DefaultControllerRateLimiter()) ctrlInstance, _ := controller.(*modifyController) @@ -231,7 +231,7 @@ func TestMarkControllerModifyVolumeCompleted(t *testing.T) { tc := test t.Run(tc.name, func(t *testing.T) { featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.VolumeAttributesClass, true) - client := csi.NewMockClient("foo", true, true, true, true, true) + client := csi.NewMockClient("foo", true, true, true, true, true, false) driverName, _ := client.GetDriverName(context.TODO()) var initialObjects []runtime.Object @@ -240,13 +240,13 @@ func TestMarkControllerModifyVolumeCompleted(t *testing.T) { kubeClient, informerFactory := fakeK8s(initialObjects) - csiModifier, err := modifier.NewModifierFromClient(client, 15*time.Second, kubeClient, informerFactory, driverName) + csiModifier, err := modifier.NewModifierFromClient(client, 15*time.Second, kubeClient, informerFactory, false, driverName) if err != nil { t.Fatalf("Test %s: Unable to create modifier: %v", test.name, err) } controller := NewModifyController(driverName, csiModifier, kubeClient, - time.Second, informerFactory, + time.Second, false, informerFactory, workqueue.DefaultControllerRateLimiter()) ctrlInstance, _ := controller.(*modifyController) @@ -293,7 +293,7 @@ func TestRemovePVCFromModifyVolumeUncertainCache(t *testing.T) { tc := test t.Run(tc.name, func(t *testing.T) { featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.VolumeAttributesClass, true) - client := csi.NewMockClient("foo", true, true, true, true, true) + client := csi.NewMockClient("foo", true, true, true, true, true, false) driverName, _ := client.GetDriverName(context.TODO()) var initialObjects []runtime.Object @@ -306,13 +306,13 @@ func TestRemovePVCFromModifyVolumeUncertainCache(t *testing.T) { podInformer := informerFactory.Core().V1().Pods() vacInformer := informerFactory.Storage().V1beta1().VolumeAttributesClasses() - csiModifier, err := modifier.NewModifierFromClient(client, 15*time.Second, kubeClient, informerFactory, driverName) + csiModifier, err := modifier.NewModifierFromClient(client, 15*time.Second, kubeClient, informerFactory, false, driverName) if err != nil { t.Fatalf("Test %s: Unable to create modifier: %v", test.name, err) } controller := NewModifyController(driverName, csiModifier, kubeClient, - time.Second, informerFactory, + time.Second, false, informerFactory, workqueue.DefaultControllerRateLimiter()) ctrlInstance, _ := controller.(*modifyController) diff --git a/pkg/modifycontroller/modify_volume.go b/pkg/modifycontroller/modify_volume.go index e06e4857d..2d9d6fa33 100644 --- a/pkg/modifycontroller/modify_volume.go +++ b/pkg/modifycontroller/modify_volume.go @@ -28,6 +28,12 @@ import ( "k8s.io/klog/v2" ) +const ( + pvcNameKey = "csi.storage.k8s.io/pvc/name" + pvcNamespaceKey = "csi.storage.k8s.io/pvc/namespace" + pvNameKey = "csi.storage.k8s.io/pv/name" +) + // The return value bool is only used as a sentinel value when function returns without actually performing modification func (ctrl *modifyController) modify(pvc *v1.PersistentVolumeClaim, pv *v1.PersistentVolume) (*v1.PersistentVolumeClaim, *v1.PersistentVolume, error, bool) { pvcSpecVacName := pvc.Spec.VolumeAttributesClassName @@ -148,6 +154,11 @@ func (ctrl *modifyController) callModifyVolumeOnPlugin( pvc *v1.PersistentVolumeClaim, pv *v1.PersistentVolume, vac *storagev1beta1.VolumeAttributesClass) (*v1.PersistentVolumeClaim, *v1.PersistentVolume, error) { + if ctrl.extraModifyMetadata { + vac.Parameters[pvcNameKey] = pvc.GetName() + vac.Parameters[pvcNamespaceKey] = pvc.GetNamespace() + vac.Parameters[pvNameKey] = pv.GetName() + } err := ctrl.modifier.Modify(pv, vac.Parameters) if err != nil { diff --git a/pkg/modifycontroller/modify_volume_test.go b/pkg/modifycontroller/modify_volume_test.go index 379b2fa21..7f09275f9 100644 --- a/pkg/modifycontroller/modify_volume_test.go +++ b/pkg/modifycontroller/modify_volume_test.go @@ -32,7 +32,12 @@ var ( targetVacObject = &storagev1beta1.VolumeAttributesClass{ ObjectMeta: metav1.ObjectMeta{Name: targetVac}, DriverName: "test-driver", - Parameters: map[string]string{"iops": "4567"}, + Parameters: map[string]string{ + "iops": "4567", + "csi.storage.k8s.io/pvc/name": "foo", + "csi.storage.k8s.io/pvc/namespace": "modify", + "csi.storage.k8s.io/pv/name": "testPV", + }, } ) @@ -49,6 +54,8 @@ func TestModify(t *testing.T) { expectedModifyVolumeStatus *v1.ModifyVolumeStatus expectedCurrentVolumeAttributesClassName *string expectedPVVolumeAttributesClassName *string + withExtraMetadata bool + expectedVacParams map[string]string }{ { name: "nothing to modify", @@ -81,6 +88,23 @@ func TestModify(t *testing.T) { expectedCurrentVolumeAttributesClassName: &targetVac, expectedPVVolumeAttributesClassName: &targetVac, }, + { + name: "modify volume success with extra metadata", + pvc: createTestPVC(pvcName, targetVac /*vacName*/, testVac /*curVacName*/, testVac /*targetVacName*/), + pv: basePV, + vacExists: true, + expectModifyCall: true, + expectedModifyVolumeStatus: nil, + expectedCurrentVolumeAttributesClassName: &targetVac, + expectedPVVolumeAttributesClassName: &targetVac, + withExtraMetadata: true, + expectedVacParams: map[string]string{ + "iops": "4567", + "csi.storage.k8s.io/pvc/name": basePVC.GetName(), + "csi.storage.k8s.io/pvc/namespace": basePVC.GetNamespace(), + "csi.storage.k8s.io/pv/name": "testPV", + }, + }, } for i := range tests { @@ -88,7 +112,7 @@ func TestModify(t *testing.T) { t.Run(test.name, func(t *testing.T) { // Setup featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.VolumeAttributesClass, true) - client := csi.NewMockClient("foo", true, true, true, true, true) + client := csi.NewMockClient("foo", true, true, true, true, true, test.withExtraMetadata) driverName, _ := client.GetDriverName(context.TODO()) var initialObjects []runtime.Object @@ -105,13 +129,13 @@ func TestModify(t *testing.T) { pvcInformer := informerFactory.Core().V1().PersistentVolumeClaims() vacInformer := informerFactory.Storage().V1beta1().VolumeAttributesClasses() - csiModifier, err := modifier.NewModifierFromClient(client, 15*time.Second, kubeClient, informerFactory, driverName) + csiModifier, err := modifier.NewModifierFromClient(client, 15*time.Second, kubeClient, informerFactory, test.withExtraMetadata, driverName) if err != nil { t.Fatalf("Test %s: Unable to create modifier: %v", test.name, err) } controller := NewModifyController(driverName, csiModifier, kubeClient, - time.Second, informerFactory, + time.Second, test.withExtraMetadata, informerFactory, workqueue.DefaultControllerRateLimiter()) ctrlInstance, _ := controller.(*modifyController) @@ -134,7 +158,6 @@ func TestModify(t *testing.T) { // Action pvc, pv, err, modifyCalled := ctrlInstance.modify(test.pvc, test.pv) // Verify - if err != nil { t.Errorf("modify failed with %v", err) } @@ -158,6 +181,18 @@ func TestModify(t *testing.T) { if diff := cmp.Diff(*test.expectedPVVolumeAttributesClassName, *actualPVVolumeAttributesClassName); diff != "" { t.Errorf("expected VolumeAttributesClassName of pv to be %v, got %v", *test.expectedPVVolumeAttributesClassName, *actualPVVolumeAttributesClassName) } + + if test.withExtraMetadata { + vacObj, err := ctrlInstance.vacLister.Get(*test.expectedPVVolumeAttributesClassName) + if err != nil { + t.Errorf("failed to get VAC: %v", err) + } else { + vacParams := vacObj.Parameters + if diff := cmp.Diff(test.expectedVacParams, vacParams); diff != "" { + t.Errorf("expected VAC parameters to be %v, got %v", test.expectedVacParams, vacParams) + } + } + } }) } } diff --git a/pkg/resizer/csi_resizer_test.go b/pkg/resizer/csi_resizer_test.go index ea6b9e023..6d089511f 100644 --- a/pkg/resizer/csi_resizer_test.go +++ b/pkg/resizer/csi_resizer_test.go @@ -72,7 +72,7 @@ func TestNewResizer(t *testing.T) { Error: resizeNotSupportErr, }, } { - client := csi.NewMockClient("mock", c.SupportsNodeResize, c.SupportsControllerResize, false, c.SupportsPluginControllerService, c.SupportsControllerSingleNodeMultiWriter) + client := csi.NewMockClient("mock", c.SupportsNodeResize, c.SupportsControllerResize, false, c.SupportsPluginControllerService, c.SupportsControllerSingleNodeMultiWriter, false) driverName := "mock-driver" k8sClient := fake.NewSimpleClientset() resizer, err := NewResizerFromClient(client, 0, k8sClient, driverName) @@ -106,7 +106,7 @@ func TestResizeWithSecret(t *testing.T) { }, } for _, tc := range tests { - client := csi.NewMockClient("mock", true, true, false, true, true) + client := csi.NewMockClient("mock", true, true, false, true, true, false) secret := makeSecret("some-secret", "secret-namespace") k8sClient := fake.NewSimpleClientset(secret) pv := makeTestPV("test-csi", 2, "ebs-csi", "vol-abcde", tc.hasExpansionSecret) @@ -164,7 +164,7 @@ func TestResizeMigratedPV(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { driverName := tc.driverName - client := csi.NewMockClient(driverName, true, true, false, true, true) + client := csi.NewMockClient(driverName, true, true, false, true, true, false) client.SetCheckMigratedLabel() k8sClient := fake.NewSimpleClientset() resizer, err := NewResizerFromClient(client, 0, k8sClient, driverName) @@ -433,7 +433,7 @@ func TestCanSupport(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { driverName := tc.driverName - client := csi.NewMockClient(driverName, true, true, false, true, true) + client := csi.NewMockClient(driverName, true, true, false, true, true, false) k8sClient := fake.NewSimpleClientset() resizer, err := NewResizerFromClient(client, 0, k8sClient, driverName) if err != nil {