Skip to content

Commit d49f5da

Browse files
Align extraArg type
1 parent 80abd39 commit d49f5da

File tree

33 files changed

+1829
-628
lines changed

33 files changed

+1829
-628
lines changed

api/bootstrap/kubeadm/v1beta1/conversion.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
bootstrapv1 "sigs.k8s.io/cluster-api/api/bootstrap/kubeadm/v1beta2"
2525
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
2626
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
27+
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
2728
)
2829

2930
func (src *KubeadmConfig) ConvertTo(dstRaw conversion.Hub) error {
@@ -82,11 +83,44 @@ func Convert_v1beta2_KubeadmConfigStatus_To_v1beta1_KubeadmConfigStatus(in *boot
8283
return nil
8384
}
8485

86+
func Convert_v1beta2_ControlPlaneComponent_To_v1beta1_ControlPlaneComponent(in *bootstrapv1.ControlPlaneComponent, out *ControlPlaneComponent, s apimachineryconversion.Scope) error {
87+
// Following fields require a custom conversions.
88+
out.ExtraArgs = utilconversion.ConvertFromArgs(in.ExtraArgs)
89+
return autoConvert_v1beta2_ControlPlaneComponent_To_v1beta1_ControlPlaneComponent(in, out, s)
90+
}
91+
92+
func Convert_v1beta2_LocalEtcd_To_v1beta1_LocalEtcd(in *bootstrapv1.LocalEtcd, out *LocalEtcd, s apimachineryconversion.Scope) error {
93+
// Following fields require a custom conversions.
94+
out.ExtraArgs = utilconversion.ConvertFromArgs(in.ExtraArgs)
95+
return autoConvert_v1beta2_LocalEtcd_To_v1beta1_LocalEtcd(in, out, s)
96+
}
97+
98+
func Convert_v1beta2_NodeRegistrationOptions_To_v1beta1_NodeRegistrationOptions(in *bootstrapv1.NodeRegistrationOptions, out *NodeRegistrationOptions, s apimachineryconversion.Scope) error {
99+
// Following fields require a custom conversions.
100+
out.KubeletExtraArgs = utilconversion.ConvertFromArgs(in.KubeletExtraArgs)
101+
return autoConvert_v1beta2_NodeRegistrationOptions_To_v1beta1_NodeRegistrationOptions(in, out, s)
102+
}
103+
85104
func Convert_v1beta1_KubeadmConfigSpec_To_v1beta2_KubeadmConfigSpec(in *KubeadmConfigSpec, out *bootstrapv1.KubeadmConfigSpec, s apimachineryconversion.Scope) error {
86105
// NOTE: v1beta2 KubeadmConfigSpec does not have UseExperimentalRetryJoin anymore, so it's fine to just lose this field.
87106
return autoConvert_v1beta1_KubeadmConfigSpec_To_v1beta2_KubeadmConfigSpec(in, out, s)
88107
}
89108

109+
func Convert_v1beta1_ControlPlaneComponent_To_v1beta2_ControlPlaneComponent(in *ControlPlaneComponent, out *bootstrapv1.ControlPlaneComponent, s apimachineryconversion.Scope) error {
110+
out.ExtraArgs = utilconversion.ConvertToArgs(in.ExtraArgs)
111+
return autoConvert_v1beta1_ControlPlaneComponent_To_v1beta2_ControlPlaneComponent(in, out, s)
112+
}
113+
114+
func Convert_v1beta1_LocalEtcd_To_v1beta2_LocalEtcd(in *LocalEtcd, out *bootstrapv1.LocalEtcd, s apimachineryconversion.Scope) error {
115+
out.ExtraArgs = utilconversion.ConvertToArgs(in.ExtraArgs)
116+
return autoConvert_v1beta1_LocalEtcd_To_v1beta2_LocalEtcd(in, out, s)
117+
}
118+
119+
func Convert_v1beta1_NodeRegistrationOptions_To_v1beta2_NodeRegistrationOptions(in *NodeRegistrationOptions, out *bootstrapv1.NodeRegistrationOptions, s apimachineryconversion.Scope) error {
120+
out.KubeletExtraArgs = utilconversion.ConvertToArgs(in.KubeletExtraArgs)
121+
return autoConvert_v1beta1_NodeRegistrationOptions_To_v1beta2_NodeRegistrationOptions(in, out, s)
122+
}
123+
90124
func Convert_v1beta1_KubeadmConfigStatus_To_v1beta2_KubeadmConfigStatus(in *KubeadmConfigStatus, out *bootstrapv1.KubeadmConfigStatus, s apimachineryconversion.Scope) error {
91125
if err := autoConvert_v1beta1_KubeadmConfigStatus_To_v1beta2_KubeadmConfigStatus(in, out, s); err != nil {
92126
return err

api/bootstrap/kubeadm/v1beta1/zz_generated.conversion.go

Lines changed: 108 additions & 74 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/bootstrap/kubeadm/v1beta2/kubeadm_types.go

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,15 @@ type ClusterConfiguration struct {
207207

208208
// ControlPlaneComponent holds settings common to control plane component of the cluster.
209209
type ControlPlaneComponent struct {
210-
// extraArgs is an extra set of flags to pass to the control plane component.
211-
// TODO: This is temporary and ideally we would like to switch all components to use ComponentConfig + ConfigMaps.
210+
// extraArgs is a list of args to pass to the control plane component.
211+
// The arg name must match be the command line flag name except without leading dash(es).
212+
// Extra arguments will override existing default arguments set by kubeadm.
212213
// +optional
213-
ExtraArgs map[string]string `json:"extraArgs,omitempty"`
214+
// +listType=atomic
215+
// +kubebuilder:validation:MinItems=1
216+
// +kubebuilder:validation:MaxItems=100
217+
// +kubebuilder:validation:XValidation:rule="self.all(x, self.exists_one(y, x == y))",message="extraArgs name must be unique"
218+
ExtraArgs []Arg `json:"extraArgs,omitempty"`
214219

215220
// extraVolumes is an extra set of host volumes, mounted to the control plane component.
216221
// +optional
@@ -322,13 +327,18 @@ type NodeRegistrationOptions struct {
322327
// +kubebuilder:validation:MaxItems=100
323328
Taints []corev1.Taint `json:"taints,omitempty"`
324329

325-
// kubeletExtraArgs passes through extra arguments to the kubelet. The arguments here are passed to the kubelet command line via the environment file
326-
// kubeadm writes at runtime for the kubelet to source. This overrides the generic base-level configuration in the kubelet-config-1.X ConfigMap
327-
// Flags have higher priority when parsing. These values are local and specific to the node kubeadm is executing on.
330+
// kubeletExtraArgs is a list of args to pass to kubelet.
331+
// The arg name must match be the command line flag name except without leading dash(es).
332+
// Extra arguments will override existing default arguments set by kubeadm.
328333
// +optional
329-
KubeletExtraArgs map[string]string `json:"kubeletExtraArgs,omitempty"`
334+
// +listType=atomic
335+
// +kubebuilder:validation:MinItems=1
336+
// +kubebuilder:validation:MaxItems=100
337+
// +kubebuilder:validation:XValidation:rule="self.all(x, self.exists_one(y, x == y))",message="kubeletExtraArgs name must be unique"
338+
KubeletExtraArgs []Arg `json:"kubeletExtraArgs,omitempty"`
330339

331-
// ignorePreflightErrors provides a slice of pre-flight errors to be ignored when the current node is registered.
340+
// ignorePreflightErrors provides a slice of pre-flight errors to be ignored when the current node is registered, e.g. 'IsPrivilegedUser,Swap'.
341+
// // Value 'all' ignores errors from all checks.
332342
// +optional
333343
// +kubebuilder:validation:MaxItems=50
334344
// +kubebuilder:validation:items:MinLength=1
@@ -364,13 +374,13 @@ func (n *NodeRegistrationOptions) MarshalJSON() ([]byte, error) {
364374
// Marshal an empty Taints slice array without omitempty so it's preserved.
365375
if n.Taints != nil && len(n.Taints) == 0 {
366376
return json.Marshal(struct {
367-
Name string `json:"name,omitempty"`
368-
CRISocket string `json:"criSocket,omitempty"`
369-
Taints []corev1.Taint `json:"taints"`
370-
KubeletExtraArgs map[string]string `json:"kubeletExtraArgs,omitempty"`
371-
IgnorePreflightErrors []string `json:"ignorePreflightErrors,omitempty"`
372-
ImagePullPolicy string `json:"imagePullPolicy,omitempty"`
373-
ImagePullSerial *bool `json:"imagePullSerial,omitempty"`
377+
Name string `json:"name,omitempty"`
378+
CRISocket string `json:"criSocket,omitempty"`
379+
Taints []corev1.Taint `json:"taints"`
380+
KubeletExtraArgs []Arg `json:"kubeletExtraArgs,omitempty"`
381+
IgnorePreflightErrors []string `json:"ignorePreflightErrors,omitempty"`
382+
ImagePullPolicy string `json:"imagePullPolicy,omitempty"`
383+
ImagePullSerial *bool `json:"imagePullSerial,omitempty"`
374384
}{
375385
Name: n.Name,
376386
CRISocket: n.CRISocket,
@@ -384,13 +394,13 @@ func (n *NodeRegistrationOptions) MarshalJSON() ([]byte, error) {
384394

385395
// If Taints is nil or not empty we can use omitempty.
386396
return json.Marshal(struct {
387-
Name string `json:"name,omitempty"`
388-
CRISocket string `json:"criSocket,omitempty"`
389-
Taints []corev1.Taint `json:"taints,omitempty"`
390-
KubeletExtraArgs map[string]string `json:"kubeletExtraArgs,omitempty"`
391-
IgnorePreflightErrors []string `json:"ignorePreflightErrors,omitempty"`
392-
ImagePullPolicy string `json:"imagePullPolicy,omitempty"`
393-
ImagePullSerial *bool `json:"imagePullSerial,omitempty"`
397+
Name string `json:"name,omitempty"`
398+
CRISocket string `json:"criSocket,omitempty"`
399+
Taints []corev1.Taint `json:"taints,omitempty"`
400+
KubeletExtraArgs []Arg `json:"kubeletExtraArgs,omitempty"`
401+
IgnorePreflightErrors []string `json:"ignorePreflightErrors,omitempty"`
402+
ImagePullPolicy string `json:"imagePullPolicy,omitempty"`
403+
ImagePullSerial *bool `json:"imagePullSerial,omitempty"`
394404
}{
395405
Name: n.Name,
396406
CRISocket: n.CRISocket,
@@ -487,12 +497,17 @@ type LocalEtcd struct {
487497
// +kubebuilder:validation:MaxLength=512
488498
DataDir string `json:"dataDir,omitempty"`
489499

490-
// extraArgs are extra arguments provided to the etcd binary
491-
// when run inside a static pod.
500+
// extraArgs is a list of args to pass to etcd.
501+
// The arg name must match be the command line flag name except without leading dash(es).
502+
// Extra arguments will override existing default arguments set by kubeadm.
492503
// +optional
493-
ExtraArgs map[string]string `json:"extraArgs,omitempty"`
504+
// +listType=atomic
505+
// +kubebuilder:validation:MinItems=1
506+
// +kubebuilder:validation:MaxItems=100
507+
// +kubebuilder:validation:XValidation:rule="self.all(x, self.exists_one(y, x == y))",message="extraArgs name must be unique"
508+
ExtraArgs []Arg `json:"extraArgs,omitempty"`
494509

495-
// extraEnvs is an extra set of environment variables to pass to the control plane component.
510+
// extraEnvs is an extra set of environment variables to pass to etcd.
496511
// Environment variables passed using ExtraEnvs will override any existing environment variables, or *_proxy environment variables that kubeadm adds by default.
497512
// This option takes effect only on Kubernetes >=1.31.0.
498513
// +optional
@@ -559,7 +574,7 @@ type JoinConfiguration struct {
559574
NodeRegistration NodeRegistrationOptions `json:"nodeRegistration,omitempty"`
560575

561576
// caCertPath is the path to the SSL certificate authority used to
562-
// secure comunications between node and control-plane.
577+
// secure communications between node and control-plane.
563578
// Defaults to "/etc/kubernetes/pki/ca.crt".
564579
// +optional
565580
// TODO: revisit when there is defaulting from k/k
@@ -931,6 +946,21 @@ type Patches struct {
931946
Directory string `json:"directory,omitempty"`
932947
}
933948

949+
// Arg represents an argument with a name and a value.
950+
type Arg struct {
951+
// name is the Name of the extraArg.
952+
// +required
953+
// +kubebuilder:validation:MinLength=1
954+
// +kubebuilder:validation:MaxLength=256
955+
Name string `json:"name"`
956+
957+
// value is the Value of the extraArg.
958+
// +required
959+
// +kubebuilder:validation:MinLength=1
960+
// +kubebuilder:validation:MaxLength=1024
961+
Value string `json:"value"`
962+
}
963+
934964
// EnvVar represents an environment variable present in a Container.
935965
type EnvVar struct {
936966
corev1.EnvVar `json:",inline"`

api/bootstrap/kubeadm/v1beta2/kubeadm_types_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,21 @@ func TestNodeRegistrationOptionsMarshalJSON(t *testing.T) {
3838
Name: "node-1",
3939
CRISocket: "unix:///var/run/containerd/containerd.sock",
4040
Taints: nil,
41-
KubeletExtraArgs: map[string]string{"abc": "def"},
41+
KubeletExtraArgs: []Arg{{Name: "abc", Value: "def"}},
4242
IgnorePreflightErrors: []string{"ignore-1"},
4343
},
44-
expected: `{"name":"node-1","criSocket":"unix:///var/run/containerd/containerd.sock","kubeletExtraArgs":{"abc":"def"},"ignorePreflightErrors":["ignore-1"]}`,
44+
expected: `{"name":"node-1","criSocket":"unix:///var/run/containerd/containerd.sock","kubeletExtraArgs":[{"name":"abc","value":"def"}],"ignorePreflightErrors":["ignore-1"]}`,
4545
},
4646
{
4747
name: "marshal empty taints",
4848
opts: NodeRegistrationOptions{
4949
Name: "node-1",
5050
CRISocket: "unix:///var/run/containerd/containerd.sock",
5151
Taints: []corev1.Taint{},
52-
KubeletExtraArgs: map[string]string{"abc": "def"},
52+
KubeletExtraArgs: []Arg{{Name: "abc", Value: "def"}},
5353
IgnorePreflightErrors: []string{"ignore-1"},
5454
},
55-
expected: `{"name":"node-1","criSocket":"unix:///var/run/containerd/containerd.sock","taints":[],"kubeletExtraArgs":{"abc":"def"},"ignorePreflightErrors":["ignore-1"]}`,
55+
expected: `{"name":"node-1","criSocket":"unix:///var/run/containerd/containerd.sock","taints":[],"kubeletExtraArgs":[{"name":"abc","value":"def"}],"ignorePreflightErrors":["ignore-1"]}`,
5656
},
5757
{
5858
name: "marshal regular taints",
@@ -66,10 +66,10 @@ func TestNodeRegistrationOptionsMarshalJSON(t *testing.T) {
6666
Effect: "effect",
6767
},
6868
},
69-
KubeletExtraArgs: map[string]string{"abc": "def"},
69+
KubeletExtraArgs: []Arg{{Name: "abc", Value: "def"}},
7070
IgnorePreflightErrors: []string{"ignore-1"},
7171
},
72-
expected: `{"name":"node-1","criSocket":"unix:///var/run/containerd/containerd.sock","taints":[{"key":"key","value":"value","effect":"effect"}],"kubeletExtraArgs":{"abc":"def"},"ignorePreflightErrors":["ignore-1"]}`,
72+
expected: `{"name":"node-1","criSocket":"unix:///var/run/containerd/containerd.sock","taints":[{"key":"key","value":"value","effect":"effect"}],"kubeletExtraArgs":[{"name":"abc","value":"def"}],"ignorePreflightErrors":["ignore-1"]}`,
7373
},
7474
}
7575
for _, tt := range tests {

api/bootstrap/kubeadm/v1beta2/zz_generated.deepcopy.go

Lines changed: 21 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)