Skip to content

Commit

Permalink
Add tests for direct pvc volume mount use case
Browse files Browse the repository at this point in the history
Signed-off-by: Hannah DeFazio <h2defazio@gmail.com>
  • Loading branch information
hdefazio committed Sep 23, 2024
1 parent 560ae68 commit 1cc0c3a
Showing 1 changed file with 100 additions and 0 deletions.
100 changes: 100 additions & 0 deletions pkg/webhook/admission/pod/storage_initializer_injector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2185,6 +2185,106 @@ func TestDirectVolumeMountForPvc(t *testing.T) {
},
},
},
"StorageInitializerNotInjectedAndMountsPvcViaVolumeMountReadOnlyFalse": {
original: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
constants.StorageInitializerSourceUriInternalAnnotationKey: "pvc://mypvcname/some/path/on/pvc",
constants.StorageReadonlyAnnotationKey: "false",
},
},
Spec: v1.PodSpec{
Containers: []v1.Container{
{
Name: constants.InferenceServiceContainerName,
},
},
},
},
expected: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
constants.StorageInitializerSourceUriInternalAnnotationKey: "pvc://mypvcname/some/path/on/pvc",
},
},
Spec: v1.PodSpec{
Containers: []v1.Container{
{
Name: constants.InferenceServiceContainerName,
VolumeMounts: []v1.VolumeMount{
{
Name: "kserve-pvc-source",
MountPath: "/mnt/models",
SubPath: "some/path/on/pvc",
ReadOnly: false,
},
},
},
},
Volumes: []v1.Volume{
{
Name: "kserve-pvc-source",
VolumeSource: v1.VolumeSource{
PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{
ClaimName: "mypvcname",
ReadOnly: false,
},
},
},
},
},
},
},
"StorageInitializerNotInjectedAndMountsPvcViaVolumeMountReadOnlyTrue": {
original: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
constants.StorageInitializerSourceUriInternalAnnotationKey: "pvc://mypvcname/some/path/on/pvc",
constants.StorageReadonlyAnnotationKey: "true",
},
},
Spec: v1.PodSpec{
Containers: []v1.Container{
{
Name: constants.InferenceServiceContainerName,
},
},
},
},
expected: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
constants.StorageInitializerSourceUriInternalAnnotationKey: "pvc://mypvcname/some/path/on/pvc",
},
},
Spec: v1.PodSpec{
Containers: []v1.Container{
{
Name: constants.InferenceServiceContainerName,
VolumeMounts: []v1.VolumeMount{
{
Name: "kserve-pvc-source",
MountPath: "/mnt/models",
SubPath: "some/path/on/pvc",
ReadOnly: true,
},
},
},
},
Volumes: []v1.Volume{
{
Name: "kserve-pvc-source",
VolumeSource: v1.VolumeSource{
PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{
ClaimName: "mypvcname",
ReadOnly: false,
},
},
},
},
},
},
},
}

for name, scenario := range scenarios {
Expand Down

0 comments on commit 1cc0c3a

Please sign in to comment.