Skip to content

Commit

Permalink
fix scale down of deploy and cleanup of csp
Browse files Browse the repository at this point in the history
Signed-off-by: shubham <[email protected]>
  • Loading branch information
shubham14bajpai committed May 24, 2020
1 parent 29e5e7f commit 7a64b26
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 5 deletions.
42 changes: 42 additions & 0 deletions pkg/migrate/cstor/helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright 2020 The OpenEBS Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package migrate

import (
"encoding/json"
"fmt"

"k8s.io/apimachinery/pkg/util/strategicpatch"
)

// GetPatchData returns patch data by
// marshalling and taking diff of two objects
func GetPatchData(oldObj, newObj interface{}) ([]byte, error) {
oldData, err := json.Marshal(oldObj)
if err != nil {
return nil, fmt.Errorf("marshal old object failed: %v", err)
}
newData, err := json.Marshal(newObj)
if err != nil {
return nil, fmt.Errorf("mashal new object failed: %v", err)
}
patchBytes, err := strategicpatch.CreateTwoWayMergePatch(oldData, newData, oldObj)
if err != nil {
return nil, fmt.Errorf("CreateTwoWayMergePatch failed: %v", err)
}
return patchBytes, nil
}
30 changes: 25 additions & 5 deletions pkg/migrate/cstor/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,25 @@ func (c *CSPCMigrator) csptocspi(
if err != nil {
return err
}
return nil
// remove the finalizers from csp object for cleanup
// as pool pod is no longer running to remove them.
return removeCSPFinalizers(cspObj)
}

func removeCSPFinalizers(cspObj *apis.CStorPool) error {
cspClient := csp.KubeClient()
newCSP := cspObj.DeepCopy()
newCSP.Finalizers = []string{}
patchData, err := GetPatchData(cspObj, newCSP)
if err != nil {
return err
}
_, err = cspClient.Patch(
cspObj.Name,
k8stypes.MergePatchType,
patchData,
)
return err
}

// get csp for cspi on the basis of cspLabel, which is the combination of
Expand Down Expand Up @@ -304,13 +322,15 @@ func (c *CSPCMigrator) scaleDownDeployment(cspObj *apis.CStorPool, openebsNamesp
Times(60).
Wait(5 * time.Second).
Try(func(attempt uint) error {
cspDeploy, err1 := c.KubeClientset.AppsV1().
Deployments(openebsNamespace).
Get(cspDeployList.Items[0].Name, metav1.GetOptions{})
cspPods, err1 := c.KubeClientset.CoreV1().
Pods(openebsNamespace).
List(metav1.ListOptions{
LabelSelector: "openebs.io/cstor-pool=" + cspObj.Name,
})
if err1 != nil {
return errors.Wrapf(err1, "failed to get csp deploy")
}
if cspDeploy.Status.ReadyReplicas != 0 {
if len(cspPods.Items) != 0 {
return errors.Errorf("failed to scale down csp deployment")
}
return nil
Expand Down

0 comments on commit 7a64b26

Please sign in to comment.