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

Set PreserveUnknownFields: false in v1 CRDs #124

Conversation

julianKatz
Copy link
Contributor

@julianKatz julianKatz commented Jun 10, 2021

Our CRDs were previously of version v1beta1. In v1beta1,
spec.PreserveUnknownFields defaulted to true. As we did not set this
value explicitly, the value was set to true.

We've now updated our CRDs to v1. In v1, spec.PreserveUnknownFields
defaults to false. In fact, it is being deprecated in favor of the more
targeted x-kubernetes-preserve-unknown-fields field.

Despite this new default, spec.PreserveUnknownFields remains true for
our CRDs, even after applying the new v1 versions. This does not cause
any bad behavior, but is incorrect. The simple fix is to set
spec.PreserveUnknownFields to false in all our CRDs.

As the Constraint kind CRD is generated in code, I've added this field
in constraint/pkg/client/crd_helpers.go.

The ConstraintTemplate CRD is generated using controller-gen, but
v0.5.0 of the tool doesn't include an annotation for that, presumably
because it's not longer the supported path for disabling pruning. So, I've
achieved the desired effect with a simple kustomize patch.

Contributes to open-policy-agent/gatekeeper#550

Signed-off-by: juliankatz juliankatz@google.com

Our CRDs were previously of version v1beta1.  In v1beta1,
spec.PreserveUnknownFields defaulted to `true`.  As we did not set this
value explicitly, the value was set to `true`.

We've now updated our CRDs to v1.  In v1, spec.PreserveUnknownFields
defaults to false.  In fact, it is being deprecated in favor of the more
targeted x-kubernetes-preserve-unknown-fields field.

Despite this new default, spec.PreserveUnknownFields remains `true` for
our CRDs, even after applying the new v1 versions.  This does not cause
any bad behavior, but is incorrect.

To fix this, we must set spec.PreserveUnknownFields to false in our
CRDs.  `controller-gen` v0.5.0 doesn't include an annotation for that,
presumably because it's not longer the supported path for disabling
pruning.  So, I've achieved the desired effect with a simple kustomize
patch.

Contributes to open-policy-agent/gatekeeper#550

Signed-off-by: juliankatz <juliankatz@google.com>
@julianKatz julianKatz force-pushed the PreserveUnknownFields-false-with-kustomize branch from d89d10d to 2073faf Compare June 10, 2021 20:43
Copy link
Contributor

@maxsmythe maxsmythe left a comment

Choose a reason for hiding this comment

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

Should we set this for the other CRDs as well?

Signed-off-by: juliankatz <juliankatz@google.com>
@codecov-commenter
Copy link

codecov-commenter commented Jun 10, 2021

Codecov Report

Merging #124 (8f1e1db) into master (5c03494) will increase coverage by 0.04%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #124      +/-   ##
==========================================
+ Coverage   44.26%   44.31%   +0.04%     
==========================================
  Files          30       30              
  Lines        2417     2419       +2     
==========================================
+ Hits         1070     1072       +2     
  Misses       1022     1022              
  Partials      325      325              
Flag Coverage Δ
unittests 44.31% <ø> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...nt/frameworks/constraint/pkg/client/crd_helpers.go 89.58% <0.00%> (+0.22%) ⬆️

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 878a63a...8f1e1db. Read the comment docs.

@julianKatz julianKatz changed the title Set PreserveUnknownFields: false in ConstraintTemplate v1 CRD Set PreserveUnknownFields: false in v1 CRDs Jun 10, 2021
@julianKatz
Copy link
Contributor Author

Should we set this for the other CRDs as well?

I've added the field to the code that generates Constraint kind CRDs. I'll make a PR in g8r as well.

Signed-off-by: juliankatz <juliankatz@google.com>
Copy link
Contributor

@maxsmythe maxsmythe left a comment

Choose a reason for hiding this comment

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

@maxsmythe
Copy link
Contributor

@ritazh @shomron @sozercan poke

@maxsmythe maxsmythe merged commit 1a90d7c into open-policy-agent:master Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants