mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Fix issue #63183 that pods on different nodes mount Ceph RBD PVC stuck on ContainerCreating.
This commit is contained in:
parent
456b56a2fb
commit
6d3b41cd85
@ -232,6 +232,10 @@ func (plugin *rbdPlugin) createMounterFromVolumeSpecAndPod(spec *volume.Spec, po
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
ams, err := getVolumeAccessModes(spec)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
secretName, secretNs, err := getSecretNameAndNamespace(spec, pod.Namespace)
|
secretName, secretNs, err := getSecretNameAndNamespace(spec, pod.Namespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -261,6 +265,7 @@ func (plugin *rbdPlugin) createMounterFromVolumeSpecAndPod(spec *volume.Spec, po
|
|||||||
Keyring: keyring,
|
Keyring: keyring,
|
||||||
Secret: secret,
|
Secret: secret,
|
||||||
fsType: fstype,
|
fsType: fstype,
|
||||||
|
accessModes: ams,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -319,6 +324,10 @@ func (plugin *rbdPlugin) newMounterInternal(spec *volume.Spec, podUID types.UID,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
ams, err := getVolumeAccessModes(spec)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return &rbdMounter{
|
return &rbdMounter{
|
||||||
rbd: newRBD(podUID, spec.Name(), img, pool, ro, plugin, manager),
|
rbd: newRBD(podUID, spec.Name(), img, pool, ro, plugin, manager),
|
||||||
@ -328,6 +337,7 @@ func (plugin *rbdPlugin) newMounterInternal(spec *volume.Spec, podUID types.UID,
|
|||||||
Secret: secret,
|
Secret: secret,
|
||||||
fsType: fstype,
|
fsType: fstype,
|
||||||
mountOptions: volutil.MountOptionFromSpec(spec),
|
mountOptions: volutil.MountOptionFromSpec(spec),
|
||||||
|
accessModes: ams,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -764,6 +774,7 @@ type rbdMounter struct {
|
|||||||
mountOptions []string
|
mountOptions []string
|
||||||
imageFormat string
|
imageFormat string
|
||||||
imageFeatures []string
|
imageFeatures []string
|
||||||
|
accessModes []v1.PersistentVolumeAccessMode
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ volume.Mounter = &rbdMounter{}
|
var _ volume.Mounter = &rbdMounter{}
|
||||||
@ -1039,6 +1050,19 @@ func getVolumeSourceReadOnly(spec *volume.Spec) (bool, error) {
|
|||||||
return false, fmt.Errorf("Spec does not reference a RBD volume type")
|
return false, fmt.Errorf("Spec does not reference a RBD volume type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getVolumeAccessModes(spec *volume.Spec) ([]v1.PersistentVolumeAccessMode, error) {
|
||||||
|
// Only PersistentVolumeSpec has AccessModes
|
||||||
|
if spec.PersistentVolume != nil {
|
||||||
|
if spec.PersistentVolume.Spec.RBD != nil {
|
||||||
|
return spec.PersistentVolume.Spec.AccessModes, nil
|
||||||
|
} else {
|
||||||
|
return nil, fmt.Errorf("Spec does not reference a RBD volume type")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
func parsePodSecret(pod *v1.Pod, secretName string, kubeClient clientset.Interface) (string, error) {
|
func parsePodSecret(pod *v1.Pod, secretName string, kubeClient clientset.Interface) (string, error) {
|
||||||
secret, err := volutil.GetSecretForPod(pod, secretName, kubeClient)
|
secret, err := volutil.GetSecretForPod(pod, secretName, kubeClient)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -358,6 +358,7 @@ func TestPlugin(t *testing.T) {
|
|||||||
FSType: "ext4",
|
FSType: "ext4",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
AccessModes: []v1.PersistentVolumeAccessMode{v1.ReadOnlyMany},
|
||||||
},
|
},
|
||||||
}, false),
|
}, false),
|
||||||
root: tmpDir,
|
root: tmpDir,
|
||||||
|
@ -390,12 +390,22 @@ func (util *RBDUtil) AttachDisk(b rbdMounter) (string, error) {
|
|||||||
Factor: rbdImageWatcherFactor,
|
Factor: rbdImageWatcherFactor,
|
||||||
Steps: rbdImageWatcherSteps,
|
Steps: rbdImageWatcherSteps,
|
||||||
}
|
}
|
||||||
|
needValidUsed := true
|
||||||
|
// If accessModes contain ReadOnlyMany, we don't need check rbd status of being used.
|
||||||
|
if b.accessModes != nil {
|
||||||
|
for _, v := range b.accessModes {
|
||||||
|
if v != v1.ReadWriteOnce {
|
||||||
|
needValidUsed = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
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 !used, nil
|
return !needValidUsed || !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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user