Skip to content

Commit

Permalink
refact(cspc): add migration support for spc to cspc (#79)
Browse files Browse the repository at this point in the history
Signed-off-by: shubham <[email protected]>
  • Loading branch information
shubham14bajpai authored Jun 2, 2020
1 parent 3773fc4 commit c828979
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 9 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.10.0
1.11.0
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ bitbucket.org/bertimus9/systemstat v0.0.0-20180207000608-0eeff89b0690/go.mod h1:
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
github.com/Azure/azure-sdk-for-go v35.0.0+incompatible h1:PkmdmQUmeSdQQ5258f4SyCf2Zcz0w67qztEg37cOR7U=
github.com/Azure/azure-sdk-for-go v35.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
github.com/Azure/go-autorest/autorest v0.9.0/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI=
Expand Down Expand Up @@ -269,6 +270,7 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ=
github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU=
github.com/jimstudt/http-authentication v0.0.0-20140401203705-3eca13d6893a/go.mod h1:wK6yTYYcgjHE1Z1QtXACPDjcFJyBskHEdagmnq3vsP8=
Expand Down Expand Up @@ -438,6 +440,7 @@ github.com/spf13/cast v1.2.0/go.mod h1:r2rcYCSwa1IExKTDiTfzaxqT2FNHs8hODu4LnUfgK
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v0.0.2/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s=
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
github.com/spf13/jwalterweatherman v0.0.0-20180109140146-7c0cea34c8ec/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
Expand Down Expand Up @@ -647,6 +650,7 @@ google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873 h1:nfPFGzJkUDX6uBmpN/pSw7MbOAWegH5QDQuoXFHedLg=
google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
Expand Down
7 changes: 7 additions & 0 deletions pkg/cspc/algorithm/build_csp.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ func (ac *Config) GetCSPISpec() (*cstor.CStorPoolInstance, error) {
WithFinalizer(types.CSPCFinalizer).
WithNewVersion(version.GetVersion()).
WithDependentsUpgraded()
// check for OpenEBSDisableDependantsReconcileKey annotation which implies
// the CSPI should have OpenEBSDisableReconcileLabelKey enabled
if ac.CSPC.GetAnnotations()[types.OpenEBSDisableDependantsReconcileKey] == "true" {
cspiObj.WithAnnotations(map[string]string{
types.OpenEBSDisableReconcileLabelKey: "true",
})
}

err = ac.ClaimBDsForNode(GetBDListForNode(*poolSpec))
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/pool/operations/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ func (oc *OperationsConfig) Create(cspi *cstor.CStorPoolInstance) error {

// Let's check if there is any disk having the pool config
// If so then we will not create the pool
ret, notImported, err := oc.checkIfPoolNotImported(cspi)
ret, notImported, err := oc.checkIfPoolIsImportable(cspi)
if err != nil {
return errors.Errorf("Failed to check not imported pool %s", err.Error())
return errors.Errorf("failed to verify if pool is importable: %s", err.Error())
}
if notImported {
return errors.Errorf("Pool {%s} is in faulty state.. %s", PoolName(), ret)
Expand Down
43 changes: 38 additions & 5 deletions pkg/pool/operations/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/openebs/cstor-operators/pkg/pool"
"github.com/openebs/cstor-operators/pkg/volumereplica"
zfs "github.com/openebs/cstor-operators/pkg/zcmd"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
"k8s.io/klog"
)
Expand All @@ -36,14 +37,33 @@ import (
// - If any error occurred during import operation
func (oc *OperationsConfig) Import(cspi *cstor.CStorPoolInstance) (bool, error) {
if poolExist := checkIfPoolPresent(PoolName(), oc.zcmdExecutor); poolExist {
// If the pool is renamed and imported but the pool-mgmt restarts
// for some reason then the annotation should be removed.
delete(cspi.Annotations, types.OpenEBSCStorExistingPoolName)
return true, nil
}

var poolImported, importable bool
var err error
// existingPoolName denotes the pool name that may be present
// from previous version and needs to be imported with new name
existingPoolName := cspi.Annotations[types.OpenEBSCStorExistingPoolName]
if existingPoolName != "" {
_, importable, err = oc.checkIfPoolIsImportable(cspi)
if err != nil {
return false, errors.Errorf("failed to verify if pool is importable: %s", err.Error())
}
if importable {
// If the pool is renamed but not imported, remove the
// annotation to avoid not found errors.
existingPoolName = ""
delete(cspi.Annotations, types.OpenEBSCStorExistingPoolName)
}
}

// Pool is not imported.. Let's update the syncResource
var cmdOut []byte
var err error
common.SyncResources.IsImported = false
var poolImported bool

bdPath, err := oc.getPathForBDev(cspi.Spec.DataRaidGroups[0].CStorPoolInstanceBlockDevices[0].BlockDeviceName)
if err != nil {
Expand All @@ -54,12 +74,17 @@ func (oc *OperationsConfig) Import(cspi *cstor.CStorPoolInstance) (bool, error)
devID := pool.GetDevPathIfNotSlashDev(bdPath[0])
cacheFile := types.CStorPoolBasePath + types.CacheFileName

if existingPoolName != "" {
klog.Infof("Renaming pool %s to %s", existingPoolName, PoolName())
}
// Import the pool using cachefile
// command will looks like: zpool import -c <cachefile_path> -o <cachefile_path> <pool_name>
// command will look like: zpool import -c <cachefile_path> -o <cachefile_path> <pool_name>
// if existing pool name is present: zpool import -c <cachefile_path> -o <cachefile_path> <existing_pool_name> <pool_name>
cmdOut, err = zfs.NewPoolImport().
WithCachefile(cacheFile).
WithProperty("cachefile", cacheFile).
WithPool(PoolName()).
WithPool(existingPoolName).
WithNewPool(PoolName()).
WithExecutor(oc.zcmdExecutor).
Execute()
if err == nil {
Expand All @@ -72,11 +97,14 @@ func (oc *OperationsConfig) Import(cspi *cstor.CStorPoolInstance) (bool, error)
if !poolImported {
// Import the pool without cachefile by scanning the directory
// For sparse based pools import command: zpool import -d <parent_dir_sparse_files> -o <cachefile_path> <pool_name>
// if existing pool name is present: zpool import -d <parent_dir_sparse_files> -o <cachefile_path> <existing_pool_name> <pool_name>
// For device based pools import command: zpool import -o <cachefile_path> <pool_name>(by default it will scan /dev directory)
// if existing pool name is present: zpool import -o <cachefile_path> <existing_pool_name> <pool_name>(by default it will scan /dev directory)
cmdOut, err = zfs.NewPoolImport().
WithDirectory(devID).
WithProperty("cachefile", cacheFile).
WithPool(PoolName()).
WithPool(existingPoolName).
WithNewPool(PoolName()).
WithExecutor(oc.zcmdExecutor).
Execute()
}
Expand All @@ -87,6 +115,11 @@ func (oc *OperationsConfig) Import(cspi *cstor.CStorPoolInstance) (bool, error)
return false, err
}

// after successful import of pool the annotation needs to be deleted
// to avoid renaming of pool that is already renamed which will cause
// pool not found errors
delete(cspi.Annotations, types.OpenEBSCStorExistingPoolName)

common.SyncResources.IsImported = true
oc.recorder.Event(cspi,
corev1.EventTypeNormal,
Expand Down
5 changes: 4 additions & 1 deletion pkg/pool/operations/pool_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ func checkIfDeviceUsed(path []string, t zpool.Topology) (string, bool) {
return usedPath, isUsed
}

func (oc *OperationsConfig) checkIfPoolNotImported(cspi *cstor.CStorPoolInstance) (string, bool, error) {
// checkIfPoolIsImportable checks if the pool is imported or not. If the pool
// is present on the disk but not imported it returns true as the pool can be
// imported. It also returns false if pool is not found on the disk.
func (oc *OperationsConfig) checkIfPoolIsImportable(cspi *cstor.CStorPoolInstance) (string, bool, error) {
var cmdOut []byte
var err error

Expand Down

0 comments on commit c828979

Please sign in to comment.