Skip to content

Commit 6934655

Browse files
author
sai chaithanya
authored
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 <[email protected]>
1 parent 0f16def commit 6934655

File tree

8 files changed

+69
-25
lines changed

8 files changed

+69
-25
lines changed

ci/sanity/sanity.sh

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,25 @@ kubectl apply -f ./ci/sanity/cspc.yaml
113113

114114
IsPoolHealthy 30
115115

116+
## Once the pool is healthy verify whether cachefile stored in persistent path
117+
## Get the CSPC name
118+
echo "Verifying whether pool cachefile is stored in persistent path"
119+
cspcName=$(kubectl get cspc -n openebs -o=jsonpath={.items[0].metadata.name})
120+
if [ $? -ne 0 ]; then
121+
echo "Failed to get CSPC name"
122+
exit 1
123+
fi
124+
## verify whether cache file present in persistent path
125+
ls -lrth /var/openebs/cstor-pool/${cspcName}/pool.cache
126+
if [ $? -ne 0 ]; then
127+
echo "cache file is not present in persistent path"
128+
exit 1
129+
fi
130+
116131
echo "Applying cstor-csi storage class"
117132
kubectl apply -f ./ci/artifacts/csi-storageclass.yaml
118133
echo "Deploying Busy-Box pod to use the cStor CSI volume..."
119134
kubectl apply -f ./ci/artifacts/busybox-csi-cstor-sparse.yaml
120135

121136
IsPVCBound csi-claim 30
122-
IsPodRunning busybox 30
137+
IsPodRunning busybox 30

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/imdario/mergo v0.3.8 // indirect
99
github.com/onsi/ginkgo v1.12.0 // indirect
1010
github.com/onsi/gomega v1.9.0 // indirect
11-
github.com/openebs/api v0.0.0-20200429072019-650209fba28b
11+
github.com/openebs/api v1.10.1-0.20200519181449-902964f2beb0
1212
github.com/pkg/errors v0.9.1
1313
github.com/spf13/cobra v0.0.5
1414
github.com/spf13/pflag v1.0.5

go.sum

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Z
226226
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
227227
github.com/google/cadvisor v0.35.0/go.mod h1:1nql6U13uTHaLYB8rLS5x9IJc2qT6Xd/Tr1sTX6NE48=
228228
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
229+
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
229230
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
230231
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
231232
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
278279
github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
279280
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
280281
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
282+
github.com/json-iterator/go v1.1.8 h1:QiWkFLKq0T7mpzwOTu6BzNDbfTE8OLrYhVKYMLF46Ok=
281283
github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
282284
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
283285
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
383385
github.com/opencontainers/runc v1.0.0-rc9/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U=
384386
github.com/opencontainers/runtime-spec v1.0.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
385387
github.com/opencontainers/selinux v1.3.1-0.20190929122143-5215b1806f52/go.mod h1:+BLncwf63G4dgOzykXAxcmnFlUaOlkDdmw/CqsW6pjs=
386-
github.com/openebs/api v0.0.0-20200429072019-650209fba28b h1:XC6wCUascCjnEEstKkSFuEZB2YjTtm10Mx7SoRSHfhk=
387-
github.com/openebs/api v0.0.0-20200429072019-650209fba28b/go.mod h1:TASujm6H1LGdx43MN7Dab1xdAqR7MVU8bsS74Ywop5w=
388+
github.com/openebs/api v1.10.0 h1:Jg+oN6g5McySACFkFyHqskomDgQJe7gFX35m0fkvRSU=
389+
github.com/openebs/api v1.10.0/go.mod h1:TASujm6H1LGdx43MN7Dab1xdAqR7MVU8bsS74Ywop5w=
390+
github.com/openebs/api v1.10.1-0.20200519181449-902964f2beb0 h1:8Cn6lH1T1RNwFa6t6OxCGkP1ZySNNrTU5UJpJHSSl60=
391+
github.com/openebs/api v1.10.1-0.20200519181449-902964f2beb0/go.mod h1:TASujm6H1LGdx43MN7Dab1xdAqR7MVU8bsS74Ywop5w=
388392
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
389393
github.com/pelletier/go-toml v1.1.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
390394
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
590594
golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
591595
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
592596
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
597+
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e h1:N7DeIrjYszNmSW409R3frPPwglRwMkXSBzwVbkOjLLA=
593598
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
594599
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82 h1:ywK/j/KkyTHcdyYSZNXGjMwgmDSfjglYZ3vStQ/gSCU=
595600
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
635640
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
636641
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5 h1:hKsoRgsbwY1NafxrwTs+k64bikrLBkAgPir1TNCj3Zs=
637642
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
643+
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc=
638644
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
639645
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
640646
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
659665
gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
660666
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
661667
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
668+
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
662669
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
663670
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
664671
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

