Skip to content

Commit f574402

Browse files
authored
Merge pull request #1470 from uriel-guzman/cpv-12
Allow customer to override gcsfuse buffer and cache volumes in shared
2 parents 517f728 + 4798795 commit f574402

3 files changed

Lines changed: 280 additions & 86 deletions

File tree

pkg/csi_driver/controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ func (s *controllerServer) ControllerPublishVolume(ctx context.Context, req *csi
230230
resources: containerResources,
231231
nodeID: nodeID,
232232
image: containerImage,
233+
volumes: podTemplate.Template.Spec.Volumes,
233234
}
234235

235236
if err := createMounterPod(clientset, ctx, podConfig); err != nil {

pkg/csi_driver/shared_mount.go

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ type mounterPodConfig struct {
6060
image string // The image for the mounter pod binary.
6161
serviceAccountName string // The KSA name for the mounter pod.
6262
resources *corev1.ResourceRequirements // The resource requirements for the mounter pod container.
63+
volumes []corev1.Volume // The volumes for the mounter pod.
6364
}
6465

6566
// sharedMount checks if the VolumeContext enables the shared node mount feature
@@ -175,26 +176,20 @@ func createMounterPodSpec(config *mounterPodConfig) *corev1.Pod {
175176
Name: util.SidecarContainerTmpVolumeName,
176177
MountPath: util.SidecarContainerTmpVolumePath,
177178
},
178-
},
179-
},
180-
},
181-
Volumes: []corev1.Volume{
182-
{
183-
Name: mounterPodMountDir,
184-
VolumeSource: corev1.VolumeSource{
185-
HostPath: &corev1.HostPathVolumeSource{
186-
Path: util.KubeletDir,
187-
Type: ptr.To(corev1.HostPathDirectoryOrCreate),
179+
{
180+
Name: webhook.SidecarContainerBufferVolumeName,
181+
MountPath: webhook.SidecarContainerBufferVolumeMountPath,
188182
},
189-
},
190-
},
191-
{
192-
Name: util.SidecarContainerTmpVolumeName,
193-
VolumeSource: corev1.VolumeSource{
194-
EmptyDir: &corev1.EmptyDirVolumeSource{},
183+
{
184+
Name: webhook.SidecarContainerCacheVolumeName,
185+
MountPath: webhook.SidecarContainerCacheVolumeMountPath,
186+
},
187+
// TODO(urielguzman): Add host network and profiles volume mounts when those features are implemented
188+
// for shared mount.
195189
},
196190
},
197191
},
192+
Volumes: mounterPodVolumes(config),
198193
Tolerations: []corev1.Toleration{
199194
{
200195
// https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/
@@ -359,6 +354,31 @@ func mounterPodResources(config *mounterPodConfig) *corev1.ResourceRequirements
359354
return &resources
360355
}
361356

357+
// mounterPodVolumes returns the list of volumes required by the mounter pod.
358+
// This includes standard GCS FUSE volumes and the host path to the kubelet directory.
359+
func mounterPodVolumes(config *mounterPodConfig) []corev1.Volume {
360+
// Get the gke-gcsfuse-tmp, gke-gcsfuse-buffer, and gke-gcsfuse-cache volumes, and allow
361+
// the buffer and cache to be overridden by the PodTemplate volumes.
362+
volumes := []corev1.Volume{}
363+
volumes = append(volumes, config.volumes...) // Make a copy to avoid mutating the PodTemplate volumes.
364+
volumes = append(volumes, webhook.GetSidecarContainerVolumeSpec(config.volumes...)...)
365+
366+
// Set the /var/lib/kubelet host path, so the mounter pod can mount the staging path to the node.
367+
volumes = append(volumes, corev1.Volume{Name: mounterPodMountDir,
368+
VolumeSource: corev1.VolumeSource{
369+
HostPath: &corev1.HostPathVolumeSource{
370+
// TODO(urielguzman): Check if we can use /var/lib/kubelet/plugins/gcsfuse.csi.storage.gke.io/
371+
// instead, to decrease the host path scope.
372+
Path: util.KubeletDir,
373+
Type: ptr.To(corev1.HostPathDirectoryOrCreate),
374+
},
375+
}})
376+
377+
// TODO(urielguzman): Add profiles and host network volumes when those features are implemnented for
378+
// shared mount.
379+
return volumes
380+
}
381+
362382
func setResource(target *corev1.ResourceList, override corev1.ResourceList, resourceName corev1.ResourceName) {
363383
if target == nil {
364384
return

0 commit comments

Comments
 (0)