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

Add support for emptydir rw access and e2e testing #11705

Merged
merged 8 commits into from
Jul 23, 2021

Conversation

skonto
Copy link
Contributor

@skonto skonto commented Jul 21, 2021

Part of the work in #11664.

  • adds an e2e test that serves data in an emptyDir volume. Test run here. It will be run along with the rest when the feature is on by default.
  • allows rw access to emptyDir volumes only (extends logic to allow more types of volumes eg. pvc in the future).

/cc @julz @dprotaso @markusthoemmes @nak3

@knative-prow-robot knative-prow-robot added area/API API objects and controllers area/test-and-release It flags unit/e2e/conformance/perf test issues for product features size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 21, 2021
@google-cla google-cla bot added the cla: yes Indicates the PR's author has signed the CLA. label Jul 21, 2021
@skonto skonto changed the title Add support for emptydir rw access and e2e testing [wip] Add support for emptydir rw access and e2e testing Jul 21, 2021
@knative-prow-robot knative-prow-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 21, 2021
@codecov
Copy link

codecov bot commented Jul 21, 2021

Codecov Report

Merging #11705 (3b17ad7) into main (11abffd) will increase coverage by 0.02%.
The diff coverage is 80.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #11705      +/-   ##
==========================================
+ Coverage   87.80%   87.83%   +0.02%     
==========================================
  Files         190      190              
  Lines        9275     9279       +4     
==========================================
+ Hits         8144     8150       +6     
  Misses        878      878              
+ Partials      253      251       -2     
Impacted Files Coverage Δ
pkg/apis/serving/v1/revision_defaults.go 97.05% <60.00%> (-2.95%) ⬇️
pkg/apis/serving/k8s_validation.go 96.12% <100.00%> (ø)
pkg/autoscaler/statforwarder/leases.go 78.41% <0.00%> (+1.43%) ⬆️
pkg/reconciler/configuration/configuration.go 86.15% <0.00%> (+1.53%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 11abffd...3b17ad7. Read the comment docs.

@skonto skonto force-pushed the add_e2e_empty_dir branch from 6b30d5d to adfe004 Compare July 21, 2021 13:21
@skonto
Copy link
Contributor Author

skonto commented Jul 21, 2021

/retest

@skonto skonto changed the title [wip] Add support for emptydir rw access and e2e testing Add support for emptydir rw access and e2e testing Jul 21, 2021
@knative-prow-robot knative-prow-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 21, 2021
@skonto skonto changed the title Add support for emptydir rw access and e2e testing [WIP] Add support for emptydir rw access and e2e testing Jul 21, 2021
@knative-prow-robot knative-prow-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 21, 2021
@skonto skonto changed the title [WIP] Add support for emptydir rw access and e2e testing Add support for emptydir rw access and e2e testing Jul 22, 2021
@knative-prow-robot knative-prow-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 22, 2021
@skonto
Copy link
Contributor Author

skonto commented Jul 22, 2021

/assign @dprotaso

@@ -105,8 +106,11 @@ func ValidateVolumes(ctx context.Context, vs []corev1.Volume, mountedVolumes set
}
errs = errs.Also(validateVolume(ctx, volume).ViaIndex(i))
volumes.Insert(volume.Name)
if volume.EmptyDir != nil {
nonReadOnlyVolumes.Insert(volume.Name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the variable is called nonReadOnlyVolumes, but it seems like it actually contains nonEmptyDirVolumes. When we actually use it we end up negating it again (!nonReadOnlyValumes.Has(..)) which is a lot of negations for my mind to follow and confused me a bit: maybe this could be emptyDirVolumes or allowedReadWriteVolumes or something like that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(see suggested alternative approach in 3rd comment though which makes this comment and the next redundant if it works!)

Copy link
Contributor Author

@skonto skonto Jul 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can change the name but the var contains only emptyDirs as they are the only ones which are supported and can have rw access. At least this is the intention here.

but it seems like it actually contains nonEmptyDirVolumes

Don't parse this part. Could you explain a bit more?

@@ -82,8 +82,9 @@ var (
)

// ValidateVolumes validates the Volumes of a PodSpec.
func ValidateVolumes(ctx context.Context, vs []corev1.Volume, mountedVolumes sets.String) (sets.String, *apis.FieldError) {
func ValidateVolumes(ctx context.Context, vs []corev1.Volume, mountedVolumes sets.String) (sets.String, sets.String, *apis.FieldError) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we have two sets.String in the return section now I'd probably add variable names for them and maybe add to the method comment to indicate what each is

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes ok.

volumes := make(sets.String, len(vs))
nonReadOnlyVolumes := make(sets.String)
Copy link
Member

@julz julz Jul 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thinking out loud: a nice alternative approach might be to make the return value of this method a map[string]corev1.Volume (rather than two sets.Strings each with different semantics, which is maybe a bit unwieldy and slightly hard to document). The volume.EmptyDir != nil in this method would then not be needed at all, and in validateVolumeMounts you could do: if volumes[vm.Name].EmptyDir != nil && !vm.ReadOnly (which means the logic would only be in only one place).

Copy link
Contributor Author

@skonto skonto Jul 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I also thought of returning volumes instead or some data structure but didnt want to change the signature for existing code (less changes).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right but we have to change the signature anyway since we pass two sets.Strings around everywhere now?

Copy link
Contributor Author

@skonto skonto Jul 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but didnt touch some other parts though eg. accessing the first string set stayed the same. Anyway I can take a look and refactor it ;)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heheheh yeah, worth a go anyway I think since it'd move all the logic to one place and avoid having two pass two things up and down the stack

@@ -1509,7 +1509,7 @@ func TestContainerValidation(t *testing.T) {
ctx = config.ToContext(ctx, cfg)
}

got := ValidateContainer(ctx, test.c, test.volumes)
got := ValidateContainer(ctx, test.c, test.volumes, make(sets.String))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably worth a unit test for the new behaviour here too I think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we can cover more cases there by adding a test case field.

Copy link
Member

@julz julz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! lgtm bar a formatting nit in the tests and I think it's probably worth logging the errors in the test image in this case

Comment on lines 1082 to 1091
volumes: map[string]corev1.Volume{
"the-name": {
Name: "the-name",
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: "test-cm",
}},
},
}},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

