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

Update Knative Serving schema #13095

Merged
merged 6 commits into from
Jul 11, 2022
Merged

Update Knative Serving schema #13095

merged 6 commits into from
Jul 11, 2022

Conversation

dprotaso
Copy link
Member

@dprotaso dprotaso commented Jul 6, 2022

Part of #11980

Proposed Changes

  • I've pushed x-kubernetes-preserve-unknown-fields markers further down in the schema to the properties behind feature flags
  • This should prevent people from supplying a bad known property - ie. misspelling containerConcurrency
  • I've omitted the schema for features behind flags - they're essentially the wild west
  • After this I'll follow up with a PR to relax our webhooks to not error out on unknown properties

Release Note

CRD schemas have been updated and `x-kubernetes-preserve-unknown-fields` is now only specified for attributes behind feature flags

@knative-prow knative-prow bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. 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 labels Jul 6, 2022
@dprotaso
Copy link
Member Author

dprotaso commented Jul 6, 2022

I'm also seeing if we can upstream our controller-tools changes - kubernetes-sigs/controller-tools#705

@dprotaso
Copy link
Member Author

dprotaso commented Jul 6, 2022

/assign @nader-ziada

@codecov
Copy link

codecov bot commented Jul 6, 2022

Codecov Report

Merging #13095 (ec4b0c8) into main (752c336) will decrease coverage by 0.28%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main   #13095      +/-   ##
==========================================
- Coverage   87.05%   86.77%   -0.29%     
==========================================
  Files         197      197              
  Lines       14443    14477      +34     
==========================================
- Hits        12573    12562      -11     
- Misses       1576     1619      +43     
- Partials      294      296       +2     
Impacted Files Coverage Δ
pkg/apis/serving/fieldmask.go 95.55% <ø> (-0.08%) ⬇️
pkg/reconciler/revision/cruds.go 62.50% <0.00%> (-14.43%) ⬇️
pkg/reconciler/revision/reconcile_resources.go 66.88% <0.00%> (-13.92%) ⬇️
pkg/reconciler/revision/revision.go 92.13% <0.00%> (-4.34%) ⬇️
pkg/reconciler/configuration/configuration.go 83.67% <0.00%> (-1.54%) ⬇️
cmd/queue/main.go 0.64% <0.00%> (ø)
cmd/activator/main.go 0.00% <0.00%> (ø)
cmd/controller/main.go 0.00% <0.00%> (ø)

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 752c336...ec4b0c8. Read the comment docs.

@nader-ziada
Copy link
Member

looks like the failures in e2e are legit

@nader-ziada
Copy link
Member

looks like the failures in e2e are legit

the serving install fails on the kind cluster before running the tests

@dprotaso
Copy link
Member Author

dprotaso commented Jul 6, 2022

Yeah looks like the generated Schema is invalid - will take a look tomorrow

@dprotaso dprotaso changed the title Update Knative Serving schema [wip] Update Knative Serving schema Jul 6, 2022
@knative-prow knative-prow bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 6, 2022
@dprotaso
Copy link
Member Author

dprotaso commented Jul 7, 2022

/test build-tests_serving_main

1 similar comment
@dprotaso
Copy link
Member Author

dprotaso commented Jul 7, 2022

/test build-tests_serving_main

@dprotaso dprotaso changed the title [wip] Update Knative Serving schema Update Knative Serving schema Jul 7, 2022
@knative-prow knative-prow bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 7, 2022
@dprotaso
Copy link
Member Author

dprotaso commented Jul 7, 2022

Just checking which version of the branch is being pulled from the go cache

/test build-tests_serving_main

@dprotaso
Copy link
Member Author

dprotaso commented Jul 8, 2022

/assign @evankanderson for conformance test changes

@nader-ziada
Copy link
Member

lgtm

Copy link
Member

@evankanderson evankanderson left a comment

Choose a reason for hiding this comment

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

Pruning seems like unexpected behavior -- for example, if I write:

...
  posts:
    - port: 5000
      name: http

Having Knative attempt to start my pod and eventually fail the health check seems less useful than "Hey dummy, what is posts, I don't know about it."

