From 160c69988b6a7aa55eb5e26563809c2b173dddbf Mon Sep 17 00:00:00 2001 From: shubham Date: Thu, 28 Nov 2019 16:56:10 +0530 Subject: [PATCH] fix linting issues Signed-off-by: shubham --- cmd/migrate/executor/setup_job.go | 4 +--- pkg/cstor/migrate/migration.go | 35 ++++++++++++++++++------------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/cmd/migrate/executor/setup_job.go b/cmd/migrate/executor/setup_job.go index 52a0edd1c6..dccb58216d 100644 --- a/cmd/migrate/executor/setup_job.go +++ b/cmd/migrate/executor/setup_job.go @@ -27,8 +27,6 @@ import ( "github.com/spf13/cobra" ) -var spcName, openebsNamespace string - // NewJob will setup a new migrate job func NewJob() *cobra.Command { // Create a new command. @@ -61,6 +59,6 @@ func NewJob() *cobra.Command { func PreRun(cmd *cobra.Command, args []string) { namespace := getOpenEBSNamespace() if len(strings.TrimSpace(namespace)) != 0 { - openebsNamespace = namespace + options.openebsNamespace = namespace } } diff --git a/pkg/cstor/migrate/migration.go b/pkg/cstor/migrate/migration.go index ebdc74418e..e7f4507115 100644 --- a/pkg/cstor/migrate/migration.go +++ b/pkg/cstor/migrate/migration.go @@ -52,7 +52,7 @@ func Pool(spcName, openebsNamespace string) error { Get(spcName, metav1.GetOptions{}) if k8serrors.IsNotFound(err) { klog.Infof("spc %s not found.", spcName) - _, err := cspc.NewKubeClient(). + _, err = cspc.NewKubeClient(). WithNamespace(openebsNamespace).Get(spcName, metav1.GetOptions{}) if err != nil { return errors.Wrapf(err, "failed to get equivalent cspc for spc %s", spcName) @@ -79,13 +79,17 @@ func Pool(spcName, openebsNamespace string) error { } for _, cspiObj := range cspiList.Items { + cspiObj := &cspiObj if cspiObj.Status.Phase != "ONLINE" { - err = csptocspi(&cspiObj, cspcObj, openebsNamespace) + err = csptocspi(cspiObj, cspcObj, openebsNamespace) if err != nil { return err } cspcObj, err = cspc.NewKubeClient(). WithNamespace(openebsNamespace).Get(cspcObj.Name, metav1.GetOptions{}) + if err != nil { + return err + } for i, poolspec := range cspcObj.Spec.Pools { if poolspec.NodeSelector[string(apis.HostNameCPK)] == cspiObj.Labels[string(apis.HostNameCPK)] { @@ -111,7 +115,7 @@ func csptocspi(cspiObj *apis.CStorPoolInstance, cspcObj *apis.CStorPoolCluster, hostnameLabel := string(apis.HostNameCPK) + "=" + cspiObj.Labels[string(apis.HostNameCPK)] spcLabel := string(apis.StoragePoolClaimCPK) + "=" + cspcObj.Name cspLabel := hostnameLabel + "," + spcLabel - + var err1 error cspObj, err := getCSP(cspLabel) if err != nil { return err @@ -138,7 +142,7 @@ func csptocspi(cspiObj *apis.CStorPoolInstance, cspcObj *apis.CStorPoolCluster, Times(60). Wait(5 * time.Second). Try(func(attempt uint) error { - cspiObj, err1 := cspi.NewKubeClient(). + cspiObj, err1 = cspi.NewKubeClient(). WithNamespace(openebsNamespace). Get(cspiObj.Name, metav1.GetOptions{}) if err1 != nil { @@ -172,9 +176,6 @@ func getCSP(cspLabel string) (*apis.CStorPool, error) { return nil, fmt.Errorf("Invalid number of pools on one node: %d", len(cspList.Items)) } cspObj := cspList.Items[0] - if err != nil { - return nil, err - } return &cspObj, nil } @@ -188,12 +189,15 @@ func scaleDownDeployment(cspObj *apis.CStorPool, openebsNamespace string) error if err != nil { return err } - _, err = deploy.NewKubeClient(). - WithNamespace(openebsNamespace).Patch( - cspObj.Name, - types.StrategicMergePatchType, - []byte(replicaPatch), - ) + _, err = deploy.NewKubeClient().WithNamespace(openebsNamespace). + Patch( + cspObj.Name, + types.StrategicMergePatchType, + []byte(replicaPatch), + ) + if err != nil { + return err + } err = retry. Times(60). Wait(5 * time.Second). @@ -235,7 +239,7 @@ func updateBDC(bdName apis.CspBlockDevice, cspcObj *apis.CStorPoolCluster, opene } bdcObj.OwnerReferences[0].Kind = "CStorPoolCluster" bdcObj.OwnerReferences[0].UID = cspcObj.UID - bdcObj, err = bdc.NewKubeClient(). + _, err = bdc.NewKubeClient(). WithNamespace(openebsNamespace). Update(bdcObj) if err != nil { @@ -253,6 +257,7 @@ func updateCVRsLabels(cspName, openebsNamespace string, cspiObj *apis.CStorPoolI return err } for _, cvrObj := range cvrList.Items { + cvrObj := &cvrObj klog.Infof("Updating cvr %s with cspi %s info.", cvrObj.Name, cspiObj.Name) delete(cvrObj.Labels, "cstorpool.openebs.io/name") delete(cvrObj.Labels, "cstorpool.openebs.io/uid") @@ -261,7 +266,7 @@ func updateCVRsLabels(cspName, openebsNamespace string, cspiObj *apis.CStorPoolI delete(cvrObj.Annotations, "cstorpool.openebs.io/hostname") cvrObj.Annotations["cstorpoolinstance.openebs.io/hostname"] = cspiObj.Spec.HostName _, err = cvr.NewKubeclient().WithNamespace(openebsNamespace). - Update(&cvrObj) + Update(cvrObj) if err != nil { return err }