- Notifications
You must be signed in to change notification settings - Fork 736
Description
Versions
kubeadm API v1alpha3 and v1beta1 (releases 1.11, 1.12, 1.13)
What happened?
I wanted to use a Go program to generate kubeadm configuration, such that no taints are applied to the node. I imported the kubeadm types, initialized an InitConfiguration struct, and set NodeRegistration.Taints to an empty slice. I then marshalled the struct YAML and wrote this to a configuration file. I observed that NodeRegistration.Taints was not present in the file. When I passed the configuration file to kubeadm init, I observed that kubeadm applied the default set of taints to the node.
What you expected to happen?
The Taints field is explained in the code as follows:
Taints specifies the taints the Node API object should be registered with. If this field is unset, i.e. nil, in the
kubeadm initprocess it will be defaulted to []v1.Taint{'node-role.kubernetes.io/master=""'}. If you don't want to taint your master node, set this field to an empty slice, i.e.taints: {}in the YAML file. This field is solely used for Node registration.
I want to use the kubeadm types in a Go program and set the Taints field to an empty slice. However, when I marshal the struct, the field is omitted (because it is tagged omitempty).
How to reproduce it (as minimally and precisely as possible)?
Here is a Go program that generates InitConfiguration with NodeRegistration.Taints set to an empty slice, then marshals the configuration to YAML, then unmarshals it into a fresh InitConfiguration struct.. Note that, in the fresh configuration struct, NodeRegistration.Taints is nil, not an empty slice.
package main import ( "fmt" "log" "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" kubeadm "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta1" "sigs.k8s.io/yaml" ) func main() { // Create an InitConfiguration that sets taints to an empty slice srcConfig := kubeadm.InitConfiguration{ TypeMeta: metav1.TypeMeta{ Kind: "InitConfiguration", APIVersion: "kubeadm.k8s.io/v1beta1", }, NodeRegistration: kubeadm.NodeRegistrationOptions{ // empty slice means no taints should be applied Taints: []v1.Taint{}, }, } b, err := yaml.Marshal(srcConfig) if err != nil { log.Fatal(err) } dstConfig := kubeadm.InitConfiguration{} err = yaml.Unmarshal(b, dstConfig) if err != nil { log.Fatal(err) } // Taints is not an empty slice fmt.Println(dstConfig.NodeRegistration.Taints == nil) } Output:
true