Is there a way to error on fields not in the schema?

test/conformance/runtime/container_test.go Outdated Show resolved Hide resolved
@dprotaso
Copy link
Member Author

dprotaso commented Jul 11, 2022

Is there a way to error on fields not in the schema?

Unfortunately no and to catch these errors would mean you would have to preserve fields and still validate with webhooks. Also to preserve unknown fields while having the entire spec defined means you would need excess x-kubernetes-preserve-unknown-fields: true properties set at every node in the schema.

(with pruning) It does buy contributors some benefits

  • we can introduce a new field and use it in the same release
  • we have move validation logic out of the webhook and into the schema (so it's enforced by the k8s api server)
  • having the flushed out schema could introduce some client side validation (ie. non-go clients)

@dprotaso
Copy link
Member Author

/assign @psschwei since Nader's OOO

@evankanderson
Copy link
Member

Testing this, I followed the structural schema validation example, and defined the CRD they mentioned. I then defined a custom resources where I mis-spelled replicas as replica:

apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:
  name: my-new-cron-object
spec:
  cronSpec: "* * * * *"
  image: my-awesome-cron-image
  replica: 15

Running kubectl apply on these resource produces the following error:

error: error validating "/tmp/cr.yaml": error validating data: ValidationError(CronTab.spec): unknown field "replica" in com.example.stable.v1.CronTab.spec; if you choose to ignore these errors, turn validation off with --validate=false

But, it turns out this error is client-side, and if I pass --validate=false, the field is silently cleared from the resource without error and accepted by the apiserver.

Since the Knative spec was an attempt to back-document the Kubernetes apiserver behavior, I think we'd have to give this one a pass for now, but I'd love it if @dprotaso could file an issue upstream asking for a "validation means validation, not silently make my request something different" feature.

@dprotaso
Copy link
Member Author

Created an upstream issue here: kubernetes/kubernetes#111074

@evankanderson
Copy link
Member

/approve
/lgtm

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label Jul 11, 2022
@knative-prow
Copy link

knative-prow bot commented Jul 11, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dprotaso, evankanderson

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 knative-prow bot merged commit e701a33 into knative:main Jul 11, 2022
@dprotaso dprotaso deleted the schema branch July 11, 2022 20:27
Muhammad-Raiyan added a commit to Muhammad-Raiyan/serving that referenced this pull request Feb 3, 2024
fix (issue knative#14231): DEVELOPMENT.md is outdated
 
* As part of Fix knative#13095 it seems like both allowedFields from preserveUnknownFields in schemapatch-config.yaml. Hence, updated DEVELOPMENT.md to drop references to these 2 fields.
Muhammad-Raiyan added a commit to Muhammad-Raiyan/serving that referenced this pull request Feb 3, 2024
Updated DEVELOPMENT.md

* As part of Fix knative#13095 it seems like both `allowedFields` and `preserveUnknownFields` were removed from [schemapatch-config.yaml](https://github.com/knative/serving/blob/main/hack/schemapatch-config.yaml). Hence, updated [DEVELOPMENT.md](https://github.com/knative/serving/blob/main/DEVELOPMENT.md) to drop references to these 2 fields.
knative-prow bot pushed a commit that referenced this pull request Feb 13, 2024
…rveUnknownFields (#14865)

* Fixes #14231

Updated DEVELOPMENT.md

* As part of Fix #13095 it seems like both `allowedFields` and `preserveUnknownFields` were removed from [schemapatch-config.yaml](https://github.com/knative/serving/blob/main/hack/schemapatch-config.yaml). Hence, updated [DEVELOPMENT.md](https://github.com/knative/serving/blob/main/DEVELOPMENT.md) to drop references to these 2 fields.

* Update DEVELOPMENT.md

Documented usage of kubebuilder:validation:DropProperties
 and kubebuilder:pruning:PreserveUnknownFields with example

* Update DEVELOPMENT.md

Added comment

Co-authored-by: Paul Schweigert <[email protected]>

* Update DEVELOPMENT.md

Co-authored-by: Paul Schweigert <[email protected]>

---------

Co-authored-by: Paul Schweigert <[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 lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants