From 26798d24c2007a07d3b9fa384ecd512ec8200e35 Mon Sep 17 00:00:00 2001 From: Hemant Kumar Date: Wed, 14 Aug 2024 12:54:40 -0400 Subject: [PATCH] Fix linter hints etc --- .../util/operationexecutor/node_expander.go | 24 ++++++++++++------- .../operationexecutor/node_expander_test.go | 3 ++- .../operationexecutor/operation_generator.go | 4 ++-- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/pkg/volume/util/operationexecutor/node_expander.go b/pkg/volume/util/operationexecutor/node_expander.go index d20ef6e9cd5..c909949a475 100644 --- a/pkg/volume/util/operationexecutor/node_expander.go +++ b/pkg/volume/util/operationexecutor/node_expander.go @@ -46,6 +46,9 @@ type NodeExpander struct { // PVC has already been updated - possibly because expansion already succeeded on different node. // This can happen when a RWX PVC is expanded. pvcAlreadyUpdated bool + + // testStatus is used for testing purposes only. + testStatus testResponseData } func newNodeExpander(resizeOp nodeResizeOperationOpts, client clientset.Interface, recorder record.EventRecorder) *NodeExpander { @@ -115,11 +118,12 @@ func (ne *NodeExpander) runPreCheck() bool { return false } -func (ne *NodeExpander) expandOnPlugin() (bool, resource.Quantity, error, testResponseData) { +func (ne *NodeExpander) expandOnPlugin() (bool, resource.Quantity, error) { allowExpansion := ne.runPreCheck() if !allowExpansion { klog.V(3).Infof("NodeExpandVolume is not allowed to proceed for volume %s with resizeStatus %s", ne.vmt.VolumeName, ne.resizeStatus) - return false, ne.pluginResizeOpts.OldSize, nil, testResponseData{false, true} + ne.testStatus = testResponseData{false /* resizeCalledOnPlugin */, true /* assumeResizeFinished */} + return false, ne.pluginResizeOpts.OldSize, nil } var err error @@ -131,7 +135,8 @@ func (ne *NodeExpander) expandOnPlugin() (bool, resource.Quantity, error, testRe if err != nil { msg := ne.vmt.GenerateErrorDetailed("MountVolume.NodeExpandVolume failed to mark node expansion in progress: %v", err) klog.Errorf(msg.Error()) - return false, ne.pluginResizeOpts.OldSize, err, testResponseData{} + ne.testStatus = testResponseData{} + return false, ne.pluginResizeOpts.OldSize, err } } _, resizeErr := ne.volumePlugin.NodeExpand(ne.pluginResizeOpts) @@ -158,24 +163,27 @@ func (ne *NodeExpander) expandOnPlugin() (bool, resource.Quantity, error, testRe if volumetypes.IsFailedPreconditionError(resizeErr) { ne.actualStateOfWorld.MarkForInUseExpansionError(ne.vmt.VolumeName) klog.Errorf(ne.vmt.GenerateErrorDetailed("MountVolume.NodeExapndVolume failed with %v", resizeErr).Error()) - return false, ne.pluginResizeOpts.OldSize, nil, testResponseData{assumeResizeFinished: true, resizeCalledOnPlugin: true} + ne.testStatus = testResponseData{assumeResizeFinished: true, resizeCalledOnPlugin: true} + return false, ne.pluginResizeOpts.OldSize, nil } - return false, ne.pluginResizeOpts.OldSize, resizeErr, testResponseData{assumeResizeFinished: true, resizeCalledOnPlugin: true} + ne.testStatus = testResponseData{assumeResizeFinished: true, resizeCalledOnPlugin: true} + return false, ne.pluginResizeOpts.OldSize, resizeErr } simpleMsg, detailedMsg := ne.vmt.GenerateMsg("MountVolume.NodeExpandVolume succeeded", nodeName) ne.recorder.Eventf(ne.vmt.Pod, v1.EventTypeNormal, kevents.FileSystemResizeSuccess, simpleMsg) ne.recorder.Eventf(ne.pvc, v1.EventTypeNormal, kevents.FileSystemResizeSuccess, simpleMsg) klog.InfoS(detailedMsg, "pod", klog.KObj(ne.vmt.Pod)) + ne.testStatus = testResponseData{true /*resizeCalledOnPlugin */, true /* assumeResizeFinished */} // no need to update PVC object if we already updated it if ne.pvcAlreadyUpdated { - return true, ne.pluginResizeOpts.NewSize, nil, testResponseData{true, true} + return true, ne.pluginResizeOpts.NewSize, nil } // File system resize succeeded, now update the PVC's Capacity to match the PV's ne.pvc, err = util.MarkFSResizeFinished(ne.pvc, ne.pluginResizeOpts.NewSize, ne.kubeClient) if err != nil { - return true, ne.pluginResizeOpts.NewSize, fmt.Errorf("mountVolume.NodeExpandVolume update pvc status failed: %w", err), testResponseData{true, true} + return true, ne.pluginResizeOpts.NewSize, fmt.Errorf("mountVolume.NodeExpandVolume update pvc status failed: %w", err) } - return true, ne.pluginResizeOpts.NewSize, nil, testResponseData{true, true} + return true, ne.pluginResizeOpts.NewSize, nil } diff --git a/pkg/volume/util/operationexecutor/node_expander_test.go b/pkg/volume/util/operationexecutor/node_expander_test.go index 16709147295..81938d509c6 100644 --- a/pkg/volume/util/operationexecutor/node_expander_test.go +++ b/pkg/volume/util/operationexecutor/node_expander_test.go @@ -162,7 +162,8 @@ func TestNodeExpander(t *testing.T) { ogInstance, _ := og.(*operationGenerator) nodeExpander := newNodeExpander(resizeOp, ogInstance.kubeClient, ogInstance.recorder) - _, _, err, expansionResponse := nodeExpander.expandOnPlugin() + _, _, err := nodeExpander.expandOnPlugin() + expansionResponse := nodeExpander.testStatus pvc = nodeExpander.pvc pvcStatusCap := pvc.Status.Capacity[v1.ResourceStorage] diff --git a/pkg/volume/util/operationexecutor/operation_generator.go b/pkg/volume/util/operationexecutor/operation_generator.go index 69e6af2c58d..5611e53e77a 100644 --- a/pkg/volume/util/operationexecutor/operation_generator.go +++ b/pkg/volume/util/operationexecutor/operation_generator.go @@ -2013,7 +2013,7 @@ func (og *operationGenerator) expandVolumeDuringMount(volumeToMount VolumeToMoun rsOpts.NewSize = pvc.Status.AllocatedResources[v1.ResourceStorage] resizeOp.pluginResizeOpts = rsOpts nodeExpander := newNodeExpander(resizeOp, og.kubeClient, og.recorder) - resizeFinished, _, err, _ := nodeExpander.expandOnPlugin() + resizeFinished, _, err := nodeExpander.expandOnPlugin() return resizeFinished, err } else { return og.legacyCallNodeExpandOnPlugin(resizeOp) @@ -2081,7 +2081,7 @@ func (og *operationGenerator) nodeExpandVolume( rsOpts.NewSize = newSize resizeOp.pluginResizeOpts.NewSize = newSize nodeExpander := newNodeExpander(resizeOp, og.kubeClient, og.recorder) - resizeFinished, newSize, err, _ := nodeExpander.expandOnPlugin() + resizeFinished, newSize, err := nodeExpander.expandOnPlugin() return resizeFinished, newSize, err } else { resizeFinished, err := og.legacyCallNodeExpandOnPlugin(resizeOp)