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

🏃mark defaulted fields as optional #2678

Conversation

sethp-nr
Copy link
Contributor

Perhaps easier to iterate on than a full kubernetes cluster

What this PR does / why we need it:

Addresses some odd defaulting behavior in the KCP webhook, as well as smoothing out some UX.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #1941

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 13, 2020
@sethp-nr
Copy link
Contributor Author

I'm not sure omitempty is going to solve our troubles here without changing some of these types to pointers. I'd like to avoid that if possible, especially for the types that already have an IsZero implementation.

What do folks think? More pointers or more json serialization code?

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 13, 2020
@sethp-nr sethp-nr changed the title wip: add integration test for defaulting webhook wip: omit fields from KubeadmConfig (and KubeadmConfigSpec) that are defaulted elsewhere Mar 13, 2020
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 13, 2020
@sethp-nr
Copy link
Contributor Author

/test pull-cluster-api-capd-e2e

@sethp-nr
Copy link
Contributor Author

sethp-nr commented Mar 14, 2020

Well, I have to say that teaching encoding/json to omit empty struct fields was both better and worse than I expected.

On one hand, the badness is almost entirely contained inside one or two files as opposed to spread out throughout the codebase.

On the other, I've done a limited survey of the code and it looks like we almost never actually use those fields from go-land, only after serializing to yaml to pass to kubeadm. At that point, the pointers are really only awkward the next time we'd need to copy over the config structures for the next kubeadm config version.

@chuckha
Copy link
Contributor

chuckha commented Mar 16, 2020

@sethp-nr this capd-e2e is failing because the kubeadm configuration is now missing kind and apiVersion

Comment on lines 50 to 52
func (ic InitConfiguration) MarshalJSON() ([]byte, error) {
return marshalJSONOmittingEmptyStructs(ic)
}
Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't need this I think, rather when we're adding omitempty, we should have a pointer

@sethp-nr
Copy link
Contributor Author

Ah, ok – I hadn't gotten to the point yet where I was running that locally. In the tests I did it was populating apiVersion but, truth be told, I couldn't figure out how my encoding code was handling embedded structs. Maybe it wasn't after all :)

After sleeping on it, I'm feeling like turning things into pointers is the better way forward anyway.

@sethp-nr
Copy link
Contributor Author

Chatted with Vince in Slack: https://kubernetes.slack.com/archives/C8TSNPY4T/p1584373580418500

Since changing to pointers is a breaking API change for go clients, I'm moving that work to a different PR. This one is going to just change the // +optional tags for kube API clients.

@sethp-nr sethp-nr force-pushed the other/kubeadm-config-defaulting-and-empties branch from b43d5d1 to 7090b93 Compare March 16, 2020 17:56
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Mar 16, 2020
@sethp-nr sethp-nr changed the title wip: omit fields from KubeadmConfig (and KubeadmConfigSpec) that are defaulted elsewhere 🐛 mark defaulted fields as optional Mar 16, 2020
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 16, 2020
@vincepri
Copy link
Member

@sethp-nr changes lgtm, did you want to keep the IsZero methods? They don't seem to be used anywhere

@sethp-nr
Copy link
Contributor Author

Oh, no, I just missed a few cleaning things up. will fix.

@sethp-nr sethp-nr force-pushed the other/kubeadm-config-defaulting-and-empties branch from 7090b93 to e8b9f1a Compare March 16, 2020 19:10
@sethp-nr sethp-nr changed the title 🐛 mark defaulted fields as optional 🏃 mark defaulted fields as optional Mar 16, 2020
Add optional tags for fields that have defaults provided elsewhere (in the bootstrap provider, or kubeadm itself).
@sethp-nr sethp-nr force-pushed the other/kubeadm-config-defaulting-and-empties branch from e8b9f1a to a963cbc Compare March 16, 2020 19:11
@sethp-nr sethp-nr changed the title 🏃 mark defaulted fields as optional 🏃mark defaulted fields as optional Mar 16, 2020
Copy link
Member

@vincepri vincepri left a comment

Choose a reason for hiding this comment

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

/approve
/assign @ncdc
/milestone v0.3.1

@k8s-ci-robot k8s-ci-robot added this to the v0.3.1 milestone Mar 16, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sethp-nr, vincepri

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 16, 2020
@ncdc
Copy link
Contributor

ncdc commented Mar 16, 2020

/lgtm
thanks!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 16, 2020
@k8s-ci-robot k8s-ci-robot merged commit 94bd603 into kubernetes-sigs:master Mar 16, 2020
@sethp-nr sethp-nr deleted the other/kubeadm-config-defaulting-and-empties branch March 16, 2020 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mark kubeadm fields optional & omitempty + document defaults if kubeadm defaults the fields
5 participants