mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-10 12:32:03 +00:00
RBD Plugin: rbdStatus only check output of successful rbd status
run
This commit is contained in:
parent
d1bf3bc281
commit
bcacfff798
@ -436,7 +436,7 @@ func (util *RBDUtil) DeleteImage(p *rbdVolumeDeleter) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// run rbd status command to check if there is watcher on the image
|
// rbdStatus runs `rbd status` command to check if there is watcher on the image.
|
||||||
func (util *RBDUtil) rbdStatus(b *rbdMounter) (bool, error) {
|
func (util *RBDUtil) rbdStatus(b *rbdMounter) (bool, error) {
|
||||||
var err error
|
var err error
|
||||||
var output string
|
var output string
|
||||||
@ -444,26 +444,45 @@ func (util *RBDUtil) rbdStatus(b *rbdMounter) (bool, error) {
|
|||||||
|
|
||||||
l := len(b.Mon)
|
l := len(b.Mon)
|
||||||
start := rand.Int() % l
|
start := rand.Int() % l
|
||||||
// iterate all hosts until mount succeeds.
|
// iterate all hosts until rbd command succeeds.
|
||||||
for i := start; i < start+l; i++ {
|
for i := start; i < start+l; i++ {
|
||||||
mon := b.Mon[i%l]
|
mon := b.Mon[i%l]
|
||||||
// cmd "rbd status" list the rbd client watch with the following output:
|
// cmd "rbd status" list the rbd client watch with the following output:
|
||||||
|
//
|
||||||
|
// # there is a watcher (exit=0)
|
||||||
// Watchers:
|
// Watchers:
|
||||||
// watcher=10.16.153.105:0/710245699 client.14163 cookie=1
|
// watcher=10.16.153.105:0/710245699 client.14163 cookie=1
|
||||||
|
//
|
||||||
|
// # there is no watcher (exit=0)
|
||||||
|
// Watchers: none
|
||||||
|
//
|
||||||
|
// Otherwise, exit is non-zero, for example:
|
||||||
|
//
|
||||||
|
// # image does not exist (exit=2)
|
||||||
|
// rbd: error opening image kubernetes-dynamic-pvc-<UUID>: (2) No such file or directory
|
||||||
|
//
|
||||||
glog.V(4).Infof("rbd: status %s using mon %s, pool %s id %s key %s", b.Image, mon, b.Pool, b.adminId, b.adminSecret)
|
glog.V(4).Infof("rbd: status %s using mon %s, pool %s id %s key %s", b.Image, mon, b.Pool, b.adminId, b.adminSecret)
|
||||||
cmd, err = b.exec.Run("rbd",
|
cmd, err = b.exec.Run("rbd",
|
||||||
"status", b.Image, "--pool", b.Pool, "-m", mon, "--id", b.adminId, "--key="+b.adminSecret)
|
"status", b.Image, "--pool", b.Pool, "-m", mon, "--id", b.adminId, "--key="+b.adminSecret)
|
||||||
output = string(cmd)
|
output = string(cmd)
|
||||||
|
|
||||||
if err != nil {
|
// break if command succeeds
|
||||||
|
if err == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
if err.Error() == rbdCmdErr {
|
if err.Error() == rbdCmdErr {
|
||||||
glog.Errorf("rbd cmd not found")
|
glog.Errorf("rbd cmd not found")
|
||||||
} else {
|
// fail fast if command not found
|
||||||
// ignore error code, just checkout output for watcher string
|
return false, err
|
||||||
glog.Warningf("failed to execute rbd status on mon %s", mon)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If command never succeed, returns its last error.
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
if strings.Contains(output, imageWatcherStr) {
|
if strings.Contains(output, imageWatcherStr) {
|
||||||
glog.V(4).Infof("rbd: watchers on %s: %s", b.Image, output)
|
glog.V(4).Infof("rbd: watchers on %s: %s", b.Image, output)
|
||||||
return true, nil
|
return true, nil
|
||||||
@ -472,5 +491,3 @@ func (util *RBDUtil) rbdStatus(b *rbdMounter) (bool, error) {
|
|||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user