total nit, but I think for consistency the formatting here should be:

Suggested change
volumes: map[string]corev1.Volume{
"the-name": {
Name: "the-name",
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: "test-cm",
}},
},
}},
volumes: map[string]corev1.Volume{
"the-name": {
Name: "the-name",
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: "test-cm",
},
},
},
},
},

(basically line the braces up under the first column of where the opening brace is)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

})

withVolume2 := WithVolume("cache", "/cache", corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think we actually try reading/writing to this, but I guess we just want to test the validation allows this since we tested read/write on the other volume?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes to show that we can have multiple ones.

if path == "" {
path = "/data"
}
f, _ := os.OpenFile(path+"/testfile", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth logging the error here, since it may help with debugging if e.g. the volume was mounted read-only?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok let me add that

@skonto
Copy link
Contributor Author

skonto commented Jul 23, 2021

/assign @julz

Copy link
Member

@julz julz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

nice, thanks @skonto!

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 23, 2021
@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: julz, skonto

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 23, 2021
@knative-prow-robot knative-prow-robot merged commit 6447982 into knative:main Jul 23, 2021
markusthoemmes pushed a commit to markusthoemmes/knative-serving that referenced this pull request Aug 20, 2021
* add support for emptydir rw access, e2e

* fix header

* fix quantity

* set to alpha feature

* toggle feature

* fixes

* fix  fmt

* fix nit
markusthoemmes pushed a commit to markusthoemmes/knative-serving that referenced this pull request Aug 23, 2021
* add support for emptydir rw access, e2e

* fix header

* fix quantity

* set to alpha feature

* toggle feature

* fixes

* fix  fmt

* fix nit
openshift-merge-robot pushed a commit to openshift/knative-serving that referenced this pull request Aug 23, 2021
* Add support for emptyDir volume type (knative#11669)

* support emptyDir volume

* fixes

* reorder feature

* Add support for emptydir rw access and e2e testing (knative#11705)

* add support for emptydir rw access, e2e

* fix header

* fix quantity

* set to alpha feature

* toggle feature

* fixes

* fix  fmt

* fix nit

Co-authored-by: Stavros Kontopoulos <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/API API objects and controllers area/test-and-release It flags unit/e2e/conformance/perf test issues for product features cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants