From 69346557fdbe2e6d2e5e1fc8ad69510a958ed6fb Mon Sep 17 00:00:00 2001 From: sai chaithanya Date: Wed, 20 May 2020 15:33:25 +0530 Subject: [PATCH] fix(cspi): import pool without cachefile (#77) (#78) This commits fixes a bug due to which pool import was failing in case of pool manager pod restarts. Signed-off-by: mittachaitu --- ci/sanity/sanity.sh | 17 ++++++++- go.mod | 2 +- go.sum | 11 +++++- pkg/pool/operations/import.go | 37 ++++++++++--------- .../api/pkg/apis/cstor/v1/cstorpoolcluster.go | 2 +- .../v1alpha1/blockdeviceclaimbuilder.go | 21 +++++++++++ .../openebs/api/pkg/apis/types/types.go | 2 +- vendor/modules.txt | 2 +- 8 files changed, 69 insertions(+), 25 deletions(-) diff --git a/ci/sanity/sanity.sh b/ci/sanity/sanity.sh index 5e369d76..38aaba98 100755 --- a/ci/sanity/sanity.sh +++ b/ci/sanity/sanity.sh @@ -113,10 +113,25 @@ kubectl apply -f ./ci/sanity/cspc.yaml IsPoolHealthy 30 +## Once the pool is healthy verify whether cachefile stored in persistent path +## Get the CSPC name +echo "Verifying whether pool cachefile is stored in persistent path" +cspcName=$(kubectl get cspc -n openebs -o=jsonpath={.items[0].metadata.name}) +if [ $? -ne 0 ]; then + echo "Failed to get CSPC name" + exit 1 +fi +## verify whether cache file present in persistent path +ls -lrth /var/openebs/cstor-pool/${cspcName}/pool.cache +if [ $? -ne 0 ]; then + echo "cache file is not present in persistent path" + exit 1 +fi + echo "Applying cstor-csi storage class" kubectl apply -f ./ci/artifacts/csi-storageclass.yaml echo "Deploying Busy-Box pod to use the cStor CSI volume..." kubectl apply -f ./ci/artifacts/busybox-csi-cstor-sparse.yaml IsPVCBound csi-claim 30 -IsPodRunning busybox 30 \ No newline at end of file +IsPodRunning busybox 30 diff --git a/go.mod b/go.mod index 39c88e38..ddc2ff49 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/imdario/mergo v0.3.8 // indirect github.com/onsi/ginkgo v1.12.0 // indirect github.com/onsi/gomega v1.9.0 // indirect - github.com/openebs/api v0.0.0-20200429072019-650209fba28b + github.com/openebs/api v1.10.1-0.20200519181449-902964f2beb0 github.com/pkg/errors v0.9.1 github.com/spf13/cobra v0.0.5 github.com/spf13/pflag v1.0.5 diff --git a/go.sum b/go.sum index 2aa19f3b..0ee3ad09 100644 --- a/go.sum +++ b/go.sum @@ -226,6 +226,7 @@ github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Z github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/cadvisor v0.35.0/go.mod h1:1nql6U13uTHaLYB8rLS5x9IJc2qT6Xd/Tr1sTX6NE48= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= @@ -278,6 +279,7 @@ github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22 github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.8 h1:QiWkFLKq0T7mpzwOTu6BzNDbfTE8OLrYhVKYMLF46Ok= github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= @@ -383,8 +385,10 @@ github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zM github.com/opencontainers/runc v1.0.0-rc9/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U= github.com/opencontainers/runtime-spec v1.0.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= github.com/opencontainers/selinux v1.3.1-0.20190929122143-5215b1806f52/go.mod h1:+BLncwf63G4dgOzykXAxcmnFlUaOlkDdmw/CqsW6pjs= -github.com/openebs/api v0.0.0-20200429072019-650209fba28b h1:XC6wCUascCjnEEstKkSFuEZB2YjTtm10Mx7SoRSHfhk= -github.com/openebs/api v0.0.0-20200429072019-650209fba28b/go.mod h1:TASujm6H1LGdx43MN7Dab1xdAqR7MVU8bsS74Ywop5w= +github.com/openebs/api v1.10.0 h1:Jg+oN6g5McySACFkFyHqskomDgQJe7gFX35m0fkvRSU= +github.com/openebs/api v1.10.0/go.mod h1:TASujm6H1LGdx43MN7Dab1xdAqR7MVU8bsS74Ywop5w= +github.com/openebs/api v1.10.1-0.20200519181449-902964f2beb0 h1:8Cn6lH1T1RNwFa6t6OxCGkP1ZySNNrTU5UJpJHSSl60= +github.com/openebs/api v1.10.1-0.20200519181449-902964f2beb0/go.mod h1:TASujm6H1LGdx43MN7Dab1xdAqR7MVU8bsS74Ywop5w= github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= github.com/pelletier/go-toml v1.1.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= @@ -590,6 +594,7 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e h1:N7DeIrjYszNmSW409R3frPPwglRwMkXSBzwVbkOjLLA= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200122134326-e047566fdf82 h1:ywK/j/KkyTHcdyYSZNXGjMwgmDSfjglYZ3vStQ/gSCU= golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -635,6 +640,7 @@ golang.org/x/tools v0.0.0-20190920225731-5eefd052ad72/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5 h1:hKsoRgsbwY1NafxrwTs+k64bikrLBkAgPir1TNCj3Zs= golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -659,6 +665,7 @@ google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyac gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/pkg/pool/operations/import.go b/pkg/pool/operations/import.go index a0022ea9..f9f07bf7 100644 --- a/pkg/pool/operations/import.go +++ b/pkg/pool/operations/import.go @@ -30,8 +30,7 @@ import ( ) // Import will import pool for given CSPI object. -// It will also set `cachefile` property for that pool -// if it is mentioned in object +// It will always set `cachefile` property for that pool // It will return following thing // - If pool is imported or not // - If any error occurred during import operation @@ -54,25 +53,27 @@ func (oc *OperationsConfig) Import(cspi *cstor.CStorPoolInstance) (bool, error) klog.Infof("Importing pool %s %s", string(cspi.GetUID()), PoolName()) devID := pool.GetDevPathIfNotSlashDev(bdPath[0]) cacheFile := types.CStorPoolBasePath + types.CacheFileName - if len(devID) != 0 { - cmdOut, err = zfs.NewPoolImport(). - WithCachefile(cacheFile). - WithProperty("cachefile", cacheFile). - WithDirectory(devID). - WithPool(PoolName()). - Execute() - if err == nil { - poolImported = true - } else { - // If pool import failed, fallback to try for import without Directory - klog.Errorf("Failed to import pool with directory %s : %s : %s", - devID, cmdOut, err.Error()) - } + + // Import the pool using cachefile + // command will looks like: zpool import -c -o + cmdOut, err = zfs.NewPoolImport(). + WithCachefile(cacheFile). + WithProperty("cachefile", cacheFile). + WithPool(PoolName()). + Execute() + if err == nil { + poolImported = true + } else { + // TODO may be possible that there is no pool exists or no cache file exists + klog.Errorf("Failed to import pool by reading cache file: %s : %s", cmdOut, err.Error()) } if !poolImported { + // Import the pool without cachefile by scanning the directory + // For sparse based pools import command: zpool import -d -o + // For device based pools import command: zpool import -o (by default it will scan /dev directory) cmdOut, err = zfs.NewPoolImport(). - WithCachefile(cacheFile). + WithDirectory(devID). WithProperty("cachefile", cacheFile). WithPool(PoolName()). Execute() @@ -80,7 +81,7 @@ func (oc *OperationsConfig) Import(cspi *cstor.CStorPoolInstance) (bool, error) if err != nil { // TODO may be possible that there is no pool exists.. - klog.Errorf("Failed to import pool : %s : %s", cmdOut, err.Error()) + klog.Errorf("Failed to import pool by scanning directory: %s : %s", cmdOut, err.Error()) return false, err } diff --git a/vendor/github.com/openebs/api/pkg/apis/cstor/v1/cstorpoolcluster.go b/vendor/github.com/openebs/api/pkg/apis/cstor/v1/cstorpoolcluster.go index 4e93ff85..7769945d 100644 --- a/vendor/github.com/openebs/api/pkg/apis/cstor/v1/cstorpoolcluster.go +++ b/vendor/github.com/openebs/api/pkg/apis/cstor/v1/cstorpoolcluster.go @@ -160,7 +160,7 @@ type CStorPoolClusterStatus struct { HealthyInstances int32 `json:"healthyInstances"` // Current state of CSPC. - Conditions []CStorPoolClusterCondition `json:conditions` + Conditions []CStorPoolClusterCondition `json:"conditions"` } type CSPCConditionType string diff --git a/vendor/github.com/openebs/api/pkg/apis/openebs.io/v1alpha1/blockdeviceclaimbuilder.go b/vendor/github.com/openebs/api/pkg/apis/openebs.io/v1alpha1/blockdeviceclaimbuilder.go index 53b43288..94c741b6 100644 --- a/vendor/github.com/openebs/api/pkg/apis/openebs.io/v1alpha1/blockdeviceclaimbuilder.go +++ b/vendor/github.com/openebs/api/pkg/apis/openebs.io/v1alpha1/blockdeviceclaimbuilder.go @@ -29,6 +29,10 @@ const ( StoragePoolKindCSPC = "CStorPoolCluster" // APIVersion holds the value of OpenEBS version APIVersion = "openebs.io/v1alpha1" + + // bdTagKey defines the label selector key + // used for grouping block devices using a tag. + bdTagKey = "openebs.io/block-device-tag" ) func NewBlockDeviceClaim() *BlockDeviceClaim { @@ -144,6 +148,23 @@ func (bdc *BlockDeviceClaim) WithBlockVolumeMode(mode corev1.PersistentVolumeMod return bdc } +// WithBlockDeviceTag appends (or creates) the BDC Label Selector +// by setting the provided value to the fixed key +// openebs.io/block-device-tag +// This will enable the NDM to pick only devices that +// match the node (hostname) and block device tag value. +func (bdc *BlockDeviceClaim) WithBlockDeviceTag(bdTagValue string) *BlockDeviceClaim { + if bdc.Spec.Selector == nil { + bdc.Spec.Selector = &metav1.LabelSelector{} + } + if bdc.Spec.Selector.MatchLabels == nil { + bdc.Spec.Selector.MatchLabels = map[string]string{} + } + + bdc.Spec.Selector.MatchLabels[bdTagKey] = bdTagValue + return bdc +} + // RemoveFinalizer removes the given finalizer from the object. func (bdc *BlockDeviceClaim) RemoveFinalizer(finalizer string) { bdc.Finalizers = util.RemoveString(bdc.Finalizers, finalizer) diff --git a/vendor/github.com/openebs/api/pkg/apis/types/types.go b/vendor/github.com/openebs/api/pkg/apis/types/types.go index c621ea01..488b3446 100644 --- a/vendor/github.com/openebs/api/pkg/apis/types/types.go +++ b/vendor/github.com/openebs/api/pkg/apis/types/types.go @@ -81,7 +81,7 @@ const ( ) const ( - CStorPoolBasePath = "/var/openebs/cstor-pool" + CStorPoolBasePath = "/var/openebs/cstor-pool/" CacheFileName = "pool.cache" ) diff --git a/vendor/modules.txt b/vendor/modules.txt index 64ee7d62..67322eb3 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -40,7 +40,7 @@ github.com/json-iterator/go github.com/modern-go/concurrent # github.com/modern-go/reflect2 v1.0.1 github.com/modern-go/reflect2 -# github.com/openebs/api v0.0.0-20200429072019-650209fba28b +# github.com/openebs/api v1.10.1-0.20200519181449-902964f2beb0 github.com/openebs/api/pkg/apis/cstor github.com/openebs/api/pkg/apis/cstor/v1 github.com/openebs/api/pkg/apis/openebs.io