Skip to content

Commit

Permalink
fix linting issues
Browse files Browse the repository at this point in the history
Signed-off-by: shubham <[email protected]>
  • Loading branch information
shubham14bajpai committed Nov 28, 2019
1 parent 0e14d17 commit 160c699
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
4 changes: 1 addition & 3 deletions cmd/migrate/executor/setup_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
}
35 changes: 20 additions & 15 deletions pkg/cstor/migrate/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)] {
Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}

Expand All @@ -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).
Expand Down Expand Up @@ -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 {
Expand All @@ -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")
Expand All @@ -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
}
Expand Down

0 comments on commit 160c699

Please sign in to comment.