controller-tools
controller-tools copied to clipboard
preserveUnknownFields=false doesn't work with crdVersions=v1
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
I'm hitting the same issue, any ideas?
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).
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
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
Any updates on 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
@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.
@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.
/reopen
@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.
/assign
I took a stab at this, but it's a bit hairier than I expected.
Basically, the root cause is that CRDSpec.PreserveUnknownFields went from a type *bool in v1beta1 to a type bool in v1. The default value for a bool is false and because the field has an omitempty tag on it, a false value will never be written out to the yaml.
Since the object that gets written to yaml has the correct value of false, there's no easy way to get it to show up. I've hacked together a proof-of-concept of one way to do this that involves aliasing the apiext.CustomResourceDefinition type in order to start a conversation, but it's pretty icky and I'm not sure the maintainers will go for it. Check it out at https://github.com/kubernetes-sigs/controller-tools/pull/590
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/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas 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
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/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas applied, the issue is closed
You can:
- Mark this issue or PR as fresh with
/remove-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 rotten
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/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas 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-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/staleis applied- After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied- After 30d of inactivity since
lifecycle/rottenwas applied, the issue is closedYou 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.
Still hitting this problem, though I was able to manually edit the CRD to set it to false
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
/remove-lifecycle rotten /reopen
@AlexanderYastrebov Feel free to open a PR (please with a corresponding test)
@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.
Feel free to open a PR (please with a corresponding test)
Ok, created #912
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/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas 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
@sbueringer @alvaroaleman I guess we can close this as done?
Yes we can, thx!
/close
@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.