Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pkg/driver/node/mounter/pod_unmounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,13 @@ func (u *PodUnmounter) writeExitFile(podPath string) error {

// cleanupCredentials removes credentials associated with the Mountpoint Pod
func (u *PodUnmounter) cleanupCredentials(mpPod *corev1.Pod) error {
volumeID, exists := mpPod.Annotations[mppod.AnnotationVolumeId]
if !exists {
// Fallback to deprecated label for backward compatibility with older Mountpoint Pods
volumeID = mpPod.Labels[mppod.DeprecatedLabelVolumeId]
}
return u.credProvider.Cleanup(credentialprovider.CleanupContext{
VolumeID: mpPod.Labels[mppod.LabelVolumeId],
VolumeID: volumeID,
PodID: string(mpPod.UID),
WritePath: mppod.PathOnHost(u.podPath(string(mpPod.UID)), mppod.KnownPathCredentials),
MountKind: credentialprovider.MountKindPod,
Expand Down
10 changes: 5 additions & 5 deletions pkg/driver/node/mounter/pod_unmounter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func TestCleanupCredentials(t *testing.T) {
Name: "test-pod",
UID: "test-uid",
Labels: map[string]string{
mppod.LabelVolumeId: "test-volume",
mppod.DeprecatedLabelVolumeId: "test-volume",
},
},
}
Expand All @@ -306,7 +306,7 @@ func TestCleanupDanglingMounts(t *testing.T) {
Name: name,
UID: "test-uid",
Labels: map[string]string{
mppod.LabelVolumeId: "test-volume",
mppod.DeprecatedLabelVolumeId: "test-volume",
},
},
}
Expand Down Expand Up @@ -630,7 +630,7 @@ func TestCleanUnmount(t *testing.T) {
Name: "mp-test-pod",
UID: "test-uid",
Labels: map[string]string{
mppod.LabelVolumeId: "test-volume",
mppod.DeprecatedLabelVolumeId: "test-volume",
},
},
}
Expand Down Expand Up @@ -824,7 +824,7 @@ func TestCleanUnmount(t *testing.T) {
Name: "mp-test-pod",
UID: "test-uid",
Labels: map[string]string{
mppod.LabelVolumeId: "test-volume",
mppod.DeprecatedLabelVolumeId: "test-volume",
},
},
}
Expand Down Expand Up @@ -874,7 +874,7 @@ func TestCleanUnmount(t *testing.T) {
Name: "mp-test-pod",
UID: "test-uid",
Labels: map[string]string{
mppod.LabelVolumeId: "test-volume",
mppod.DeprecatedLabelVolumeId: "test-volume",
},
},
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/driver/node/volumecontext/volume_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ package volumecontext
const (
BucketName = "bucketName"
AuthenticationSource = "authenticationSource"
STSRegion = "stsRegion"

Cache = "cache"
CacheEmptyDirSizeLimit = "cacheEmptyDirSizeLimit"
CacheEmptyDirMedium = "cacheEmptyDirMedium"
CacheEphemeralStorageClassName = "cacheEphemeralStorageClassName"
CacheEphemeralStorageResourceRequest = "cacheEphemeralStorageResourceRequest"

MountpointPodServiceAccountName = "mountpointPodServiceAccountName"

Expand Down
13 changes: 9 additions & 4 deletions pkg/podmounter/mppod/creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import (
// Labels populated on spawned Mountpoint Pods.
const (
LabelMountpointVersion = constants.DriverName + "/mountpoint-version"
LabelPodUID = constants.DriverName + "/pod-uid"
LabelVolumeName = constants.DriverName + "/volume-name"
LabelCSIDriverVersion = constants.DriverName + "/mounted-by-csi-driver-version"
)

Expand Down Expand Up @@ -62,16 +60,23 @@ func (c *Creator) Create(pod *corev1.Pod, pv *corev1.PersistentVolume) *corev1.P
node := pod.Spec.NodeName
name := MountpointPodNameFor(string(pod.UID), pv.Name)

var volumeHandle string
if pv.Spec.CSI != nil {
volumeHandle = pv.Spec.CSI.VolumeHandle
}

mpPod := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: c.config.Namespace,
Labels: map[string]string{
LabelMountpointVersion: c.config.MountpointVersion,
LabelPodUID: string(pod.UID),
LabelVolumeName: pv.Name,
LabelCSIDriverVersion: c.config.CSIDriverVersion,
},
Annotations: map[string]string{
AnnotationVolumeName: pv.Name,
AnnotationVolumeId: volumeHandle,
},
},
Spec: corev1.PodSpec{
// Mountpoint terminates with zero exit code on a successful termination,
Expand Down
4 changes: 2 additions & 2 deletions pkg/podmounter/mppod/creator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ func createAndVerifyPod(t *testing.T, clusterVariant cluster.Variant, expectedRu
assert.Equals(t, namespace, mpPod.Namespace)
assert.Equals(t, map[string]string{
mppod.LabelMountpointVersion: mountpointVersion,
mppod.LabelPodUID: testPodUID,
mppod.LabelVolumeName: testVolName,
mppod.LabelCSIDriverVersion: csiDriverVersion,
}, mpPod.Labels)
assert.Equals(t, testVolName, mpPod.Annotations[mppod.AnnotationVolumeName])

assert.Equals(t, priorityClassName, mpPod.Spec.PriorityClassName)
assert.Equals(t, corev1.RestartPolicyOnFailure, mpPod.Spec.RestartPolicy)
Expand Down Expand Up @@ -202,6 +201,7 @@ func TestNewCreator(t *testing.T) {
assert.Equals(t, config.Namespace, mpPod.Namespace)
assert.Equals(t, config.MountpointVersion, mpPod.Labels[mppod.LabelMountpointVersion])
assert.Equals(t, config.CSIDriverVersion, mpPod.Labels[mppod.LabelCSIDriverVersion])
assert.Equals(t, "test-pv", mpPod.Annotations[mppod.AnnotationVolumeName])
assert.Equals(t, config.PriorityClassName, mpPod.Spec.PriorityClassName)
assert.Equals(t, config.Container.Image, mpPod.Spec.Containers[0].Image)
assert.Equals(t, config.Container.ImagePullPolicy, mpPod.Spec.Containers[0].ImagePullPolicy)
Expand Down
11 changes: 8 additions & 3 deletions pkg/podmounter/mppod/mppod.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ const (
AnnotationNeedsUnmount = constants.DriverName + "/needs-unmount"
// AnnotationNoNewWorkload is the annotation used to prevent new workloads from being assigned
AnnotationNoNewWorkload = constants.DriverName + "/no-new-workload"
// AnnotationVolumeName stores the PV name as an annotation (no length limit unlike labels).
AnnotationVolumeName = constants.DriverName + "/volume-name"
// AnnotationVolumeId stores the volume ID as an annotation (no length limit unlike labels).
AnnotationVolumeId = constants.DriverName + "/volume-id"
)

// Pod labels
// Deprecated Pod labels -- kept for backward compatibility with older Mountpoint Pods.
const (
// LabelVolumeId is the label used to store the volume ID
LabelVolumeId = constants.DriverName + "/volume-id"
// DeprecatedLabelVolumeId is the deprecated label used to store the volume ID.
// Use AnnotationVolumeId instead. Labels are limited to 63 characters.
DeprecatedLabelVolumeId = constants.DriverName + "/volume-id"
)

// MountpointPodNameFor returns a consistent and unique Pod name for
Expand Down
10 changes: 4 additions & 6 deletions tests/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -763,13 +763,12 @@ func expectNoMountpointPodFor(pod *testPod, vol *testVolume) {

// expectNoMountpointPodForWorkloadPod verifies that there is no Mountpoint Pod scheduled for given `pod`.
// `expectNoMountpointPodFor` is preferable to this method if the `vol` is known as this performs a slower list operation.
func expectNoMountpointPodForWorkloadPod(pod *testPod) {
// This lists all pods in the mountpoint namespace with the mountpoint-version label to find any mountpoint pods.
func expectNoMountpointPodForWorkloadPod(_ *testPod) {
Consistently(func(g Gomega) {
podList := &corev1.PodList{}
g.Expect(k8sClient.List(ctx, podList,
client.InNamespace(mountpointNamespace), client.MatchingLabels{
mppod.LabelPodUID: string(pod.UID),
},
client.InNamespace(mountpointNamespace), client.HasLabels{mppod.LabelMountpointVersion},
)).To(Succeed())

g.Expect(podList.Items).To(BeEmpty(), "Expected empty list but got: %#v", podList)
Expand All @@ -786,9 +785,8 @@ func waitAndVerifyMountpointPodFor(pod *testPod, vol *testVolume) {
// verifyMountpointPodFor verifies given `mountpointPod` for given `pod` and `vol`.
func verifyMountpointPodFor(pod *testPod, vol *testVolume, mountpointPod *testPod) {
Expect(mountpointPod.ObjectMeta.Labels).To(HaveKeyWithValue(mppod.LabelMountpointVersion, mountpointVersion))
Expect(mountpointPod.ObjectMeta.Labels).To(HaveKeyWithValue(mppod.LabelPodUID, string(pod.UID)))
Expect(mountpointPod.ObjectMeta.Labels).To(HaveKeyWithValue(mppod.LabelVolumeName, vol.pvc.Spec.VolumeName))
Expect(mountpointPod.ObjectMeta.Labels).To(HaveKeyWithValue(mppod.LabelCSIDriverVersion, version.GetVersion().DriverVersion))
Expect(mountpointPod.ObjectMeta.Annotations).To(HaveKeyWithValue(mppod.AnnotationVolumeName, vol.pvc.Spec.VolumeName))

Expect(mountpointPod.Spec.RestartPolicy).To(Equal(corev1.RestartPolicyOnFailure))

Expand Down
Loading