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 volume type #11669

Merged
merged 3 commits into from
Jul 18, 2021

Conversation

skonto
Copy link
Contributor

@skonto skonto commented Jul 13, 2021

Part of work in #11664

Proposed Changes

  • Adds the required feature flag kubernetes.podspec-volumes-emptydir, updates the related CRD and apis.
  • Updates related unit tests
  • Validates EmptyDir contents. A bit stricter with the negative values compared to what K8s does here.

Tested manually, test cases and results here.

/cc @dprotaso @julz @markusthoemmes

@google-cla google-cla bot added the cla: yes Indicates the PR's author has signed the CLA. label Jul 13, 2021
@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. area/API API objects and controllers area/networking area/test-and-release It flags unit/e2e/conformance/perf test issues for product features labels Jul 13, 2021
@codecov
Copy link

codecov bot commented Jul 13, 2021

Codecov Report

Merging #11669 (6392811) into main (0b09cdd) will decrease coverage by 0.04%.
The diff coverage is 77.41%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #11669      +/-   ##
==========================================
- Coverage   87.82%   87.78%   -0.05%     
==========================================
  Files         190      190              
  Lines        9249     9275      +26     
==========================================
+ Hits         8123     8142      +19     
- Misses        876      879       +3     
- Partials      250      254       +4     
Impacted Files Coverage Δ
pkg/apis/serving/k8s_validation.go 96.12% <69.56%> (-1.84%) ⬇️
pkg/apis/config/features.go 94.73% <100.00%> (+0.29%) ⬆️
pkg/apis/serving/fieldmask.go 95.01% <100.00%> (+0.10%) ⬆️
pkg/reconciler/configuration/configuration.go 84.61% <0.00%> (-2.31%) ⬇️
pkg/reconciler/revision/background.go 89.58% <0.00%> (-2.09%) ⬇️
pkg/autoscaler/statforwarder/processor.go 94.44% <0.00%> (+5.55%) ⬆️
pkg/autoscaler/statforwarder/forwarder.go 96.29% <0.00%> (+5.55%) ⬆️

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 0b09cdd...6392811. Read the comment docs.

@@ -9,6 +9,7 @@ k8s.io/api/core/v1.VolumeSource:
- Secret
- ConfigMap
- Projected
- EmptyDir
Copy link
Contributor

Choose a reason for hiding this comment

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

We should add a preserveUnknownFields: true # for feature flagged fields here in accordance with the other types. So far, all of the fields that require a feature flag are not actually in the schema but allowed this way.

Copy link
Contributor Author

@skonto skonto Jul 15, 2021

Choose a reason for hiding this comment

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

Ok yes let me try that, want to check what it means from a validation perspective.

Copy link
Contributor

@markusthoemmes markusthoemmes left a comment

Choose a reason for hiding this comment

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

a few drive-by comments. Looks good overall.

/assign @dprotaso

@@ -72,7 +73,8 @@ func NewFeaturesConfigFromMap(data map[string]string) (*Features, error) {
asFlag("kubernetes.containerspec-addcapabilities", &nc.ContainerSpecAddCapabilities),
asFlag("kubernetes.podspec-tolerations", &nc.PodSpecTolerations),
asFlag("tag-header-based-routing", &nc.TagHeaderBasedRouting),
asFlag("autodetect-http2", &nc.AutoDetectHTTP2)); err != nil {
asFlag("autodetect-http2", &nc.AutoDetectHTTP2),
asFlag("kubernetes.podspec-volumes-emptydir", &nc.PodSpecVolumesEmptyDir)); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: group with the others?

