Skip to content

Commit

Permalink
Fix volume creation for PVC (#1709)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsimansk authored Jul 29, 2022
1 parent 526d680 commit 05ccf8e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pkg/kn/flags/podspec_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ func updateVolume(volume *corev1.Volume, info *volumeSourceInfo) error {
case EmptyDirVolumeSourceType:
volume.EmptyDir = &corev1.EmptyDirVolumeSource{Medium: corev1.StorageMedium(info.emptyDirMemoryType), SizeLimit: info.emptyDirSize}
case PVCVolumeSourceType:
volume.PersistentVolumeClaim = &corev1.PersistentVolumeClaimVolumeSource{ClaimName: info.volumeSourceName, ReadOnly: true}
volume.PersistentVolumeClaim = &corev1.PersistentVolumeClaimVolumeSource{ClaimName: info.volumeSourceName}
default:
return fmt.Errorf("Invalid VolumeSourceType")
}
Expand Down
23 changes: 10 additions & 13 deletions test/e2e/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,13 @@ func serviceCreateWithMount(r *test.KnRunResultCollector) {
it := r.KnTest()
kubectl := test.NewKubectl("knative-serving")

_, err := kubectl.Run("patch", "cm", "config-features", "--patch={\"data\":{\"kubernetes.podspec-persistent-volume-claim\": \"enabled\", \"kubernetes.podspec-volumes-emptydir\": \"enabled\"}}")
_, err := kubectl.Run("patch", "cm", "config-features", "--patch={\"data\":{\"kubernetes.podspec-persistent-volume-claim\": \"enabled\", "+
"\"kubernetes.podspec-persistent-volume-write\": \"enabled\", "+
"\"kubernetes.podspec-volumes-emptydir\": \"enabled\"}}")
assert.NilError(r.T(), err)
defer kubectl.Run("patch", "cm", "config-features", "--patch={\"data\":{\"kubernetes.podspec-persistent-volume-claim\": \"disabled\", \"kubernetes.podspec-volumes-emptydir\": \"disabled\"}}")
defer kubectl.Run("patch", "cm", "config-features", "--patch={\"data\":{\"kubernetes.podspec-persistent-volume-claim\": \"disabled\", "+
"\"kubernetes.podspec-persistent-volume-write\": \"disabled\", "+
"\"kubernetes.podspec-volumes-emptydir\": \"disabled\"}}")

kubectl = test.NewKubectl(it.Namespace())

Expand All @@ -213,6 +217,7 @@ func serviceCreateWithMount(r *test.KnRunResultCollector) {
r.T().Log("update the subpath in mounted cm")
out = r.KnTest().Kn().Run("service", "update", "test-svc", "--mount", "/mydir=cm:test-cm/key")
r.AssertNoError(out)
serviceDescribeMount(r, "test-svc", "/mydir", "key")

r.T().Log("create secret test-sec")
_, err = kubectl.Run("create", "secret", "generic", "test-sec", "--from-literal", "key1=val1")
Expand Down Expand Up @@ -240,17 +245,9 @@ func serviceCreateWithMount(r *test.KnRunResultCollector) {
assert.NilError(r.T(), err)
r.AssertNoError(out)

_, err = kubectl.Run("wait", "--for='jsonpath={..status.phase}'=Bound", "pvc/test-pvc", "--timeout=30s")
if err == nil {
r.T().Log("update service with a new pvc mount")
out = r.KnTest().Kn().Run("service", "update", "test-svc", "--mount", "/mydir5=pvc:test-pvc")
r.AssertNoError(out)

serviceDescribeMount(r, "test-svc", "/mydir", "key")
} else {
r.T().Log("PVC test skip due to unsatisfied PVC")
}

r.T().Log("update service with a new pvc mount")
out = r.KnTest().Kn().Run("service", "update", "test-svc", "--mount", "/mydir5=pvc:test-pvc")
r.AssertNoError(out)
}

func getVolumeMountWithHostPath(svc *servingv1.Service, hostPath string) *v1.VolumeMount {
Expand Down

0 comments on commit 05ccf8e

Please sign in to comment.