-
Notifications
You must be signed in to change notification settings - Fork 39.9k
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
kubeadm: Fix omitempty in v1beta2 #77345
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: rosti 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @rosti
the diff LGTM.
There are a couple of problems with regards to the `omitempty` in v1beta1: - It is not applied to certain fields. This makes emitting YAML configuration files in v1beta1 config format verbose by both kubeadm and third party Go lang tools. Certain fields, that were never given an explicit value would show up in the marshalled YAML document. This can cause confusion and even misconfiguration. - It can be used in inappropriate places. In this case it's used for fields, that need to be always serialized. The only one such field at the moment is `NodeRegistrationOptions.Taints`. If the `Taints` field is nil, then it's defaulted to a slice containing a single control plane node taint. If it's an empty slice, no taints are applied, thus, the cluster behaves differently. With that in mind, a Go program, that uses v1beta1 with `omitempty` on the `Taints` field has no way to specify an explicit empty slice of taints, as this would get lost after marshalling to YAML. To fix these issues the following is done in this change: - A whole bunch of additional omitemptys are placed at many fields in v1beta2. - `omitempty` is removed from `NodeRegistrationOptions.Taints` - A test, that verifies the ability to specify empty slice value for `Taints` is included. Signed-off-by: Rostislav M. Georgiev <rostislavg@vmware.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/test pull-kubernetes-integration |
/retest Review the full test history for this PR. Silence the bot with an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One unexpected change
@@ -205,7 +205,7 @@ type NodeRegistrationOptions struct { | |||
// Taints specifies the taints the Node API object should be registered with. If this field is unset, i.e. nil, in the `kubeadm init` process | |||
// it will be defaulted to []v1.Taint{'node-role.kubernetes.io/master=""'}. If you don't want to taint your control-plane node, set this field to an | |||
// empty slice, i.e. `taints: {}` in the YAML file. This field is solely used for Node registration. | |||
Taints []v1.Taint `json:"taints,omitempty"` | |||
Taints []v1.Taint `json:"taints"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why remove omitempty here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@luxas I think you may have missed the explanation in the PR description above. Here's an excerpt:
It can be used in inappropriate places. In this case it's used for fields, that need to be always serialized. The only one such field at the moment is NodeRegistrationOptions.Taints. If the Taints field is nil, then it's defaulted to a slice containing a single control plane node taint. If it's an empty slice, no taints are applied, thus, the cluster behaves differently. With that in mind, a Go program, that uses v1beta1 with omitempty on the Taints field has no way to specify an explicit empty slice of taints, as this would get lost after marshalling to YAML.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, ok, yeah I missed that 👍
Otherwise LGTM 👍 |
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
There are a couple of problems with regards to the
omitempty
in v1beta1:It is not applied to certain fields. This makes emitting YAML configuration files in v1beta1 config format verbose by both kubeadm and third party Go lang tools. Certain fields, that were never given an explicit value would show up in the marshalled YAML document. This can cause confusion and even misconfiguration.
It can be used in inappropriate places. In this case it's used for fields, that need to be always serialized. The only one such field at the moment is
NodeRegistrationOptions.Taints
. If theTaints
field is nil, then it's defaulted to a slice containing a single control plane node taint. If it's an empty slice, no taints are applied, thus, the cluster behaves differently. With that in mind, a Go program, that uses v1beta1 withomitempty
on theTaints
field has no way to specify an explicit empty slice of taints, as this would get lost after marshalling to YAML.To fix these issues the following is done in this change:
omitempty
is removed fromNodeRegistrationOptions.Taints
Taints
is included.Which issue(s) this PR fixes:
Fixes kubernetes/kubeadm#1358
Refs kubernetes/enhancements#970 kubernetes/kubeadm#1439
Special notes for your reviewer:
/cc @kubernetes/sig-cluster-lifecycle-pr-reviews
/area kubeadm
/priority important-soon
/assign @fabriziopandini
/assign @timothysc
/assign @neolit123
/cc @dlipovetsky
Does this PR introduce a user-facing change?: