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 pvc support #12458

Merged
merged 9 commits into from
Jan 19, 2022
Merged

Add pvc support #12458

merged 9 commits into from
Jan 19, 2022

Conversation

skonto
Copy link
Contributor

@skonto skonto commented Dec 23, 2021

Part of the work in #12438

  • Adds support for PVCs.
  • Introduces two feature flags as described in the related feature doc:
 kubernetes.podspec-persistent-volume-claim
 kubernetes.podspec-persistent-volume-write

Release note

We're experimenting with PVC support behind the feature flags `kubernetes.podspec-persistent-volume-claim` `kubernetes.podspec-persistent-volume-write`

@knative-prow-robot knative-prow-robot added area/API API objects and controllers size/L Denotes a PR that changes 100-499 lines, ignoring generated files. area/networking area/test-and-release It flags unit/e2e/conformance/perf test issues for product features labels Dec 23, 2021
@skonto skonto changed the title Add pvc support [wip] Add pvc support Dec 23, 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 Dec 23, 2021
@codecov
Copy link

codecov bot commented Dec 23, 2021

Codecov Report

Merging #12458 (da63dcb) into main (ee55bd0) will decrease coverage by 0.03%.
The diff coverage is 85.71%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #12458      +/-   ##
==========================================
- Coverage   87.46%   87.42%   -0.04%     
==========================================
  Files         195      195              
  Lines        9686     9720      +34     
==========================================
+ Hits         8472     8498      +26     
- Misses        930      937       +7     
- Partials      284      285       +1     
Impacted Files Coverage Δ
pkg/apis/serving/v1/revision_defaults.go 97.22% <0.00%> (ø)
pkg/apis/serving/k8s_validation.go 93.61% <84.84%> (-0.08%) ⬇️
pkg/apis/config/features.go 95.83% <100.00%> (+0.37%) ⬆️
pkg/apis/serving/fieldmask.go 95.13% <100.00%> (+0.06%) ⬆️
pkg/autoscaler/statforwarder/forwarder.go 88.88% <0.00%> (-7.41%) ⬇️
pkg/autoscaler/scaling/multiscaler.go 87.27% <0.00%> (-1.82%) ⬇️
pkg/activator/net/revision_backends.go 91.73% <0.00%> (-0.87%) ⬇️
pkg/autoscaler/statforwarder/leases.go 76.97% <0.00%> (+1.43%) ⬆️

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 ee55bd0...da63dcb. Read the comment docs.

limitations under the License.
*/

package helpers
Copy link
Contributor Author

Choose a reason for hiding this comment

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

need this otherwise we end up with a cycle deps issue.

@skonto skonto changed the title [wip] Add pvc support Add pvc support Dec 27, 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 Dec 27, 2021
@skonto
Copy link
Contributor Author

skonto commented Dec 27, 2021

/cc @julz @dprotaso

@skonto
Copy link
Contributor Author

skonto commented Jan 3, 2022

@julz @dprotaso happy new year! Gentle ping for review :)

# Controls whether persistent volumes support is enabled or not.
# 1. Enabled: enabling persistent volumes support
# 2. Disabled: disabling persistent volumes support
kubernetes.podspec-persistent-volumes-claims: "disabled"
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
kubernetes.podspec-persistent-volumes-claims: "disabled"
kubernetes.podspec-persistent-volume-claims: "disabled"

think this is singular in the spec

Copy link
Member

Choose a reason for hiding this comment

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

.. though then it wouldn't match podspec-persistent-volumes-write so maybe your way is better even if inconsistent. hm :(.

Copy link
Contributor Author

@skonto skonto Jan 11, 2022

Choose a reason for hiding this comment

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

Yeah I thought too about the naming inconsistency. I dont have a better option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I switched to:

 kubernetes.podspec-persistent-volume-claim
 kubernetes.podspec-persistent-volume-write

