Skip to content

Commit 40dfee4

Browse files
ayushr2gvisor-bot
authored andcommitted
Automatically enable host UDS for GCS FUSE sidecar containers.
This change detects the GCS FUSE sidecar by looking for a specific non-empty EmptyDir volume (`gke-gcsfuse-tmp`). If found, the `dev.gvisor.flag.host-uds` annotation is set to "open" to allow communication with the gcsfuse driver via Unix Domain Sockets. This applies to both the root container and subcontainers. PiperOrigin-RevId: 805704770
1 parent d690038 commit 40dfee4

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pkg/shim/v1/utils/volumes.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import (
2929
const (
3030
volumeKeyPrefix = "dev.gvisor.spec.mount."
3131

32+
udsFlagAnnotation = "dev.gvisor.flag.host-uds"
33+
3234
// devshmName is the volume name used for /dev/shm. Pick a name that is
3335
// unlikely to be used.
3436
devshmName = "gvisorinternaldevshm"
@@ -40,6 +42,11 @@ const (
4042
// selfFilestorePrefix is the prefix for the filestore files used for
4143
// self-backed mounts.
4244
selfFilestorePrefix = ".gvisor.filestore."
45+
46+
// gcsFuseSidecarTmpVolumeName is the name of the GCS FUSE sidecar's volume
47+
// that contains the socket for communicating with the driver. Same as
48+
// GoogleCloudPlatform/gcs-fuse-csi-driver/pkg/webhook/sidecar_spec.go:SidecarContainerTmpVolumeName.
49+
gcsFuseSidecarTmpVolumeName = "gke-gcsfuse-tmp"
4350
)
4451

4552
// The directory structure for volumes is as follows:
@@ -172,6 +179,11 @@ func UpdateVolumeAnnotations(s *specs.Spec) (bool, error) {
172179
log.L.Infof("Non-empty EmptyDir volume %q, configuring bind mount annotations", volume)
173180
s.Annotations[k] = "bind"
174181
s.Annotations[volumeShareKey(volume)] = "shared"
182+
if volume == gcsFuseSidecarTmpVolumeName && s.Annotations[udsFlagAnnotation] == "" {
183+
// Enable host UDS flag to allow communication with the gcsfuse driver.
184+
log.L.Infof("GCS Fuse sidecar detected in Pod, setting --host-uds=open")
185+
s.Annotations[udsFlagAnnotation] = "open"
186+
}
175187
}
176188
}
177189
updated = true
@@ -191,6 +203,13 @@ func UpdateVolumeAnnotations(s *specs.Spec) (bool, error) {
191203
if strings.Contains(s.Mounts[i].Source, emptyDirVolumesDir) && !isEmptyDirEmpty(s.Mounts[i].Source) {
192204
// This is a non-empty EmptyDir volume. Don't change the mount type.
193205
log.L.Infof("Non-empty EmptyDir volume %q, not changing its mount type", volume)
206+
if volume == gcsFuseSidecarTmpVolumeName && s.Annotations[udsFlagAnnotation] == "" {
207+
// Enable host UDS flag to allow communication with the gcsfuse
208+
// driver. Do this for subcontainers too to update fsgofer's UDS
209+
// configuration because each subcontainer has its own fsgofer.
210+
log.L.Infof("This is a GCS Fuse sidecar container, setting --host-uds=open")
211+
s.Annotations[udsFlagAnnotation] = "open"
212+
}
194213
continue
195214
}
196215
// Container mount type must match the mount type specified by

0 commit comments

Comments
 (0)