Skip to content

Commit b8086e3

Browse files
committed
Add capability to automount PVCs in read-only mode.
Signed-off-by: Angel Misevski <[email protected]>
1 parent c20440a commit b8086e3

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

pkg/constants/metadata.go

+5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ const (
3838
// If mountAs is not provided, the default behaviour will be to mount as a file.
3939
DevWorkspaceMountAsAnnotation = "controller.devfile.io/mount-as"
4040

41+
// DevWorkspaceMountReadyOnlyAnnotation is an annotation to configure whether a mounted volume is as read-write or
42+
// as read-only. If "true", the volume is mounted as read-only. PersistentVolumeClaims are by default mounted
43+
// read-write. Automounted configmaps and secrets are always mounted read-only and this annotation is ignored.
44+
DevWorkspaceMountReadyOnlyAnnotation = "controller.devfile.io/read-only"
45+
4146
// DevWorkspaceRestrictedAccessAnnotation marks the intention that devworkspace access is restricted to only the creator; setting this
4247
// annotation will cause devworkspace start to fail if webhooks are disabled.
4348
// Operator also propagates it to the devworkspace-related objects to perform authorization.

pkg/provision/workspace/automount/pvcs.go

+7
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,18 @@ func getAutoMountPVCs(namespace string, client k8sclient.Client) (*v1alpha1.PodA
4141
if mountPath == "" {
4242
mountPath = path.Join("/tmp/", pvc.Name)
4343
}
44+
45+
mountReadOnly := false
46+
if pvc.Annotations[constants.DevWorkspaceMountReadyOnlyAnnotation] == "true" {
47+
mountReadOnly = true
48+
}
49+
4450
podAdditions.Volumes = append(podAdditions.Volumes, corev1.Volume{
4551
Name: common.AutoMountPVCVolumeName(pvc.Name),
4652
VolumeSource: corev1.VolumeSource{
4753
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
4854
ClaimName: pvc.Name,
55+
ReadOnly: mountReadOnly,
4956
},
5057
},
5158
})

0 commit comments

Comments
 (0)