@@ -0,0 +1,42 @@
/*
Copyright 2021 The Knative Authors
Copy link
Member

Choose a reason for hiding this comment

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

Guess this is 2022 now!

Suggested change
Copyright 2021 The Knative Authors
Copyright 2022 The Knative Authors

minGroupID, maxGroupID = 0, math.MaxInt32
minUserID, maxUserID = 0, math.MaxInt32
minGroupID, maxGroupID = 0, math.MaxInt32
PodSpecPersistenceVolumesWriteAnnotation = "features.knative.dev/podspec-persistence-volumes-write"
Copy link
Member

Choose a reason for hiding this comment

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

I think this was "persistent" above

Suggested change
PodSpecPersistenceVolumesWriteAnnotation = "features.knative.dev/podspec-persistence-volumes-write"
PodSpecPersistentVolumesWriteAnnotation = "features.knative.dev/podspec-persistent-volumes-write"

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, will change.

@@ -109,6 +112,32 @@ func ValidateVolumes(ctx context.Context, vs []corev1.Volume, mountedVolumes set
return volumes, errs
}

func shouldAllowPersistenVolumeClaims(ctx context.Context, volume corev1.VolumeSource, features *config.Features) *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.

Suggested change
func shouldAllowPersistenVolumeClaims(ctx context.Context, volume corev1.VolumeSource, features *config.Features) *apis.FieldError {
func shouldAllowPersistentVolumeClaims(ctx context.Context, volume corev1.VolumeSource, features *config.Features) *apis.FieldError {

@@ -109,6 +112,32 @@ func ValidateVolumes(ctx context.Context, vs []corev1.Volume, mountedVolumes set
return volumes, errs
}

func shouldAllowPersistenVolumeClaims(ctx context.Context, volume corev1.VolumeSource, features *config.Features) *apis.FieldError {
var errs *apis.FieldError
if volume.PersistentVolumeClaim != nil {
Copy link
Member

Choose a reason for hiding this comment

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

could turn this in to a guard clause and exit immediately if nil, then the rest can be outdented

Comment on lines 122 to 125
var isWriteAllowed bool
if features.PodSpecPersistentVolumesWrite == config.Enabled {
isWriteAllowed = true
}
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
var isWriteAllowed bool
if features.PodSpecPersistentVolumesWrite == config.Enabled {
isWriteAllowed = true
}
isWriteAllowed := features.PodSpecPersistentVolumesWrite == config.Enabled

@@ -36,7 +37,7 @@ func (c *Configuration) Validate(ctx context.Context) (errs *apis.FieldError) {
errs = errs.ViaField("metadata")

ctx = apis.WithinParent(ctx, c.ObjectMeta)
errs = errs.Also(c.Spec.Validate(apis.WithinSpec(ctx)).ViaField("spec"))
errs = errs.Also(c.Spec.Validate(helpers.WithAnnotations(apis.WithinSpec(ctx), c.Annotations)).ViaField("spec"))
Copy link
Member

Choose a reason for hiding this comment

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

wonder if we could use apis.ParentMeta to avoid the extra helper pkg here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me try it, should work I think.

}},
cfgOpts: []configOption{withPodSpecPersistentVolumesClaimsEnabled(), withPodSpecPersistentVolumesWriteAllowed()},
want: &apis.FieldError{
Message: `Persistent volumes write support is off, but found Persistent Volume claim myclaim that is not read-only`,
Copy link
Member

Choose a reason for hiding this comment

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

fwiw I'm not sure I understand the point of having an annotation for this. IIUC the only case where a user should be able to set it to true is if the feature is "allowed", but if the feature is allowed why don't we just directly let them set the ReadOnly field to false without an annotation? Why would someone add ReadOnly: false and add the annotation as disabled (or, equivalently, not add it)?

Copy link
Contributor Author

@skonto skonto Jan 11, 2022

Choose a reason for hiding this comment

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

My rationale is that from an admin perspective when deploying many apps you might want to have explicit control on what apps have write access and have an easy way to mark/list them so and restrict them per case. This is due to the implications that volume write access has for the serverless model. Of course you can always implement this externally to Knative via custom tooling, annotations etc so I agree using ReadOnly could be enough in that case. I can remove it. wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the annotation if we find it useful can be added later on.

import "context"

type (
revCtxKey struct{}
Copy link
Contributor

Choose a reason for hiding this comment

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

wouldn't it be better to call it annoCtxKey ? Not sure how this helper is related to revisions 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.

Removed that part.

)

type revCtx struct {
anns map[string]string
Copy link
Contributor

Choose a reason for hiding this comment

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

would prefer annotations (or annos) but as its a private I leave it up to you

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed that part as suggested by @julz .

@skonto
Copy link
Contributor Author

skonto commented Jan 11, 2022

@julz I removed the annotation and have now simpler name for the feature attributes, no plural.

Comment on lines 119 to 120
errs = errs.Also(&apis.FieldError{Message: fmt.Sprintf("Persistent volumes claims support is disabled, "+
"but found Persistent Volume Claim %s", volume.PersistentVolumeClaim.ClaimName)})
Copy link
Contributor

Choose a reason for hiding this comment

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

Another nit pick, sorry ...

Suggested change
errs = errs.Also(&apis.FieldError{Message: fmt.Sprintf("Persistent volumes claims support is disabled, "+
"but found Persistent Volume Claim %s", volume.PersistentVolumeClaim.ClaimName)})
errs = errs.Also(&apis.FieldError{Message: fmt.Sprintf("Persistent volume claim support is disabled, "+
"but found persistent volume claim %s", volume.PersistentVolumeClaim.ClaimName)})

(the capitalization should be consistent, I would prefer to user lower case for 'persistent volume claim' and camel-case for PersistenceVolumeClaim)

Copy link
Contributor Author

@skonto skonto Jan 12, 2022

Choose a reason for hiding this comment

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

@rhuss Here you suggested the opposite no? I changed it due to that comment. I guess this is an update to that comment?

Copy link
Contributor Author

@skonto skonto Jan 12, 2022

Choose a reason for hiding this comment

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

Btw Persistent Volume Claim refers to the K8s api attribute. Persistent volumes claims support refers to the feature of supporting this type of volumes. Anyway I can change. Btw there is no PersistenceVolumeClaim.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

@rhuss Here you suggested the opposite no? I changed it due to that comment. I guess this is an update to that comment?

Yep, for me, it's important to be consistent (it doesn't make sense to reference the K8s API attribute (which btw IMO is PersistentVolumeClaim and the feature in the error message (actually the feature is disabled, not the API attribute).

Also (as @julz mentioned) persistent volumes claims sounds incorrect with the double plural (regardless of the arguments above)

@skonto
Copy link
Contributor Author

skonto commented Jan 12, 2022

   image_pull_error_test.go:86: Failed to validate revision state: the Revision image-pull-error-cerabxvl-00001 ReadyCondition = (Reason="Unschedulable", Message="0/2 nodes are available: 1 Insufficient cpu, 1 node(s) had taint {node-role.kubernetes.io/master: }, that the pod didn't tolerate."), wantReasons: [ImagePullBackOff ErrImagePull]

@skonto
Copy link
Contributor Author

skonto commented Jan 12, 2022

/retest

@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 12, 2022
@knative-prow-robot knative-prow-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 13, 2022
@skonto
Copy link
Contributor Author

skonto commented Jan 13, 2022

@dprotaso @julz gentle ping :)

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.

nits

@@ -109,6 +110,24 @@ func ValidateVolumes(ctx context.Context, vs []corev1.Volume, mountedVolumes set
return volumes, errs
}

func shouldAllowPersistentVolumeClaims(volume corev1.VolumeSource, features *config.Features) *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.

bit of a nit, but given I think this should probably be validatePersistentVolumeClaims since it's not a boolean check / returns apis.FieldError

if len(specified) == 0 {
fieldPaths := []string{"secret", "configMap", "projected"}
cfg := config.FromContextOrDefaults(ctx)
if cfg.Features.PodSpecVolumesEmptyDir == config.Enabled {
fieldPaths = append(fieldPaths, "emptyDir")
}
if cfg.Features.PodSpecPersistentVolumeClaim == config.Enabled {
fieldPaths = append(fieldPaths, "persistenVolumeClaim")
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
fieldPaths = append(fieldPaths, "persistenVolumeClaim")
fieldPaths = append(fieldPaths, "persistentVolumeClaim")

Copy link
Contributor Author

@skonto skonto Jan 13, 2022

Choose a reason for hiding this comment

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

Persistent typo:) My bad will fix.

@@ -142,12 +161,20 @@ func validateVolume(ctx context.Context, volume corev1.Volume) *apis.FieldError
specified = append(specified, "emptyDir")
errs = errs.Also(validateEmptyDirFields(vs.EmptyDir).ViaField("emptyDir"))
}

if vs.PersistentVolumeClaim != nil {
specified = append(specified, "persistentVolumeClaim")
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if we should call shouldAllowPersistentVolumeClaims->validatePersistentVolumeClaims here (rather than in ValidateVolumes) to be consistent with the other volume types above

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 makes sense will switch to that.

Copy link
Member

Choose a reason for hiding this comment

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

did you miss this one?

Copy link
Contributor Author

@skonto skonto Jan 18, 2022

Choose a reason for hiding this comment

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

@julz this part is about validating the volume itself wrt to K8s reqs among others. On the other hand, validatePersistentVolumeClaims is related to whether we should allow the specific type of volume wrt to the related Serving feature. That is why I used the name shouldAllowPersistentVolumeClaims similarly to what we have for emptydir.
However in general we could move this code part

if volume.EmptyDir != nil && features.PodSpecVolumesEmptyDir != config.Enabled {
errs = errs.Also((&apis.FieldError{Message: fmt.Sprintf("EmptyDir volume support is disabled, "+
"but found EmptyDir volume %s", volume.Name)}).ViaIndex(i))
}
errs = errs.Also(validatePersistentVolumeClaims(volume.VolumeSource, features).ViaIndex(i))
if _, ok := volumes[volume.Name]; ok {
errs = errs.Also((&apis.FieldError{
Message: fmt.Sprintf("duplicate volume name %q", volume.Name),
Paths: []string{"name"},
}).ViaIndex(i))
}
if !mountedVolumes.Has(volume.Name) {
errs = errs.Also((&apis.FieldError{
Message: fmt.Sprintf("volume with name %q not mounted", volume.Name),
Paths: []string{"name"},
}).ViaIndex(i))
}

in validateVolume. It does not make sense to do it only for pvcs because the same concept applies for emptydir. Personally I find this ok as is and the name validatePersistentVolumeClaims a bit misleading in terms of what we are validating (k8s specs va something else). Should I move the whole part?

Copy link
Contributor Author

@skonto skonto Jan 18, 2022

Choose a reason for hiding this comment

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

moved emptyDir & pvc related checks to the volumeValidate func

@skonto
Copy link
Contributor Author

skonto commented Jan 13, 2022

    image_pull_error_test.go:86: Failed to validate revision state: the Revision image-pull-error-jiiucylu-00001 ReadyCondition = (Reason="Unschedulable", Message="0/2 nodes are available: 1 Insufficient cpu, 1 node(s) had taint {node-role.kubernetes.io/master: }, that the pod didn't tolerate."), wantReasons: [ImagePullBackOff ErrImagePull] ```

@skonto
Copy link
Contributor Author

skonto commented Jan 13, 2022

/retest

@skonto
Copy link
Contributor Author

skonto commented Jan 14, 2022

@julz ready. :)

@skonto
Copy link
Contributor Author

skonto commented Jan 17, 2022

@julz gentle ping.

@skonto
Copy link
Contributor Author

skonto commented Jan 18, 2022

@dprotaso @julz gentle ping.

@skonto
Copy link
Contributor Author

skonto commented Jan 18, 2022

@julz I addressed the last pending issue, pls review.

@skonto
Copy link
Contributor Author

skonto commented Jan 19, 2022

/retest

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

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 19, 2022
@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 Jan 19, 2022
@knative-prow-robot knative-prow-robot merged commit 0682e94 into knative:main Jan 19, 2022
@dprotaso dprotaso added this to the v1.2.0 milestone Jan 26, 2022
skonto added a commit to skonto/serving that referenced this pull request Mar 10, 2022
* add pvc support

* fix header

* fix fmt

* simplify implementation

* fixes

* fix msg

* improve test names

* nits

* more fixes
skonto added a commit to skonto/serving that referenced this pull request Mar 11, 2022
* add pvc support

* fix header

* fix fmt

* simplify implementation

* fixes

* fix msg

* improve test names

* nits

* more fixes
openshift-merge-robot pushed a commit to openshift/knative-serving that referenced this pull request Mar 15, 2022
* Add pvc support (knative#12458)

* add pvc support

* fix header

* fix fmt

* simplify implementation

* fixes

* fix msg

* improve test names

* nits

* more fixes

* Add pvc e2e test (knative#12547)

* add pvc e2e test

* fmt

* fix comment

* fix pvc ns

* add fsGroup

* add flag

* fix typo

* fixes

* fix style

* skip pvc setup in upgrade tests

* Rename test image to volumes from emptydir (#1052)

* fix volumes path & dockerfile

* run pvc test

* enable alpha

Co-authored-by: Kenjiro Nakayama <[email protected]>
skonto added a commit to openshift/knative-serving that referenced this pull request Apr 4, 2022
* Add pvc support (knative#12458)

* add pvc support

* fix header

* fix fmt

* simplify implementation

* fixes

* fix msg

* improve test names

* nits

* more fixes

* Add pvc e2e test (knative#12547)

* add pvc e2e test

* fmt

* fix comment

* fix pvc ns

* add fsGroup

* add flag

* fix typo

* fixes

* fix style

* skip pvc setup in upgrade tests

* Rename test image to volumes from emptydir (#1052)

* fix volumes path & dockerfile

* run pvc test

* enable alpha

Co-authored-by: Kenjiro Nakayama <[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 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.

None yet

5 participants