Fix volume creation for PVC (#1709)

This commit is contained in:
David Simansky 2022-07-29 12:48:38 +02:00 committed by GitHub
parent 526d680cf6
commit 05ccf8e035
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 14 deletions

View File

@ -528,7 +528,7 @@ func updateVolume(volume *corev1.Volume, info *volumeSourceInfo) error {
case EmptyDirVolumeSourceType: case EmptyDirVolumeSourceType:
volume.EmptyDir = &corev1.EmptyDirVolumeSource{Medium: corev1.StorageMedium(info.emptyDirMemoryType), SizeLimit: info.emptyDirSize} volume.EmptyDir = &corev1.EmptyDirVolumeSource{Medium: corev1.StorageMedium(info.emptyDirMemoryType), SizeLimit: info.emptyDirSize}
case PVCVolumeSourceType: case PVCVolumeSourceType:
volume.PersistentVolumeClaim = &corev1.PersistentVolumeClaimVolumeSource{ClaimName: info.volumeSourceName, ReadOnly: true} volume.PersistentVolumeClaim = &corev1.PersistentVolumeClaimVolumeSource{ClaimName: info.volumeSourceName}
default: default:
return fmt.Errorf("Invalid VolumeSourceType") return fmt.Errorf("Invalid VolumeSourceType")
} }

View File

@ -196,9 +196,13 @@ func serviceCreateWithMount(r *test.KnRunResultCollector) {
it := r.KnTest() it := r.KnTest()
kubectl := test.NewKubectl("knative-serving") 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) 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()) kubectl = test.NewKubectl(it.Namespace())
@ -213,6 +217,7 @@ func serviceCreateWithMount(r *test.KnRunResultCollector) {
r.T().Log("update the subpath in mounted cm") r.T().Log("update the subpath in mounted cm")
out = r.KnTest().Kn().Run("service", "update", "test-svc", "--mount", "/mydir=cm:test-cm/key") out = r.KnTest().Kn().Run("service", "update", "test-svc", "--mount", "/mydir=cm:test-cm/key")
r.AssertNoError(out) r.AssertNoError(out)
serviceDescribeMount(r, "test-svc", "/mydir", "key")
r.T().Log("create secret test-sec") r.T().Log("create secret test-sec")
_, err = kubectl.Run("create", "secret", "generic", "test-sec", "--from-literal", "key1=val1") _, err = kubectl.Run("create", "secret", "generic", "test-sec", "--from-literal", "key1=val1")
@ -240,17 +245,9 @@ func serviceCreateWithMount(r *test.KnRunResultCollector) {
assert.NilError(r.T(), err) assert.NilError(r.T(), err)
r.AssertNoError(out) r.AssertNoError(out)
_, err = kubectl.Run("wait", "--for='jsonpath={..status.phase}'=Bound", "pvc/test-pvc", "--timeout=30s") r.T().Log("update service with a new pvc mount")
if err == nil { out = r.KnTest().Kn().Run("service", "update", "test-svc", "--mount", "/mydir5=pvc:test-pvc")
r.T().Log("update service with a new pvc mount") r.AssertNoError(out)
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")
}
} }
func getVolumeMountWithHostPath(svc *servingv1.Service, hostPath string) *v1.VolumeMount { func getVolumeMountWithHostPath(svc *servingv1.Service, hostPath string) *v1.VolumeMount {