diff --git a/cmd/cspi-mgmt/app/handler.go b/cmd/cspi-mgmt/app/handler.go index 8ef6d39832..5211860fd0 100644 --- a/cmd/cspi-mgmt/app/handler.go +++ b/cmd/cspi-mgmt/app/handler.go @@ -59,8 +59,8 @@ func (c *CStorPoolInstanceController) reconcile(key string) error { common.SyncResources.Mux.Lock() // try to import pool - if cspi.Annotations["cspuid"] != "" { - isImported, err = zpool.Import(cspi, "cstor-"+cspi.Annotations["cspuid"]) + if cspi.Annotations[string(apis.OldCSPUID)] != "" { + isImported, err = zpool.Import(cspi, "cstor-"+cspi.Annotations[string(apis.OldCSPUID)]) } else { isImported, err = zpool.Import(cspi, "") } @@ -75,7 +75,7 @@ func (c *CStorPoolInstanceController) reconcile(key string) error { } zpool.CheckImportedPoolVolume() common.SyncResources.Mux.Unlock() - delete(cspi.Annotations, "cspuid") + delete(cspi.Annotations, string(apis.OldCSPUID)) err = c.update(cspi) if err != nil { c.recorder.Event(cspi, diff --git a/pkg/algorithm/nodeselect/v1alpha2/build_csp.go b/pkg/algorithm/nodeselect/v1alpha2/build_csp.go index cdbf774078..f9d6f9f839 100644 --- a/pkg/algorithm/nodeselect/v1alpha2/build_csp.go +++ b/pkg/algorithm/nodeselect/v1alpha2/build_csp.go @@ -63,12 +63,12 @@ func (ac *Config) GetCSPSpec() (*apis.CStorPoolInstance, error) { annotations := map[string]string{} - if ac.CSPC.GetAnnotations()["reconcile.openebs.io/dependants"] == "false" { + if ac.CSPC.GetAnnotations()[string(apis.OpenEBSDisableDependantsReconcileKey)] == "false" { annotations[string(apis.OpenEBSDisableReconcileKey)] = "true" } if poolSpec.OldCSPUID != "" { - annotations["cspuid"] = poolSpec.OldCSPUID + annotations[string(apis.OldCSPUID)] = poolSpec.OldCSPUID } if len(annotations) != 0 { diff --git a/pkg/apis/openebs.io/v1alpha1/cas_keys.go b/pkg/apis/openebs.io/v1alpha1/cas_keys.go index 75a7133123..677ad69f86 100644 --- a/pkg/apis/openebs.io/v1alpha1/cas_keys.go +++ b/pkg/apis/openebs.io/v1alpha1/cas_keys.go @@ -48,6 +48,10 @@ const ( // OpenEBSDisableReconcileKey is the label key decides to reconcile or not OpenEBSDisableReconcileKey CASKey = "reconcile.openebs.io/disable" + // OpenEBSDisableDependantsReconcileKey is the annotation key that decides to create + // children objects with OpenEBSDisableReconcileKey as true or false + OpenEBSDisableDependantsReconcileKey CASKey = "reconcile.openebs.io/dependants" + // CASConfigKey is the key to fetch configurations w.r.t a CAS entity CASConfigKey CASKey = "cas.openebs.io/config" diff --git a/pkg/apis/openebs.io/v1alpha1/cas_pool.go b/pkg/apis/openebs.io/v1alpha1/cas_pool.go index 5cc8c34404..bd97f1d5c0 100644 --- a/pkg/apis/openebs.io/v1alpha1/cas_pool.go +++ b/pkg/apis/openebs.io/v1alpha1/cas_pool.go @@ -63,6 +63,8 @@ const ( RaidzBlockDeviceCountCPV CasPoolValInt = 3 // Raidz2BlockDeviceCountCPV is the count for raidz2 type pool Raidz2BlockDeviceCountCPV CasPoolValInt = 6 + // OldCSPUID is the uid of the csp that is being migrated to cspi + OldCSPUID CasPoolKey = "cspuid" ) // CasPool is a type which will be utilised by CAS engine to perform diff --git a/pkg/cstor/migrate/cspc_generator.go b/pkg/cstor/migrate/cspc_generator.go index 77173538a3..fcb80f8499 100644 --- a/pkg/cstor/migrate/cspc_generator.go +++ b/pkg/cstor/migrate/cspc_generator.go @@ -63,7 +63,7 @@ func getCSPCSpec(spc *apis.StoragePoolClaim) (*apis.CStorPoolCluster, error) { cspcObj.Annotations = map[string]string{ // This label will be used to disable reconciliation on the dependants // In this case that will be CSPI - "reconcile.openebs.io/dependants": "false", + string(apis.OpenEBSDisableDependantsReconcileKey): "false", } for _, cspObj := range cspList.Items { cspcObj.Spec.Pools = append(cspcObj.Spec.Pools, @@ -137,7 +137,7 @@ func generateCSPC(spcObj *apis.StoragePoolClaim, openebsNamespace string) ( if err != nil { return nil, err } - delete(cspcObj.Annotations, "reconcile.openebs.io/dependants") + delete(cspcObj.Annotations, string(apis.OpenEBSDisableDependantsReconcileKey)) cspcObj, err = cspc.NewKubeClient(). WithNamespace(openebsNamespace). Update(cspcObj) diff --git a/pkg/cstor/migrate/pool.go b/pkg/cstor/migrate/pool.go index 325e6ea6f3..7c5769045a 100644 --- a/pkg/cstor/migrate/pool.go +++ b/pkg/cstor/migrate/pool.go @@ -39,11 +39,21 @@ import ( types "k8s.io/apimachinery/pkg/types" ) -const replicaPatch = `{ +const ( + replicaPatch = `{ "spec": { "replicas": 0 } }` + cspNameLabel = "openebs.io/cstor-pool" + cspUIDLabel = "cstorpool.openebs.io/uid" + cspHostnameAnnotation = "cstorpool.openebs.io/hostname" + cspiNameLabel = "cstorpoolinstance.openebs.io/name" + cspiUIDLabel = "cstorpoolinstance.openebs.io/uid" + cspiHostnameAnnotation = "cstorpoolinstance.openebs.io/hostname" + spcFinalizer = "storagepoolclaim.openebs.io/finalizer" + cspcFinalizer = "cstorpoolcluster.openebs.io/finalizer" +) // Pool ... func Pool(spcName, openebsNamespace string) error { @@ -234,8 +244,8 @@ func updateBDC(bdName apis.CspBlockDevice, cspcObj *apis.CStorPoolCluster, opene delete(bdcObj.Labels, string(apis.StoragePoolClaimCPK)) bdcObj.Labels[string(apis.CStorPoolClusterCPK)] = cspcObj.Name for i, finalizer := range bdcObj.Finalizers { - if finalizer == "storagepoolclaim.openebs.io/finalizer" { - bdcObj.Finalizers[i] = "cstorpoolcluster.openebs.io/finalizer" + if finalizer == spcFinalizer { + bdcObj.Finalizers[i] = cspcFinalizer } } bdcObj.OwnerReferences[0].Kind = "CStorPoolCluster" @@ -252,19 +262,19 @@ func updateBDC(bdName apis.CspBlockDevice, cspcObj *apis.CStorPoolCluster, opene func updateCVRsLabels(cspName, openebsNamespace string, cspiObj *apis.CStorPoolInstance) error { cvrList, err := cvr.NewKubeclient(). WithNamespace(openebsNamespace).List(metav1.ListOptions{ - LabelSelector: "cstorpool.openebs.io/name=" + cspName, + LabelSelector: cspNameLabel + "=" + cspName, }) if err != nil { return err } for _, cvrObj := range cvrList.Items { 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") - cvrObj.Labels["cstorpoolinstance.openebs.io/name"] = cspiObj.Name - cvrObj.Labels["cstorpoolinstance.openebs.io/uid"] = string(cspiObj.UID) - delete(cvrObj.Annotations, "cstorpool.openebs.io/hostname") - cvrObj.Annotations["cstorpoolinstance.openebs.io/hostname"] = cspiObj.Spec.HostName + delete(cvrObj.Labels, cspNameLabel) + delete(cvrObj.Labels, cspUIDLabel) + cvrObj.Labels[cspiNameLabel] = cspiObj.Name + cvrObj.Labels[cspiUIDLabel] = string(cspiObj.UID) + delete(cvrObj.Annotations, cspHostnameAnnotation) + cvrObj.Annotations[cspiHostnameAnnotation] = cspiObj.Spec.HostName _, err = cvr.NewKubeclient().WithNamespace(openebsNamespace). Update(&cvrObj) if err != nil {