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

preserveUnknownFields=false doesn't work with crdVersions=v1 #476

Closed
jonnylangefeld opened this issue Aug 22, 2020 · 25 comments
Closed

preserveUnknownFields=false doesn't work with crdVersions=v1 #476

jonnylangefeld opened this issue Aug 22, 2020 · 25 comments
Assignees
Labels
lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale.

Comments

@jonnylangefeld
Copy link

crdVersions=v1 which is the new default, doesn't work in conjunction with preserveUnknownFields=false. The spec.preserveUnknownFields simply doesn't appear in the crd. There is an integration test for v1beta1, but not for v1.

I'm running the following command in a kubebuilder repo:

controller-gen "crd:preserveUnknownFields=false,crdVersions=v1" rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases

I'm using defaults in my schema and if applying to a 1.16.13-gke.1 cluster, I get:

The CustomResourceDefinition "foo.example.com" is invalid: spec.preserveUnknownFields: Invalid value: true: must be false in order to use defaults in the schema

If I add spec.preserveUnknownFields manually to the crd it works

My workaround in the makefile right now is

yq w -i config/crd/bases/cluster.paas.getcruise.com_clusters.yaml spec.preserveUnknownFields false
@pugangxa
Copy link

pugangxa commented Sep 3, 2020

I'm hitting the same issue, any ideas?

@npiganeau
Copy link

I had the same issue here. It was an issue about upgrading from v1beta1 to v1 CRD.
The spec.preserveUnknownFields was true in the cluster (probably because that was the default in v1beta1).
When I upgraded to v1, spec.preserveUnknownFields was not set in the manifest, but because it was in the cluster, I had the spec.preserveUnknownFields: Invalid value: true: must be false in order to use defaults in the schema error.

The solution was simply to manually add spec.preserveUnknownFields: false in the generated CRD manifest and apply it once.
From then, it worked again when applying controller-gen generated manifests (without spec.preserveUnknownFields set).

@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 Dec 11, 2020
@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 Jan 10, 2021
bryanv added a commit to bryanv/vm-operator-api that referenced this issue Jan 29, 2021
Update tools to newer versions.

Note that despite preserveUnknownFields, this is not included in the
generated CRDs due to [1]. Importing our local kustomize hack to
include it here does not seem worthwhile since it is mostly an upgrade
issue.

[1] - kubernetes-sigs/controller-tools#476
bryanv added a commit to bryanv/vm-operator-api that referenced this issue Jan 29, 2021
Update tools to newer versions.

Note that despite preserveUnknownFields, this is not included in the
generated CRDs due to [1]. Importing our local kustomize hack to
include it here does not seem worthwhile since it is mostly an upgrade
issue.

[1] - kubernetes-sigs/controller-tools#476
bryanv added a commit to vmware-archive/vm-operator-api that referenced this issue Feb 1, 2021
Update tools to newer versions.

Note that despite preserveUnknownFields, this is not included in the
generated CRDs due to [1]. Importing our local kustomize hack to
include it here does not seem worthwhile since it is mostly an upgrade
issue.

[1] - kubernetes-sigs/controller-tools#476
@bhiravabhatla
Copy link

Any updates on this?

@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-contributor-experience at kubernetes/community.
/close

@k8s-ci-robot
Copy link
Contributor

@fejta-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-contributor-experience at kubernetes/community.
/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot
Copy link
Contributor

@elanv: You can't reopen an issue/PR unless you authored it or you are a collaborator.

In response to this:

/reopen
/remove-lifecycle rotten

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Mar 28, 2021
akutz pushed a commit to vmware-tanzu/vm-operator that referenced this issue Jun 3, 2021
By generating v1 instead of v1beta1, kubectl explain now works.

preserveUnknownFields is needed for explain to work when upgrading
from CRD v1beta1 to v1 but controller-gen has a bug [1] that causes
it not be included in the generated CRD yaml. Use kustomize to add
it the CRDs.

Keep the webhooks at their prior version until we decide to or must
update them. The new controller-gen defaults to newer version.

[1] - kubernetes-sigs/controller-tools#476
akutz pushed a commit to vmware-tanzu/vm-operator that referenced this issue Jun 3, 2021
By generating v1 instead of v1beta1, kubectl explain now works.

preserveUnknownFields is needed for explain to work when upgrading
from CRD v1beta1 to v1 but controller-gen has a bug [1] that causes
it not be included in the generated CRD yaml. Use kustomize to add
it the CRDs.

Keep the webhooks at their prior version until we decide to or must
update them. The new controller-gen defaults to newer version.

