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

Make all ContourConfig CRD fields optional #4451

Merged
merged 6 commits into from
Apr 11, 2022

Conversation

skriss
Copy link
Member

@skriss skriss commented Apr 6, 2022

  • Makes all ContourConfig CRD fields optional
  • Applies defaults internally, and overrides them with any user-specified settings
  • Documents the Contour defaults in the CRD field godoc

TODOs

  • remove kubebuilder enum constraints, replace with validation functions (copy from pkg/config) -- will likely do as a separate PR
  • more testing

// +optional
// +kubebuilder:default=false
EnableExternalNameService bool `json:"enableExternalNameService"`
EnableExternalNameService *bool `json:"enableExternalNameService,omitempty"`
Copy link
Member Author

Choose a reason for hiding this comment

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

I ended up making all boolean fields pointers. The reasoning is that, if we ever wanted to change the internal default for one of these to true, then if this weren't a pointer we'd have no way to distinguish between "user didn't provide a value for the field" and "user explicitly specified false". However, we do generally follow a pattern of boolean config fields always defaulting to false, so I'm definitely open to leaving these as non-pointers that always must default to false (it makes them easier to work with in code, fewer derefs). Looking for input.

More generally, my thinking with primitive types is - if the zero value is a valid option for the field, then the field probably should be a pointer to distinguish between "not specified" and "explicitly specified as the zero value". If the zero value is invalid, then the field doesn't need a pointer since we can assume anything with the zero value was not specified.


// Health defines the endpoints Contour uses to serve health checks.
//
// Contour's default is { address: "0.0.0.0", port: 8000 }.
Copy link
Member Author

@skriss skriss Apr 6, 2022

Choose a reason for hiding this comment

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

Since HealthConfig is a shared type, these defaults have to be documented at this level, which is a little inconsistent with other non-shared struct fields, but I think it's the best we can do? Applies to a couple other ones too, like Metrics and TLS.

Comment on lines +497 to +500
cases := map[string]struct {
getServeContext func(ctx *serveContext) *serveContext
getContourConfiguration func(cfg contour_api_v1alpha1.ContourConfigurationSpec) contour_api_v1alpha1.ContourConfigurationSpec
}{
Copy link
Member Author

Choose a reason for hiding this comment

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

I switched this test to use the pattern of "have a base config, then each test adds its own modification to that config" which I think works really well here for clarity & maintaintability and saves us ~600 lines of copy-pasted config.

Copy link
Member

Choose a reason for hiding this comment

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

yep, good stuff

@skriss skriss requested review from sunjayBhatia and youngnick April 6, 2022 15:08
@codecov
Copy link

codecov bot commented Apr 6, 2022

Codecov Report

Merging #4451 (d78a2cc) into main (b7404ee) will decrease coverage by 2.13%.
The diff coverage is 76.66%.

❗ Current head d78a2cc differs from pull request most recent head b4a95db. Consider uploading reports for the commit b4a95db to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4451      +/-   ##
==========================================
- Coverage   76.07%   73.93%   -2.14%     
==========================================
  Files         138      137       -1     
  Lines       12332    12444     +112     
==========================================
- Hits         9382     9201     -181     
- Misses       2701     3044     +343     
+ Partials      249      199      -50     
Impacted Files Coverage Δ
cmd/contour/serve.go 13.05% <2.08%> (+0.14%) ⬆️
internal/contourconfig/contourconfiguration.go 98.71% <98.34%> (-1.29%) ⬇️
cmd/contour/servecontext.go 82.66% <100.00%> (-0.29%) ⬇️
internal/featuretests/v3/featuretests.go 87.22% <100.00%> (+0.11%) ⬆️
internal/xdscache/v3/listener.go 90.65% <100.00%> (ø)
...ner/objects/rbac/serviceaccount/service_account.go 0.00% <0.00%> (-60.00%) ⬇️
internal/provisioner/objects/secret/secret.go 0.00% <0.00%> (-46.78%) ⬇️
internal/provisioner/controller/gatewayclass.go 12.82% <0.00%> (-34.19%) ⬇️
internal/provisioner/objects/rbac/role/role.go 36.84% <0.00%> (-31.58%) ⬇️
internal/provisioner/controller/gateway.go 8.07% <0.00%> (-31.06%) ⬇️
... and 10 more

Copy link
Member

@sunjayBhatia sunjayBhatia left a comment

Choose a reason for hiding this comment

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

i think the rules you described are reasonable 👍🏽 good to reduce pointer derefs/nil checks where possible and where zero values wouldn't work at all, but maintain ability to use zero values if they do make sense

@skriss
Copy link
Member Author

skriss commented Apr 6, 2022

I was able to get the provisioner updated to generate a ContourConfiguration instead of a ConfigMap, based on this PR (the provisioner work is still WIP but wasn't working prior to the ContourConfig changes): https://github.com/skriss/contour/tree/gw-provisioner-contourconfig

@skriss skriss marked this pull request as ready for review April 7, 2022 14:32
@skriss skriss requested a review from a team as a code owner April 7, 2022 14:32
@skriss
Copy link
Member Author

skriss commented Apr 7, 2022

This one should be ready for official review, ad-hoc testing looks good as well as all the E2E's and the WIP branch for the provisioner that makes use of this (and was previously not working).

I'll tackle the dropping of the kubebuilder enum constraints in a separate PR.

@skriss skriss added the release-note/minor A minor change that needs about a paragraph of explanation in the release notes. label Apr 7, 2022
Copy link
Member

@sunjayBhatia sunjayBhatia left a comment

Choose a reason for hiding this comment

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

lgtm, nice added comments in serve.go 👍🏽

skriss added 6 commits April 11, 2022 15:11
Removes all kubebuilder defaults from ContourConfig
fields and switches them to pointers with the omitempty
JSON tag to make them all fully optional. Defaults
are then applied internally by Contour.

Signed-off-by: Steve Kriss <krisss@vmware.com>
Signed-off-by: Steve Kriss <krisss@vmware.com>
Signed-off-by: Steve Kriss <krisss@vmware.com>
Signed-off-by: Steve Kriss <krisss@vmware.com>
Signed-off-by: Steve Kriss <krisss@vmware.com>
Signed-off-by: Steve Kriss <krisss@vmware.com>
@skriss
Copy link
Member Author

skriss commented Apr 11, 2022

rebased.

@skriss skriss merged commit a4478d6 into projectcontour:main Apr 11, 2022
@skriss skriss deleted the contourconfig branch April 11, 2022 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note/minor A minor change that needs about a paragraph of explanation in the release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants