-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apply backupPVCConfig to backupPod volume spec #8141
Apply backupPVCConfig to backupPod volume spec #8141
Conversation
a538b26
to
0baff97
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #8141 +/- ##
=======================================
Coverage 59.07% 59.07%
=======================================
Files 364 364
Lines 30298 30324 +26
=======================================
+ Hits 17899 17915 +16
- Misses 10956 10967 +11
+ Partials 1443 1442 -1 ☔ View full report in Codecov by Sentry. |
@shubham-pampattiwar |
@Lyndon-Li yes there were some defects identified in e2e testing by @msfrucht and these changes helped fixed those. |
I found this issue in our end-to-end testing. One cannot mount the device if the only access mode of the PVC is ReadOnlyMany as the only available option and Pod volumes and volumeMount is not read-only on selinux enabled clusters. Pod spec without read-only Read-only PVC
Pod is stuck in ContainerCreating due to the volume mount.
@Lyndon-Li Yes, it is taken as a suggestion by Kubernetes, not a requirement The failure arises in Kubernetes and Openshift clusters with selinux enabled.
Kubernetes systems and Openshift with selinux relabeling on mount fail without the datamover pod set to mount volumes as read-only. There are mechanisms to bypass the relabeling, but all of them are implementation specific to the Kubernetes distribution. Setting the Pod to make use of that the volume is read-only is not. |
@shubham-pampattiwar @msfrucht This is a good catch. |
@Lyndon-Li That configuration has several different forms.
From our experience with our own backup and restore datamovers on IBM Fusion that taking a ReadWriteOnce, ReadWriteMany, and ReadWriteOncePod, can be mounted as read-only. And the resulting writes to the volume will fail with the read-only error as expected. The shallow-copy behavior is only triggered in CSI drivers when they find the ROX mode and a VolumeSnapshot or PVC is specified as the dataSourceRef. Setting the volume as readOnly in the Pod volumes prevents the multiple container in a pod situation where one container would mount the volume readOnly as true and the other container as false. When that is performed kubelet will return an error and refuse to start the container though the mount succeeds. It is irrelevant in single container pods. Subject PVC restored from VolumeSnapshot.
For ReadWriteMany, volumeMode: Filesystem tests the original PVC was removed and replaced with one from storageclass "ocs-storagecluster-cephfs". For volumeMode: Block. The RBD PVC in volumeMode: Filesystem was restored as volumeMode: Block from snapshot. This is how "volume image" backups are generally performed as a way to prevent "high file count, small file size" volumes backups and restores from stalling from file system overhead. And the Pod volumeMounts replaced with volumeDevices. In default Openshift security settings the devicePath must be in /dev. Higher levels of SELinux permissions from SecurityContextConstraints (similar to the now removed PodSecurityPolicy Kubernetes <1.25) objects allow for attachment to other locations.
Subject Pod with selinux enabled. Kube API projected volume api access token is not shown as it is not related to this test. ServiceAccount default doesn't have any RBAC permissions anyway. Shown in Test 1 volumeMode: Filesystem with volumeMounts readOnly configuration.
Configuration PVC volumeMode: Filesystem AccessModes: ReadWriteOnce Tests.
Pod starts and runs and is in status running with volume mounted. File writes fail due to read-only filesystem.
Pod mounts the volume and starts and is in running state. File writes fail due to read-only filesystem.
Pod mounts the volume and start is in running state. File writes fail due to read-only filesystem.
This test is repeated for PVC accessModes configurations ReadWriteOnce, ReadWriteMany, and [ReadWriteOnce, ReadWriteMany]. For volumeDevices there is just one test.
This operation succeeds with readOnly removed.
The test is repeated on volume accessMode configuration ReadWriteOnce, ReadWriteMany, and [RWO, RWX]. |
@msfrucht Thanks a lot for the detailed tests. |
The only combination that fails on Kubernetes without SELinux I could force were
I'm sure there are others. But none that I could find with a single PVC attached to a Pod. StorageClass volumeBindingMode: WaitForFirstConsumer can have some interesting side-effects, but they all require multiple PVCs attached to a Pod to activate. |
0baff97
to
d14790c
Compare
@Lyndon-Li @msfrucht @blackpiglet PTAL ! Updated the PR to always set VolumeMount for backuPod as ReadOnly. |
@shubham-pampattiwar |
d14790c
to
631383f
Compare
Done, fixed. |
pkg/util/kube/pvc_pv.go
Outdated
@@ -360,6 +360,7 @@ func MakePodPVCAttachment(volumeName string, volumeMode *corev1api.PersistentVol | |||
volumeMounts = []corev1api.VolumeMount{{ | |||
Name: volumeName, | |||
MountPath: volumePath, | |||
ReadOnly: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should not be hardcoded, MakePodPVCAttachment
is a shared function and is also used by generic restore
.
So we need add a readOnly
parameter to this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, updated the PR.
631383f
to
8909b8f
Compare
Signed-off-by: Shubham Pampattiwar <[email protected]> add changelog file Signed-off-by: Shubham Pampattiwar <[email protected]> make backupPod volume mount always readOnly Signed-off-by: Shubham Pampattiwar <[email protected]> use assert.True() Signed-off-by: Shubham Pampattiwar <[email protected]> Add readOnly param for MakePodPVCAttachment func lint fix Signed-off-by: Shubham Pampattiwar <[email protected]>
7ffafa2
to
f6e2b01
Compare
Thank you for contributing to Velero!
Please add a summary of your change
createBackupPod
function to accept backupPVCConfig and make changes wherever applicable to pod specMakePodPVCAttachment
to accept readOnly volume boolean and apply the flag toPersistentVolumeFilesystem
type volumeMountsPlease indicate you've done the following:
/kind changelog-not-required
as a comment on this pull request.site/content/docs/main
.