@@ -97,6 +99,7 @@ type Features struct {
PodSpecTolerations Flag
TagHeaderBasedRouting Flag
AutoDetectHTTP2 Flag
PodSpecVolumesEmptyDir Flag
Copy link
Contributor

Choose a reason for hiding this comment

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

same nit as above.

Comment on lines 91 to 92
if volume.EmptyDir != nil {
if features.PodSpecVolumesEmptyDir != config.Enabled {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if volume.EmptyDir != nil {
if features.PodSpecVolumesEmptyDir != config.Enabled {
if volume.EmptyDir != nil && features.PodSpecVolumesEmptyDir != config.Enabled {

@@ -57,6 +58,7 @@ func VolumeSourceMask(in *corev1.VolumeSource) *corev1.VolumeSource {
out.Secret = in.Secret
out.ConfigMap = in.ConfigMap
out.Projected = in.Projected
out.EmptyDir = in.EmptyDir
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason we don't check the feature flag here like we do for example for the SecurtityContext types?

Copy link
Contributor Author

@skonto skonto Jul 15, 2021

Choose a reason for hiding this comment

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

A few lines above before a volumeValidation call is done, we check the features flags and emit an error.
Creating more errors from that point on seemed verbose to me. Otherwise we could create two errors (volumeMask and volumeSourceMask) and avoid the top one or have them all anyway.

@@ -131,3 +131,8 @@ data:
# 1. Enabled: http2 connection will be attempted via upgrade.
# 2. Disabled: http2 connection will only be attempted when port name is set to "h2c".
autodetect-http2: "disabled"

# Controls whether volume supporty for EmptyDir is enabled or not.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# Controls whether volume supporty for EmptyDir is enabled or not.
# Controls whether volume support for EmptyDir is enabled or not.

for i, volume := range vs {
// skip validating empty dir volumes if the feature is not enabled
Copy link
Member

Choose a reason for hiding this comment

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

Im not sure I understand this comment; we skip validating if the feature (that is, allowing this type of volume) is enabled. (If the feature is disabled then we DO validate that the volume is not there). Is the comment supposed to be further down maybe, above the validateEmptyDirFields line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah this needs to be removed initially I had a different logic here.

if len(specified) == 0 {
errs = errs.Also(apis.ErrMissingOneOf("secret", "configMap", "projected"))
errs = errs.Also(apis.ErrMissingOneOf("secret", "configMap", "projected", "emptyDir"))
Copy link
Member

Choose a reason for hiding this comment

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

presumably "emptydir" should only be in this list if the flag is enabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

correct

@dprotaso
Copy link
Member

A question for everyone (@julz, @skonto, @markusthoemmes) - what do people thing about allowing emptyDir without then need for a feature flag?

@markusthoemmes
Copy link
Contributor

Personally, I'm game, but what are the ramifications of that? Do we need to change specs?

@julz
Copy link
Member

julz commented Jul 14, 2021

interesting! I'm pretty ok with it, on balance, from a security perspective: it's technically more surface area, but not dramatically (although as it happens there was a recent upstream cve that not supporting arbitrary volumes meant we weren't exposed to).

Thinking out loud it does seems possible though to imagine a more opinionated administrator wanting to turn this off it in order to prevent patterns that might be difficult to support (like downloading models on startup), and if we add it without a feature flag then as @markusthoemmes says arguably we should probably add it to the spec, and it may not be a feature all implementations could support so.. I'd probably vote for keeping it flagged, though not very strongly and I'm super ok going another way if y'all disagree.

(I do wish we could have a more generic way to exclude fields so we could get out of the PodSpec validation business; maybe the openapi stuff eventually?..)

@dprotaso
Copy link
Member

dprotaso commented Jul 14, 2021

Do we need to change specs?

So the specs are more about conformance - and technically the OSS implementation can be a superset of that.

ie. We surface replica counts in the revision status though it's not in the spec at this moment. When we bring that to the KTC it could be veto'd by a member. Similarly this is the same case with multiple containers.

@dprotaso
Copy link
Member

My motivation for emptyDir not being behind a feature flag is because I think it'll help support multi-container use cases - ie. IPC via a socket or a named pipe

@dprotaso
Copy link
Member

I'm ok being conservative and having the flag to introduce this feature. ie. I'm not sure there are resourceLimits on emptyDir volumes etc.

But long term I think it's beneficial to open it up

@dprotaso
Copy link
Member

@julz
Copy link
Member

julz commented Jul 14, 2021

oh interesting you can have limits and requests on ephemeral storage

Yah I actually double-checked that before writing the sentence about being ok with it from a security perspective 😇

@skonto
Copy link
Contributor Author

skonto commented Jul 15, 2021

I would vote to keep it flagged but open it up later for sure (if we see no issues). Btw if an emptyDir should not be allowed in an app it could be caught at the deployment level eg. yaml file when people submit code or by setting a podSecurityPolicy that does not allow this volume type (same approach to avoid hostPath mounts in arbitrary pods). However, the flag is an easier way to do so in any case (but not that flexible as it is an on/off approach).

@dprotaso
Copy link
Member

Sounds good

@skonto skonto force-pushed the add_emptydir_support branch from 943b8c9 to 6392811 Compare July 16, 2021 11:33
@skonto
Copy link
Contributor Author

skonto commented Jul 16, 2021

Ready for another review round.

@dprotaso
Copy link
Member

/lgtm
/approve

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dprotaso, 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 18, 2021
@knative-prow-robot knative-prow-robot merged commit 317cde6 into knative:main Jul 18, 2021
@mattmoor
Copy link
Member

Awesome to see this. I was just asking in slack about this because I want it for something I'm playing with!

🎉

markusthoemmes pushed a commit to markusthoemmes/knative-serving that referenced this pull request Aug 20, 2021
* support emptyDir volume

* fixes

* reorder feature
markusthoemmes pushed a commit to markusthoemmes/knative-serving that referenced this pull request Aug 23, 2021
* support emptyDir volume

* fixes

* reorder feature
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/networking 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.

6 participants