From 9a7c25fd3931501aad7b1b4c4cdc7f24aee55108 Mon Sep 17 00:00:00 2001 From: aSquare14 Date: Tue, 4 May 2021 19:05:08 +0530 Subject: [PATCH 1/4] fixes opt.semgrep.err-nil-check Signed-off-by: aSquare14 --- pkg/zcmd/zfs/listsnap/builder.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pkg/zcmd/zfs/listsnap/builder.go b/pkg/zcmd/zfs/listsnap/builder.go index 27dd5aac..370c8fab 100644 --- a/pkg/zcmd/zfs/listsnap/builder.go +++ b/pkg/zcmd/zfs/listsnap/builder.go @@ -99,10 +99,8 @@ func (v *VolumeListSnapshot) Execute() (SnapshotList, error) { } err = json.Unmarshal(ret, &snapshotList) - if err != nil { - return snapshotList, err - } - return snapshotList, nil + + return snapshotList, err } // Build returns the VolumeListSnapshot object generated by builder From dc2d22dd76bd73f3159ffe0d58f6d724df3276e7 Mon Sep 17 00:00:00 2001 From: aSquare14 Date: Tue, 4 May 2021 19:09:56 +0530 Subject: [PATCH 2/4] remove more err Signed-off-by: aSquare14 --- pkg/controllers/cspc-controller/controller.go | 1 + pkg/controllers/cstorvolumeconfig/controller.go | 5 +---- pkg/pool/operations/disk_operation.go | 6 ++---- pkg/server/cstorvolumeconfig/https_test.go | 5 +---- pkg/server/cstorvolumeconfig/restore_endpoint.go | 5 +---- pkg/webhook/cspc_operations.go | 5 +---- pkg/webhook/cvc.go | 5 +---- 7 files changed, 8 insertions(+), 24 deletions(-) diff --git a/pkg/controllers/cspc-controller/controller.go b/pkg/controllers/cspc-controller/controller.go index 30b2ede3..911e8684 100644 --- a/pkg/controllers/cspc-controller/controller.go +++ b/pkg/controllers/cspc-controller/controller.go @@ -18,6 +18,7 @@ package cspccontroller import ( "fmt" + cstor "github.com/openebs/api/v2/pkg/apis/cstor/v1" types "github.com/openebs/api/v2/pkg/apis/types" clientset "github.com/openebs/api/v2/pkg/client/clientset/versioned" diff --git a/pkg/controllers/cstorvolumeconfig/controller.go b/pkg/controllers/cstorvolumeconfig/controller.go index 821bc5f3..916c1abb 100644 --- a/pkg/controllers/cstorvolumeconfig/controller.go +++ b/pkg/controllers/cstorvolumeconfig/controller.go @@ -249,11 +249,8 @@ func (c *CVCController) syncCVC(cvc *apis.CStorVolumeConfig) error { // sync policy changes from cvc.spec.policy e.g. tunables like toleration, resource requirements etc err = c.syncPolicySpec(cvc) - if err != nil { - return err - } - return nil + return err } // UpdateCVCObj updates the cstorvolumeconfig object resource to reflect the diff --git a/pkg/pool/operations/disk_operation.go b/pkg/pool/operations/disk_operation.go index 0e2d3b23..6694250b 100644 --- a/pkg/pool/operations/disk_operation.go +++ b/pkg/pool/operations/disk_operation.go @@ -57,10 +57,8 @@ func (oc *OperationsConfig) addRaidGroup(r cstor.RaidGroup, dType, pType string) WithVdevList(vdevlist). WithExecutor(oc.zcmdExecutor). Execute() - if err != nil { - return err - } - return nil + + return err } // TODO: Get better naming convention from reviews diff --git a/pkg/server/cstorvolumeconfig/https_test.go b/pkg/server/cstorvolumeconfig/https_test.go index 984b20e5..123559f9 100644 --- a/pkg/server/cstorvolumeconfig/https_test.go +++ b/pkg/server/cstorvolumeconfig/https_test.go @@ -177,10 +177,7 @@ func (f *fixture) createFakePoolPod(cspi *cstorapis.CStorPoolInstance) error { }, } _, err := f.k8sClient.CoreV1().Pods(namespace).Create(context.TODO(), pod, metav1.CreateOptions{}) - if err != nil { - return err - } - return nil + return err } // createFakeVolumeReplicas will create fake CVRs on cstorPools diff --git a/pkg/server/cstorvolumeconfig/restore_endpoint.go b/pkg/server/cstorvolumeconfig/restore_endpoint.go index ba51bb11..eaafee08 100644 --- a/pkg/server/cstorvolumeconfig/restore_endpoint.go +++ b/pkg/server/cstorvolumeconfig/restore_endpoint.go @@ -177,10 +177,7 @@ func (rOps *restoreAPIOps) createVolumeForRestore(restoreObj *cstorapis.CStorRes // In case of CStor CSI volumes, if CVC.Status.Phase is marked as Bound then // all the resources are created. err := waitForCVCBoundState(restoreObj.Spec.VolumeName, rOps.namespace, rOps.clientset) - if err != nil { - return err - } - return nil + return err } // getRestoreStatus returns the status of CStorRestore diff --git a/pkg/webhook/cspc_operations.go b/pkg/webhook/cspc_operations.go index 550e7c0c..10c115e8 100644 --- a/pkg/webhook/cspc_operations.go +++ b/pkg/webhook/cspc_operations.go @@ -449,10 +449,7 @@ func (pOps *PoolOperations) createBDC(newBD, oldBD string) error { return err } err = pOps.ClaimBD(bdObj, oldBD) - if err != nil { - return err - } - return nil + return err } func getBDOwnerReference(cspc *cstor.CStorPoolCluster) []metav1.OwnerReference { diff --git a/pkg/webhook/cvc.go b/pkg/webhook/cvc.go index 3400f4b1..27537e0b 100644 --- a/pkg/webhook/cvc.go +++ b/pkg/webhook/cvc.go @@ -91,10 +91,7 @@ func validateCVCSpecChanges(cvcOldObj, cvcNewObj *cstor.CStorVolumeConfig) error // Below validations should be done only with new CVC object err := validatePoolNames(cvcNewObj) - if err != nil { - return err - } - return nil + return err } // TODO: isScalingInProgress(cvcObj *cstor.CStorVolumeConfig) signature need to be From dba5ce56ec9762783807c2934f89188e8be9ac5a Mon Sep 17 00:00:00 2001 From: aSquare14 Date: Tue, 4 May 2021 19:13:24 +0530 Subject: [PATCH 3/4] removed some more checks Signed-off-by: aSquare14 --- pkg/controllers/cspc-controller/scale.go | 12 ++++-------- pkg/controllers/cspc-controller/sync.go | 5 +---- pkg/controllers/cspi-controller/handler_test.go | 6 ++---- pkg/controllers/cstorvolumeconfig/controller.go | 6 ++---- 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/pkg/controllers/cspc-controller/scale.go b/pkg/controllers/cspc-controller/scale.go index 7c8bdca0..5ab94153 100644 --- a/pkg/controllers/cspc-controller/scale.go +++ b/pkg/controllers/cspc-controller/scale.go @@ -68,10 +68,8 @@ func (pc *PoolConfig) CreateCSPI(cspc *cstor.CStorPoolCluster) error { return err } err = pc.CreateCSPIDeployment(cspc, cspi) - if err != nil { - return err - } - return nil + + return err } func (pc *PoolConfig) createDeployForCSPList(cspc *cstor.CStorPoolCluster, cspList []cstor.CStorPoolInstance) { @@ -90,10 +88,8 @@ func (pc *PoolConfig) createDeployForCSPList(cspc *cstor.CStorPoolCluster, cspLi func (pc *PoolConfig) CreateCSPIDeployment(cspc *cstor.CStorPoolCluster, cspi *cstor.CStorPoolInstance) error { deploy := pc.AlgorithmConfig.GetPoolDeploySpec(cspi) _, err := pc.Controller.kubeclientset.AppsV1().Deployments(cspi.Namespace).Create(context.TODO(), deploy, metav1.CreateOptions{}) - if err != nil { - return err - } - return nil + + return err } // DownScalePool deletes the required pool. diff --git a/pkg/controllers/cspc-controller/sync.go b/pkg/controllers/cspc-controller/sync.go index 6f4cdb07..a10d8ee0 100644 --- a/pkg/controllers/cspc-controller/sync.go +++ b/pkg/controllers/cspc-controller/sync.go @@ -497,11 +497,8 @@ func (pc *PoolConfig) syncCSPIWithCSPC(cspc *cstor.CStorPoolCluster, cspi *cstor return err } err = pc.patchPoolDeploymentSpec(gotCSPI) - if err != nil { - return err - } - return nil + return err } /* diff --git a/pkg/controllers/cspi-controller/handler_test.go b/pkg/controllers/cspi-controller/handler_test.go index 0997368d..c17cf977 100644 --- a/pkg/controllers/cspi-controller/handler_test.go +++ b/pkg/controllers/cspi-controller/handler_test.go @@ -429,10 +429,8 @@ func (f *fixture) updateCSPIToPerformDay2Operation(cspiName string, tConfig test } } _, err = f.openebsClient.CstorV1().CStorPoolInstances(ns).Update(context.TODO(), cspiObj, metav1.UpdateOptions{}) - if err != nil { - return err - } - return nil + + return err } func (f *fixture) run(cspiName string) { diff --git a/pkg/controllers/cstorvolumeconfig/controller.go b/pkg/controllers/cstorvolumeconfig/controller.go index 916c1abb..81dc3ed7 100644 --- a/pkg/controllers/cstorvolumeconfig/controller.go +++ b/pkg/controllers/cstorvolumeconfig/controller.go @@ -504,10 +504,8 @@ func (c *CVCController) distributePendingCVRs( return err } err = c.distributeCVRs(pendingReplicaCount, cvc, service, cv, policy) - if err != nil { - return err - } - return nil + + return err } // isClaimDeletionCandidate checks if a cstorvolumeconfig is a deletion candidate. From 3e61049104cb7848f3abc3cb5bedf089da6d5293 Mon Sep 17 00:00:00 2001 From: aSquare14 Date: Tue, 4 May 2021 19:20:31 +0530 Subject: [PATCH 4/4] move shebang to first line Signed-off-by: aSquare14 --- ci/sanity/sanity.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ci/sanity/sanity.sh b/ci/sanity/sanity.sh index 13a1ab14..6f4f7f0c 100755 --- a/ci/sanity/sanity.sh +++ b/ci/sanity/sanity.sh @@ -1,3 +1,4 @@ +#!/usr/bin/env bash # Copyright © 2020 The OpenEBS Authors # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,8 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -#!/usr/bin/env bash - function IsPoolHealthy() { MAX_RETRY=$1 for i in $(seq 1 $MAX_RETRY) ; do