mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #96659 from chendave/volume
Create PVC first if it's referenced by PV
This commit is contained in:
commit
c07c7317af
@ -1369,11 +1369,27 @@ func CreatePodWithPersistentVolume(client clientset.Interface, namespace string,
|
|||||||
pv.Status.Phase = v1.VolumeBound
|
pv.Status.Phase = v1.VolumeBound
|
||||||
|
|
||||||
// bind pvc to "pv-$i"
|
// bind pvc to "pv-$i"
|
||||||
// pvc.Spec.VolumeName = pv.Name
|
|
||||||
pvc.Status.Phase = v1.ClaimBound
|
pvc.Status.Phase = v1.ClaimBound
|
||||||
} else {
|
} else {
|
||||||
pv.Status.Phase = v1.VolumeAvailable
|
pv.Status.Phase = v1.VolumeAvailable
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create PVC first as it's referenced by the PV when the `bindVolume` is true.
|
||||||
|
if err := CreatePersistentVolumeClaimWithRetries(client, namespace, pvc); err != nil {
|
||||||
|
lock.Lock()
|
||||||
|
defer lock.Unlock()
|
||||||
|
createError = fmt.Errorf("error creating PVC: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// We need to update statuses separately, as creating pv/pvc resets status to the default one.
|
||||||
|
if _, err := client.CoreV1().PersistentVolumeClaims(namespace).UpdateStatus(context.TODO(), pvc, metav1.UpdateOptions{}); err != nil {
|
||||||
|
lock.Lock()
|
||||||
|
defer lock.Unlock()
|
||||||
|
createError = fmt.Errorf("error updating PVC status: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if err := CreatePersistentVolumeWithRetries(client, pv); err != nil {
|
if err := CreatePersistentVolumeWithRetries(client, pv); err != nil {
|
||||||
lock.Lock()
|
lock.Lock()
|
||||||
defer lock.Unlock()
|
defer lock.Unlock()
|
||||||
@ -1388,19 +1404,6 @@ func CreatePodWithPersistentVolume(client clientset.Interface, namespace string,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := CreatePersistentVolumeClaimWithRetries(client, namespace, pvc); err != nil {
|
|
||||||
lock.Lock()
|
|
||||||
defer lock.Unlock()
|
|
||||||
createError = fmt.Errorf("error creating PVC: %s", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if _, err := client.CoreV1().PersistentVolumeClaims(namespace).UpdateStatus(context.TODO(), pvc, metav1.UpdateOptions{}); err != nil {
|
|
||||||
lock.Lock()
|
|
||||||
defer lock.Unlock()
|
|
||||||
createError = fmt.Errorf("error updating PVC status: %s", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// pod
|
// pod
|
||||||
pod := podTemplate.DeepCopy()
|
pod := podTemplate.DeepCopy()
|
||||||
pod.Spec.Volumes = []v1.Volume{
|
pod.Spec.Volumes = []v1.Volume{
|
||||||
|
Loading…
Reference in New Issue
Block a user