Skip to content

Commit

Permalink
took cv from openebs namespace, updated single cv status
Browse files Browse the repository at this point in the history
Signed-off-by: Rupank Pahuja  <[email protected]>
Signed-off-by: Rupank Pahuja <[email protected]>
  • Loading branch information
Rupank Pahuja committed Oct 11, 2021
1 parent 2a10af3 commit 0a25441
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/imdario/mergo v0.3.8 // indirect
github.com/onsi/ginkgo v1.12.0
github.com/onsi/gomega v1.9.0
github.com/openebs/api/v2 v2.2.1-0.20210302070038-f282f96d77c6
github.com/openebs/api/v2 v2.4.0
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1Cpa
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.9.0 h1:R1uwffexN6Pr340GtYRIdZmAiN4J+iw6WG4wog1DUXg=
github.com/onsi/gomega v1.9.0/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA=
github.com/openebs/api/v2 v2.2.1-0.20210302070038-f282f96d77c6 h1:P+gwyB2xycGJrxJoyG4SdnOC5cZwcaYRiHmCxL1a6bw=
github.com/openebs/api/v2 v2.2.1-0.20210302070038-f282f96d77c6/go.mod h1:nLCaNvVjgjkjeD2a+n1fMbv5HjoEYP4XB8OAbwmIXtY=
github.com/openebs/api/v2 v2.4.0 h1:MiDyuNe1TnwskN+1JAQr5DoiI/IWxbgljKg7ssGPIjg=
github.com/openebs/api/v2 v2.4.0/go.mod h1:nLCaNvVjgjkjeD2a+n1fMbv5HjoEYP4XB8OAbwmIXtY=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down
29 changes: 12 additions & 17 deletions pkg/controllers/volume-mgmt/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"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/controllers/common"
"github.com/openebs/cstor-operators/pkg/controllers/volume-mgmt/volume"
"github.com/openebs/cstor-operators/pkg/version"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -762,31 +761,27 @@ func (c *CStorVolumeController) reconcileVersion(cv *apis.CStorVolume) (*apis.CS
// markCVStatusToOffline will fetch all the CV resources present
// in etcd and mark it them CV.Status to Offline
func (c *CStorVolumeController) markCVStatusToOffline() {

cvList, err := c.clientset.CstorV1().CStorVolumes("").List(context.TODO(), metav1.ListOptions{})
openebsNameSpace := os.Getenv("OPENEBS_NAMESPACE")
cvList, err := c.clientset.CstorV1().CStorVolumes(openebsNameSpace).List(context.TODO(), metav1.ListOptions{})
if err != nil {
klog.Errorf("failed to fetch CV list, error: %v", err)
return
}
cvID := os.Getenv(string(common.OpenEBSIOCSPIID))
for _, cv := range cvList.Items {
cv := cv // pin it
if string(cv.GetUID()) == cvID {
// If target container restarts or pod is deleted
// before even creating a cvr, then we can skip those cvr
if cv.Status.Phase == "" || cv.Status.Phase == apis.CStorVolumePhase(apis.CVRStatusInit) {
continue
}
// No CstorVolume enum exist, hence wrapping cvr status
cv.Status.Phase = apis.CStorVolumePhase(apis.CVRStatusOffline)

// updating cv status to offline
// Checking if Valid Cstor
if IsValidCStorVolumeMgmt(&cv) {
cv.Status.Phase = apis.CVStatusOffline
cv.Status.ReplicaStatuses = nil

// updating cv status to offline
_, err = c.clientset.CstorV1().CStorVolumes(cv.Namespace).Update(context.TODO(), &cv, metav1.UpdateOptions{})
if err != nil {
klog.Errorf("failed to update CVR: %s status to %s", cv.Name, apis.CVRStatusOffline)
klog.Errorf("failed to update CV: %s status to %s", cv.Name, apis.CVStatusOffline)
continue
}
klog.Infof("status marked %s for CV: %s", apis.CStorVolumePhase(apis.CVRStatusOffline), cv.Name)
klog.Infof("status marked %s for CV: %s", apis.CVStatusOffline, cv.Name)
// as only one cv exists returning after updating cv status
return
}
}
}
2 changes: 1 addition & 1 deletion pkg/controllers/volume-mgmt/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (c *CStorVolumeController) Run(threadiness int, stopCh <-chan struct{}) err
// Similar as when pod is running and if you stopped kubelet it will make
// pod status unknown.
// NOTE: CV status will be updated to OFFLINE even cStor target
// container alone get restarted but in this case pool will be still in
// container alone get restarted but in this case, target(istgt) will be still in
// running state. This inconsistency will be resolved in subsequent reconciliations
c.markCVStatusToOffline()
klog.Info("Shutting down CStorVolume workers")
Expand Down

0 comments on commit 0a25441

Please sign in to comment.