Skip to content
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

Allow subPath within volumeMounts. #3926

Merged
merged 1 commit into from
Apr 27, 2019
Merged
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
1 change: 1 addition & 0 deletions docs/spec/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -428,5 +428,6 @@ container: # v1.Container
- name: ... # This must match a name from Volumes
mountPath: ... # Where to mount the named Volume.
readOnly: ... # Must be True, will default to True, so it may be omitted.
subPath: ...
workingDir: ... # Optional
```
2 changes: 1 addition & 1 deletion pkg/apis/serving/fieldmask.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ func VolumeMountMask(in *corev1.VolumeMount) *corev1.VolumeMount {
out.Name = in.Name
out.ReadOnly = in.ReadOnly
out.MountPath = in.MountPath
out.SubPath = in.SubPath

// Disallowed fields
// This list is unnecessary, but added here for clarity
out.SubPath = ""
out.MountPropagation = nil

return out
Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/serving/fieldmask_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,13 @@ func TestVolumeMountMask(t *testing.T) {
Name: "foo",
ReadOnly: true,
MountPath: "/foo/bar",
SubPath: "baz",
}
in := &corev1.VolumeMount{
Name: "foo",
ReadOnly: true,
MountPath: "/foo/bar",
SubPath: "baz/",
SubPath: "baz",
MountPropagation: &mode,
}

Expand Down
1 change: 0 additions & 1 deletion pkg/apis/serving/k8s_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,6 @@ func TestContainerValidation(t *testing.T) {
}).ViaFieldIndex("volumeMounts", 0).Also(
apis.ErrMissingField("readOnly").ViaFieldIndex("volumeMounts", 0)).Also(
apis.ErrMissingField("mountPath").ViaFieldIndex("volumeMounts", 0)).Also(
apis.ErrDisallowedFields("subPath").ViaFieldIndex("volumeMounts", 0)).Also(
apis.ErrDisallowedFields("mountPropagation").ViaFieldIndex("volumeMounts", 0)),
}, {
name: "missing known volumeMounts",
Expand Down
11 changes: 8 additions & 3 deletions test/conformance/volumes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"path/filepath"
"testing"

"github.com/knative/serving/pkg/apis/serving/v1alpha1"
. "github.com/knative/serving/pkg/reconciler/testing"
"github.com/knative/serving/test"

Expand Down Expand Up @@ -129,15 +130,19 @@ func TestSecretVolume(t *testing.T) {
defer cleanup()
test.CleanupOnInterrupt(cleanup)

withVolume := WithVolume("asdf", filepath.Dir(test.HelloVolumePath), corev1.VolumeSource{
withVolume := WithVolume("asdf", "overwritten below", corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: secret.Name,
},
})
withSubpath := func(svc *v1alpha1.Service) {
vm := &svc.Spec.Template.Spec.Containers[0].VolumeMounts[0]
vm.MountPath = test.HelloVolumePath
vm.SubPath = filepath.Base(test.HelloVolumePath)
}

// Setup initial Service
if _, err := test.CreateRunLatestServiceReady(t, clients, &names, &test.Options{}, withVolume); err != nil {

if _, err := test.CreateRunLatestServiceReady(t, clients, &names, &test.Options{}, withVolume, withSubpath); err != nil {
t.Fatalf("Failed to create initial Service %v: %v", names.Service, err)
}

Expand Down
3 changes: 2 additions & 1 deletion test/test_images/hellovolume/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ spec:
image: github.com/knative/serving/test/test_images/hellovolume
volumeMounts:
- name: foo
mountPath: /hello
mountPath: /hello/world
subPath: world
volumes:
- name: foo
secret:
Expand Down