Merge pull request #67939 from NickrenREN/rbd-ams

RBD AccessModes checking when attaching
This commit is contained in:
k8s-ci-robot 2018-09-24 17:17:00 -07:00 committed by GitHub
commit 9120dc01e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -395,25 +395,23 @@ func (util *RBDUtil) AttachDisk(b rbdMounter) (string, error) {
Steps: rbdImageWatcherSteps, Steps: rbdImageWatcherSteps,
} }
needValidUsed := true needValidUsed := true
// If accessModes contain ReadOnlyMany, we don't need check rbd status of being used.
if b.accessModes != nil { if b.accessModes != nil {
for _, v := range b.accessModes { // If accessModes only contains ReadOnlyMany, we don't need check rbd status of being used.
if v != v1.ReadWriteOnce { if len(b.accessModes) == 1 && b.accessModes[0] == v1.ReadOnlyMany {
needValidUsed = false needValidUsed = false
break
} }
} }
} else { // If accessModes is nil, the volume is referenced by in-line volume.
// ReadOnly rbd volume should not check rbd status of being used to // We can assume the AccessModes to be {"RWO" and "ROX"}, which is what the volume plugin supports.
// support mounted as read-only by multiple consumers simultaneously. // We do not need to consider ReadOnly here, because it is used for VolumeMounts.
needValidUsed = !b.rbd.ReadOnly
} if needValidUsed {
err := wait.ExponentialBackoff(backoff, func() (bool, error) { err := wait.ExponentialBackoff(backoff, func() (bool, error) {
used, rbdOutput, err := util.rbdStatus(&b) used, rbdOutput, err := util.rbdStatus(&b)
if err != nil { if err != nil {
return false, fmt.Errorf("fail to check rbd image status with: (%v), rbd output: (%s)", err, rbdOutput) return false, fmt.Errorf("fail to check rbd image status with: (%v), rbd output: (%s)", err, rbdOutput)
} }
return !needValidUsed || !used, nil return !used, nil
}) })
// Return error if rbd image has not become available for the specified timeout. // Return error if rbd image has not become available for the specified timeout.
if err == wait.ErrWaitTimeout { if err == wait.ErrWaitTimeout {
@ -423,11 +421,12 @@ func (util *RBDUtil) AttachDisk(b rbdMounter) (string, error) {
if err != nil { if err != nil {
return "", err return "", err
} }
}
mon := util.kernelRBDMonitorsOpt(b.Mon) mon := util.kernelRBDMonitorsOpt(b.Mon)
glog.V(1).Infof("rbd: map mon %s", mon) glog.V(1).Infof("rbd: map mon %s", mon)
_, err = b.exec.Run("modprobe", "rbd") _, err := b.exec.Run("modprobe", "rbd")
if err != nil { if err != nil {
glog.Warningf("rbd: failed to load rbd kernel module:%v", err) glog.Warningf("rbd: failed to load rbd kernel module:%v", err)
} }