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

CRD validation resource immutable #65973

Closed
fudali113 opened this issue Jul 9, 2018 · 58 comments
Closed

CRD validation resource immutable #65973

fudali113 opened this issue Jul 9, 2018 · 58 comments
Assignees
Labels
area/custom-resources kind/feature Categorizes issue or PR as related to a new feature. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery.

Comments

@fudali113
Copy link

Is this a BUG REPORT or FEATURE REQUEST?:
FEATURE REQUEST

Uncomment only one, leave it on its own line:

/kind bug
/kind feature
/kind feature

What happened:

What you expected to happen:

How to reproduce it (as minimally and precisely as possible):

Anything else we need to know?:

I want some of my fields to be immutable in CRD, can I do that?

Environment:

  • Kubernetes version (use kubectl version):
  • Cloud provider or hardware configuration:
  • OS (e.g. from /etc/os-release):
  • Kernel (e.g. uname -a):
  • Install tools:
  • Others:
@k8s-ci-robot k8s-ci-robot added needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. kind/feature Categorizes issue or PR as related to a new feature. labels Jul 9, 2018
@mkumatag
Copy link
Member

mkumatag commented Jul 9, 2018

/sig api-machinery

@k8s-ci-robot k8s-ci-robot added sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jul 9, 2018
@mkumatag
Copy link
Member

mkumatag commented Jul 9, 2018

what do you mean by immutable? do you want to have something you don't want to change after creating it?

@fudali113
Copy link
Author

Yes,i want to some field can't be change。Is there any way? @mkumatag

@nikhita
Copy link
Member

nikhita commented Jul 9, 2018

Yes,i want to some field can't be change。Is there any way?

No, there is no way to mark fields as immutable right now.

OpenAPI schema does have a construct called readOnly (https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#fixed-fields-20) but we don't support that right now. Would need to investigate if we could indeed support it.

/area custom-resources
/cc @sttts

@fedebongio
Copy link
Contributor

/cc @mbohlool

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Oct 7, 2018
@nikhita
Copy link
Member

nikhita commented Oct 7, 2018 via email

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Oct 7, 2018
@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 5, 2019
@zliang-min
Copy link

Will this feature be considered to be implemented? This is quite useful, just like the native objects in kubernetes, not all fields are mutable after the object is created. For CRDs, there will be no different.

@mbohlool
Copy link
Contributor

You can use admission webhooks to validate any change including making sure the field is not changed. We may consider dedicated validation webhook in future but for now Admission webhooks do the job.

@zliang-min
Copy link

For sure webhook is an option here. But IMHO webhooks are heavy (compared to specifying a field in the CRD yaml file), and most likely for more complicated cases, like the validation might involves some external API calls to some other services. It makes more sense to me that simple validations like readOnly should be handled by CRD.

@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Feb 15, 2019
@ghost
Copy link

ghost commented Mar 1, 2019

It would be fantastic to get this implemented as a none webhook based solution. The read-only could be used to allow initialization, then after the field becomes immutable.

@antonlisovenko
Copy link

I absolutely support this feature. Webhooks require long time to develop and support, but we meet the use case of immutable fields again and again, the easy way is to add the field into status and mark the CR as failed in case the spec field has diverged but putting the fields to status only to support contract is a quite ugly way

@dgoodwin
Copy link
Contributor

👍 I think this would be a very high value and logical feature to support. We've done the webhook path and indeed it was a big investment, and feels disproportionately heavy handed. All we've needed to use it for thus far was making fields immutable once set.

@sttts
Copy link
Contributor

sttts commented Mar 26, 2019

I agree this would be awesome. But for being able to do that we have to restrict the OpenAPI features in a sane way that read-only can be derived in a consistent way for every field. We are working on this.

@adevjoe
Copy link

adevjoe commented Jul 21, 2021

Any progress or design doc on this?

@ChenLingPeng
Copy link
Contributor

we need this feature

@arkhipovds
Copy link

We need this feature

@sttts
Copy link
Contributor

sttts commented Nov 9, 2021

With CEL you will be able to express immutability. cc @jpbetz @cici37

@jpbetz
Copy link
Contributor

jpbetz commented Nov 10, 2021

With CEL you will be able to express immutability. cc Joe Betz Cici Huang

We have some statements in the KEP about this:

For immutability use case, validator will have access to the existing version of the object. This will be accessible to CEL via the old identifier. ...

But this won't be in the alpha for 1.23, and we need to revisit the design and look through the edge cases a lot more carefully before we commit to implementing.

cc @liggitt

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Feb 8, 2022
@abstrask
Copy link

abstrask commented Feb 9, 2022

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Feb 9, 2022
@franpog859
Copy link

Hello, any news on this topic? It'd be great to have it!

@apelisse
Copy link
Member

apelisse commented May 5, 2022

We're working on a kep, can you share what your goals are? Now is the best time to ask! ;-)

@franpog859
Copy link

@apelisse , I'm implementing an operator that uses a CR to obtain some information needed to create/ update/ delete other different resources. Some specs of these resources are not upgradeable. I think it'd be good to make these CR fields immutable so the user cannot trigger the operator with the changes that cannot be properly maintained anyway. An error while trying to edit an immutable field would solve the problem with inconsistency between the CR and the spec of the other resources and would make the validation in the operator much easier

@apelisse
Copy link
Member

cc @alexzielenski

@jpbetz
Copy link
Contributor

jpbetz commented Jun 8, 2022

Since I don't think it's been mentioned on this issue yet, I wanted to point out that x-kubernetes-validations transition rules can be used to enforce CRD immutability. The main caveat is that the feature is currently alpha. It is slated for beta in 1.25.

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Sep 6, 2022
@m-yosefpor
Copy link

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Sep 7, 2022
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Dec 6, 2022
@apelisse
Copy link
Member

apelisse commented Dec 6, 2022

We should be able to close this now, no? I'll pro-actively close, let me know in the comments if you disagree.

@apelisse apelisse closed this as completed Dec 6, 2022
@alexzielenski
Copy link
Contributor

Relevant blog post on this topic: https://kubernetes.io/blog/2022/09/29/enforce-immutability-using-cel/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/custom-resources kind/feature Categorizes issue or PR as related to a new feature. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery.
Projects
Development

No branches or pull requests