[1] - kubernetes-sigs/controller-tools#476
@kevindelgado
Copy link
Contributor

/reopen

@k8s-ci-robot
Copy link
Contributor

@kevindelgado: Reopened this issue.

In response to this:

/reopen

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot reopened this Jul 22, 2021
@kevindelgado
Copy link
Contributor

/assign

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active 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:

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

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

/close

@k8s-ci-robot
Copy link
Contributor

@k8s-triage-robot: Closing this issue.

In response to this:

The Kubernetes project currently lacks enough active 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:

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

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

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

akutz pushed a commit to vmware-tanzu/vm-operator that referenced this issue Sep 21, 2022
By generating v1 instead of v1beta1, kubectl explain now works.

preserveUnknownFields is needed for explain to work when upgrading
from CRD v1beta1 to v1 but controller-gen has a bug [1] that causes
it not be included in the generated CRD yaml. Use kustomize to add
it the CRDs.

Keep the webhooks at their prior version until we decide to or must
update them. The new controller-gen defaults to newer version.

[1] - kubernetes-sigs/controller-tools#476
@derekperkins
Copy link

derekperkins commented Nov 7, 2022

Still hitting this problem, though I was able to manually edit the CRD to set it to false

akutz pushed a commit to vmware-tanzu/vm-operator that referenced this issue Nov 19, 2022
Update tools to newer versions.

Note that despite preserveUnknownFields, this is not included in the
generated CRDs due to [1]. Importing our local kustomize hack to
include it here does not seem worthwhile since it is mostly an upgrade
issue.

[1] - kubernetes-sigs/controller-tools#476
akutz pushed a commit to vmware-tanzu/vm-operator that referenced this issue Dec 1, 2022
By generating v1 instead of v1beta1, kubectl explain now works.

preserveUnknownFields is needed for explain to work when upgrading
from CRD v1beta1 to v1 but controller-gen has a bug [1] that causes
it not be included in the generated CRD yaml. Use kustomize to add
it the CRDs.

Keep the webhooks at their prior version until we decide to or must
update them. The new controller-gen defaults to newer version.

[1] - kubernetes-sigs/controller-tools#476
AlexanderYastrebov added a commit to zalando-incubator/kubernetes-on-aws that referenced this issue Apr 9, 2024
Explicitly set `preserveUnknownFields: false` to enable strict
CRD validation and prohibit unknown fields in test environment first.

