|
| 1 | +From af25759a3205ac3cdf42254923e3e20cf336a4a0 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Vicente Cheng <vicente.cheng@suse.com> |
| 3 | +Date: Fri, 17 Feb 2023 17:23:06 +0800 |
| 4 | +Subject: [PATCH] virt-controller: render hp-volume- pod should respect |
| 5 | + blockdevices |
| 6 | + |
| 7 | + We found that the VolumeDevices does not generate as the first |
| 8 | + time we render on hp-volume- pod. That would cause the global path |
| 9 | + not to be generated by kubelet again when the hp-volume- is |
| 10 | + dead, then render again. |
| 11 | + |
| 12 | + We should respect the VolumeDevics on the Spec. That would make |
| 13 | + kubelet behavior is the same as the first time when the hp-volume- |
| 14 | + pod is killed. |
| 15 | + |
| 16 | +Signed-off-by: Vicente Cheng <vicente.cheng@suse.com> |
| 17 | +--- |
| 18 | + pkg/virt-controller/services/template.go | 41 +++++++++++------------- |
| 19 | + 1 file changed, 19 insertions(+), 22 deletions(-) |
| 20 | + |
| 21 | +diff --git a/pkg/virt-controller/services/template.go b/pkg/virt-controller/services/template.go |
| 22 | +index 4fe5fdcd0374..d4f1fbae7840 100644 |
| 23 | +--- a/pkg/virt-controller/services/template.go |
| 24 | ++++ b/pkg/virt-controller/services/template.go |
| 25 | +@@ -25,19 +25,14 @@ import ( |
| 26 | + "strconv" |
| 27 | + "strings" |
| 28 | + |
| 29 | +- "kubevirt.io/kubevirt/pkg/virt-controller/watch/topology" |
| 30 | +- |
| 31 | +- "k8s.io/kubectl/pkg/cmd/util/podcmd" |
| 32 | +- "k8s.io/utils/pointer" |
| 33 | +- |
| 34 | ++ networkv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1" |
| 35 | + k8sv1 "k8s.io/api/core/v1" |
| 36 | + "k8s.io/apimachinery/pkg/api/resource" |
| 37 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 38 | + "k8s.io/apimachinery/pkg/runtime/schema" |
| 39 | + "k8s.io/client-go/tools/cache" |
| 40 | +- |
| 41 | +- networkv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1" |
| 42 | +- |
| 43 | ++ "k8s.io/kubectl/pkg/cmd/util/podcmd" |
| 44 | ++ "k8s.io/utils/pointer" |
| 45 | + v1 "kubevirt.io/api/core/v1" |
| 46 | + exportv1 "kubevirt.io/api/export/v1alpha1" |
| 47 | + "kubevirt.io/client-go/kubecli" |
| 48 | +@@ -52,6 +47,7 @@ import ( |
| 49 | + "kubevirt.io/kubevirt/pkg/util" |
| 50 | + "kubevirt.io/kubevirt/pkg/util/net/dns" |
| 51 | + virtconfig "kubevirt.io/kubevirt/pkg/virt-config" |
| 52 | ++ "kubevirt.io/kubevirt/pkg/virt-controller/watch/topology" |
| 53 | + "kubevirt.io/kubevirt/pkg/virt-launcher/virtwrap/api" |
| 54 | + ) |
| 55 | + |
| 56 | +@@ -845,20 +841,21 @@ func (t *templateService) RenderHotplugAttachmentPodTemplate(volumes []*v1.Volum |
| 57 | + }, |
| 58 | + }, |
| 59 | + }) |
| 60 | +- if !skipMount { |
| 61 | +- pvc := claimMap[volume.Name] |
| 62 | +- if pvc != nil { |
| 63 | +- if types.IsPVCBlock(pvc.Spec.VolumeMode) { |
| 64 | +- pod.Spec.Containers[0].VolumeDevices = append(pod.Spec.Containers[0].VolumeDevices, k8sv1.VolumeDevice{ |
| 65 | +- Name: volume.Name, |
| 66 | +- DevicePath: fmt.Sprintf("/path/%s/%s", volume.Name, pvc.GetUID()), |
| 67 | +- }) |
| 68 | +- } else { |
| 69 | +- pod.Spec.Containers[0].VolumeMounts = append(pod.Spec.Containers[0].VolumeMounts, k8sv1.VolumeMount{ |
| 70 | +- Name: volume.Name, |
| 71 | +- MountPath: fmt.Sprintf("/%s", volume.Name), |
| 72 | +- }) |
| 73 | +- } |
| 74 | ++ pvc := claimMap[volume.Name] |
| 75 | ++ if pvc == nil { |
| 76 | ++ continue |
| 77 | ++ } |
| 78 | ++ if types.IsPVCBlock(pvc.Spec.VolumeMode) { |
| 79 | ++ pod.Spec.Containers[0].VolumeDevices = append(pod.Spec.Containers[0].VolumeDevices, k8sv1.VolumeDevice{ |
| 80 | ++ Name: volume.Name, |
| 81 | ++ DevicePath: fmt.Sprintf("/path/%s/%s", volume.Name, pvc.GetUID()), |
| 82 | ++ }) |
| 83 | ++ } else { |
| 84 | ++ if !skipMount { |
| 85 | ++ pod.Spec.Containers[0].VolumeMounts = append(pod.Spec.Containers[0].VolumeMounts, k8sv1.VolumeMount{ |
| 86 | ++ Name: volume.Name, |
| 87 | ++ MountPath: fmt.Sprintf("/%s", volume.Name), |
| 88 | ++ }) |
| 89 | + } |
| 90 | + } |
| 91 | + } |
0 commit comments