pkg/pool/operations/import.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ import (
3030
)
3131

3232
// Import will import pool for given CSPI object.
33-
// It will also set `cachefile` property for that pool
34-
// if it is mentioned in object
33+
// It will always set `cachefile` property for that pool
3534
// It will return following thing
3635
// - If pool is imported or not
3736
// - If any error occurred during import operation
@@ -54,33 +53,35 @@ func (oc *OperationsConfig) Import(cspi *cstor.CStorPoolInstance) (bool, error)
5453
klog.Infof("Importing pool %s %s", string(cspi.GetUID()), PoolName())
5554
devID := pool.GetDevPathIfNotSlashDev(bdPath[0])
5655
cacheFile := types.CStorPoolBasePath + types.CacheFileName
57-
if len(devID) != 0 {
58-
cmdOut, err = zfs.NewPoolImport().
59-
WithCachefile(cacheFile).
60-
WithProperty("cachefile", cacheFile).
61-
WithDirectory(devID).
62-
WithPool(PoolName()).
63-
Execute()
64-
if err == nil {
65-
poolImported = true
66-
} else {
67-
// If pool import failed, fallback to try for import without Directory
68-
klog.Errorf("Failed to import pool with directory %s : %s : %s",
69-
devID, cmdOut, err.Error())
70-
}
56+
57+
// Import the pool using cachefile
58+
// command will looks like: zpool import -c <cachefile_path> -o <cachefile_path> <pool_name>
59+
cmdOut, err = zfs.NewPoolImport().
60+
WithCachefile(cacheFile).
61+
WithProperty("cachefile", cacheFile).
62+
WithPool(PoolName()).
63+
Execute()
64+
if err == nil {
65+
poolImported = true
66+
} else {
67+
// TODO may be possible that there is no pool exists or no cache file exists
68+
klog.Errorf("Failed to import pool by reading cache file: %s : %s", cmdOut, err.Error())
7169
}
7270

7371
if !poolImported {
72+
// Import the pool without cachefile by scanning the directory
73+
// For sparse based pools import command: zpool import -d <parent_dir_sparse_files> -o <cachefile_path> <pool_name>
74+
// For device based pools import command: zpool import -o <cachefile_path> <pool_name>(by default it will scan /dev directory)
7475
cmdOut, err = zfs.NewPoolImport().
75-
WithCachefile(cacheFile).
76+
WithDirectory(devID).
7677
WithProperty("cachefile", cacheFile).
7778
WithPool(PoolName()).
7879
Execute()
7980
}
8081

8182
if err != nil {
8283
// TODO may be possible that there is no pool exists..
83-
klog.Errorf("Failed to import pool : %s : %s", cmdOut, err.Error())
84+
klog.Errorf("Failed to import pool by scanning directory: %s : %s", cmdOut, err.Error())
8485
return false, err
8586
}
8687

vendor/github.com/openebs/api/pkg/apis/cstor/v1/cstorpoolcluster.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/openebs/api/pkg/apis/openebs.io/v1alpha1/blockdeviceclaimbuilder.go

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/openebs/api/pkg/apis/types/types.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ github.com/json-iterator/go
4040
github.com/modern-go/concurrent
4141
# github.com/modern-go/reflect2 v1.0.1
4242
github.com/modern-go/reflect2
43-
# github.com/openebs/api v0.0.0-20200429072019-650209fba28b
43+
# github.com/openebs/api v1.10.1-0.20200519181449-902964f2beb0
4444
github.com/openebs/api/pkg/apis/cstor
4545
github.com/openebs/api/pkg/apis/cstor/v1
4646
github.com/openebs/api/pkg/apis/openebs.io

0 commit comments

Comments
 (0)