From 9bc25c8484b635489763285a32e8f7e5d67344b0 Mon Sep 17 00:00:00 2001 From: shubham Date: Mon, 30 Nov 2020 17:59:46 +0530 Subject: [PATCH 1/3] fix(cspc): cleanup pending bdcs on cspc deletion Signed-off-by: shubham --- pkg/controllers/cspc-controller/sync.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pkg/controllers/cspc-controller/sync.go b/pkg/controllers/cspc-controller/sync.go index 774a353c..65b0bd12 100644 --- a/pkg/controllers/cspc-controller/sync.go +++ b/pkg/controllers/cspc-controller/sync.go @@ -25,6 +25,7 @@ import ( cstor "github.com/openebs/api/v2/pkg/apis/cstor/v1" "github.com/openebs/api/v2/pkg/apis/types" clientset "github.com/openebs/api/v2/pkg/client/clientset/versioned" + "github.com/openebs/api/v2/pkg/util" "github.com/openebs/cstor-operators/pkg/cspc/algorithm" "github.com/openebs/cstor-operators/pkg/version" "github.com/pkg/errors" @@ -261,6 +262,25 @@ func (c *Controller) removeCSPCFinalizer(cspc *cstor.CStorPoolCluster) error { "CSPI(s) still exists for CSPC") } + // If the BD(s) are claimed and the CSPI(s) do not spawn up for some reason, + // the pending BDC(s) finalizer don't get removed automatically. + // The below code handles cleanup for such cases. + bdcList, err := c.GetStoredOpenebsVersionClient().BlockDeviceClaims(cspc.Namespace).List( + metav1.ListOptions{ + LabelSelector: string(types.CStorPoolClusterLabelKey) + "=" + cspc.Name, + }, + ) + + for _, bdcItem := range bdcList.Items { + bdcItem := bdcItem // pin it + bdcObj := &bdcItem + bdcObj.Finalizers = util.RemoveString(bdcObj.Finalizers, types.CSPCFinalizer) + bdcObj, err = c.GetStoredOpenebsVersionClient().BlockDeviceClaims(cspc.Namespace).Update(bdcObj) + if err != nil { + return errors.Wrapf(err, "failed to remove finalizers from bdc %s", bdcItem.Name) + } + } + cspc.RemoveFinalizer(types.CSPCFinalizer) _, err = c.GetStoredCStorVersionClient().CStorPoolClusters(cspc.Namespace).Update(cspc) From 05dfc8151f35688365397f12013d4e84d654134b Mon Sep 17 00:00:00 2001 From: shubham Date: Tue, 1 Dec 2020 12:10:29 +0530 Subject: [PATCH 2/3] fix error handling Signed-off-by: shubham --- pkg/controllers/cspc-controller/sync.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/controllers/cspc-controller/sync.go b/pkg/controllers/cspc-controller/sync.go index 65b0bd12..f5e15722 100644 --- a/pkg/controllers/cspc-controller/sync.go +++ b/pkg/controllers/cspc-controller/sync.go @@ -270,7 +270,9 @@ func (c *Controller) removeCSPCFinalizer(cspc *cstor.CStorPoolCluster) error { LabelSelector: string(types.CStorPoolClusterLabelKey) + "=" + cspc.Name, }, ) - + if err != nil { + return err + } for _, bdcItem := range bdcList.Items { bdcItem := bdcItem // pin it bdcObj := &bdcItem From 26a3f729d7571c1b5191d17dd7f7cb1de94ba2db Mon Sep 17 00:00:00 2001 From: shubham Date: Wed, 2 Dec 2020 18:20:23 +0530 Subject: [PATCH 3/3] added changelog Signed-off-by: shubham --- changelogs/unreleased/210-shubham14bajpai | 1 + pkg/version/util.go | 1 + 2 files changed, 2 insertions(+) create mode 100644 changelogs/unreleased/210-shubham14bajpai diff --git a/changelogs/unreleased/210-shubham14bajpai b/changelogs/unreleased/210-shubham14bajpai new file mode 100644 index 00000000..b3e4fe0e --- /dev/null +++ b/changelogs/unreleased/210-shubham14bajpai @@ -0,0 +1 @@ +fix(cspc): cleanup pending bdcs on cspc deletion diff --git a/pkg/version/util.go b/pkg/version/util.go index 48bff683..eaec8d7a 100644 --- a/pkg/version/util.go +++ b/pkg/version/util.go @@ -22,6 +22,7 @@ var ( validCurrentVersions = map[string]bool{ "1.10.0": true, "1.11.0": true, "1.12.0": true, "2.0.0": true, "2.1.0": true, "2.2.0": true, "2.3.0": true, + "2.4.0": true, } validDesiredVersion = strings.Split(GetVersion(), "-")[0] )