Conversion of CRD from v1beta1 to v1 (see #2991) resulted in
`preserveUnknownFields: true`:
```
$ kubectl --context=example get crd platformcredentialssets.zalando.org -o yaml | grep preserveUnknownFields
  preserveUnknownFields: true
    message: 'spec.preserveUnknownFields: Invalid value: true: must be false'
```
and requires explicit false value to reset.

See also kubernetes-sigs/controller-tools#476 (comment)

Signed-off-by: Alexander Yastrebov <[email protected]>
@AlexanderYastrebov
Copy link
Contributor

Now it is trivial to implement like:

$ git --no-pager diff -- pkg/crd/gen.go
diff --git a/pkg/crd/gen.go b/pkg/crd/gen.go
index 9eb4126b..cb6dd964 100644
--- a/pkg/crd/gen.go
+++ b/pkg/crd/gen.go
@@ -100,6 +100,12 @@ func transformRemoveCRDStatus(obj map[string]interface{}) error {
        return nil
 }
 
+// transformPreserveUnknownFields ensures we spec.preserveUnknownFields=false.
+func transformPreserveUnknownFields(obj map[string]interface{}) error {
+       obj["spec"].(map[interface{}]interface{})["preserveUnknownFields"] = false
+       return nil
+}
+
 func (g Generator) Generate(ctx *genall.GenerationContext) error {
        parser := &Parser{
                Collector: ctx.Collector,
@@ -171,7 +177,7 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error {
                        } else {
                                fileName = fmt.Sprintf("%s_%s.%s.yaml", crdRaw.Spec.Group, crdRaw.Spec.Names.Plural, crdVersions[i])
                        }
-                       if err := ctx.WriteYAML(fileName, headerText, []interface{}{crd}, genall.WithTransform(transformRemoveCRDStatus), genall.WithTransform(genall.TransformRemoveCreationTimestamp)); err != nil {
+                       if err := ctx.WriteYAML(fileName, headerText, []interface{}{crd}, genall.WithTransform(transformRemoveCRDStatus), genall.WithTransform(genall.TransformRemoveCreationTimestamp), genall.WithTransform(transformPreserveUnknownFields)); err != nil {
                                return err
                        }
                }

but unfortunately crd:preserveUnknownFields marker support was removed by #607

@sbueringer
Copy link
Member

/remove-lifecycle rotten
/reopen

@AlexanderYastrebov Feel free to open a PR (please with a corresponding test)

@k8s-ci-robot k8s-ci-robot reopened this Apr 9, 2024
@k8s-ci-robot
Copy link
Contributor

@sbueringer: Reopened this issue.

In response to this:

/remove-lifecycle rotten
/reopen

@AlexanderYastrebov Feel free to open a PR (please with a corresponding test)

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Apr 9, 2024
AlexanderYastrebov added a commit to AlexanderYastrebov/controller-tools that referenced this issue Apr 10, 2024
Reinstate crd:preserveUnknownFields option removed by kubernetes-sigs#607
to allow specifying the value of deprecated spec.preserveUnknownFields
CRD field.

This is useful for updating CRDs that were automatically converted from
v1beta1 version which had true as a default value and resulted in:
```
$ kubectl get crd foo.bar -o yaml | grep preserveUnknownFields
  preserveUnknownFields: true
    message: 'spec.preserveUnknownFields: Invalid value: true: must be false'
```

Fixes kubernetes-sigs#476
AlexanderYastrebov added a commit to AlexanderYastrebov/controller-tools that referenced this issue Apr 10, 2024
Reinstate crd:preserveUnknownFields option removed by kubernetes-sigs#607
to allow specifying the value of deprecated spec.preserveUnknownFields
CRD field.

This is useful for updating CRDs that were automatically converted from
v1beta1 version which had true as a default value and resulted in:
```
$ kubectl get crd foo.bar -o yaml | grep preserveUnknownFields
  preserveUnknownFields: true
    message: 'spec.preserveUnknownFields: Invalid value: true: must be false'
```

For kubernetes-sigs#476
@AlexanderYastrebov
Copy link
Contributor

Feel free to open a PR (please with a corresponding test)

Ok, created #912

AlexanderYastrebov added a commit to AlexanderYastrebov/controller-tools that referenced this issue Apr 11, 2024
Reinstate crd:preserveUnknownFields option removed by kubernetes-sigs#607
to allow specifying the value of deprecated spec.preserveUnknownFields
CRD field.

This is useful for updating CRDs that were automatically converted from
v1beta1 version which had true as a default value and resulted in:
```
$ kubectl get crd foo.bar -o yaml | grep preserveUnknownFields
  preserveUnknownFields: true
    message: 'spec.preserveUnknownFields: Invalid value: true: must be false'
```

For kubernetes-sigs#476
AlexanderYastrebov added a commit to AlexanderYastrebov/controller-tools that referenced this issue Apr 15, 2024
Reinstate crd:preserveUnknownFields option removed by kubernetes-sigs#607
to allow specifying the value of deprecated spec.preserveUnknownFields
CRD field.

This is useful for updating CRDs that were automatically converted from
v1beta1 version which had true as a default value and resulted in:
```
$ kubectl get crd foo.bar -o yaml | grep preserveUnknownFields
  preserveUnknownFields: true
    message: 'spec.preserveUnknownFields: Invalid value: true: must be false'
```

For kubernetes-sigs#476
k8s-ci-robot pushed a commit that referenced this issue Apr 19, 2024
* crd: allow specifying spec.preserveUnknownFields

Reinstate crd:preserveUnknownFields option removed by #607
to allow specifying the value of deprecated spec.preserveUnknownFields
CRD field.

This is useful for updating CRDs that were automatically converted from
v1beta1 version which had true as a default value and resulted in:
```
$ kubectl get crd foo.bar -o yaml | grep preserveUnknownFields
  preserveUnknownFields: true
    message: 'spec.preserveUnknownFields: Invalid value: true: must be false'
```

For #476

* crd: rename marker to DeprecatedV1beta1CompatibilityPreserveUnknownFields
@k8s-triage-robot
Copy link

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

This bot triages un-triaged issues 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 as fresh with /remove-lifecycle stale
  • Close this issue 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 Jul 9, 2024
@AlexanderYastrebov
Copy link
Contributor

@sbueringer @alvaroaleman I guess we can close this as done?

@sbueringer
Copy link
Member

Yes we can, thx!

/close

@k8s-ci-robot
Copy link
Contributor

@sbueringer: Closing this issue.

In response to this:

Yes we can, thx!

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale.
Projects
None yet
Development

Successfully merging a pull request may close this issue.