From 31406da1701a3ae9048d47d072e06b2634fb56ae Mon Sep 17 00:00:00 2001 From: davidumea Date: Thu, 26 Sep 2024 12:00:16 +0200 Subject: [PATCH 01/18] Add bootCommands cloud-init file generation --- .../api/v1beta1/kubeadmconfig_types.go | 8 ++++- ...strap.cluster.x-k8s.io_kubeadmconfigs.yaml | 27 +++++++++++++++++ ...uster.x-k8s.io_kubeadmconfigtemplates.yaml | 27 +++++++++++++++++ .../internal/cloudinit/boot_commands.go | 29 +++++++++++++++++++ .../kubeadm/internal/cloudinit/cloudinit.go | 5 ++++ .../internal/cloudinit/cloudinit_test.go | 5 ++++ .../internal/cloudinit/controlplane_init.go | 1 + .../internal/cloudinit/controlplane_join.go | 1 + bootstrap/kubeadm/internal/cloudinit/node.go | 2 +- .../controllers/kubeadmconfig_controller.go | 3 ++ .../kubeadm/internal/ignition/clc/clc_test.go | 21 +++++++++++++- ...cluster.x-k8s.io_kubeadmcontrolplanes.yaml | 27 +++++++++++++++++ ...x-k8s.io_kubeadmcontrolplanetemplates.yaml | 18 ++++++++++++ .../webhooks/kubeadm_control_plane.go | 2 ++ .../webhooks/kubeadm_control_plane_test.go | 3 ++ .../bootstrap/kubeadm-bootstrap/index.md | 7 +++++ .../kubeadm/v1alpha3/kubeadmconfig_types.go | 8 ++++- .../kubeadm/v1alpha4/kubeadmconfig_types.go | 8 ++++- 18 files changed, 197 insertions(+), 5 deletions(-) create mode 100644 bootstrap/kubeadm/internal/cloudinit/boot_commands.go diff --git a/bootstrap/kubeadm/api/v1beta1/kubeadmconfig_types.go b/bootstrap/kubeadm/api/v1beta1/kubeadmconfig_types.go index ea2956d30857..30863fd7dd64 100644 --- a/bootstrap/kubeadm/api/v1beta1/kubeadmconfig_types.go +++ b/bootstrap/kubeadm/api/v1beta1/kubeadmconfig_types.go @@ -75,7 +75,11 @@ type KubeadmConfigSpec struct { // +optional Mounts []MountPoints `json:"mounts,omitempty"` - // preKubeadmCommands specifies extra commands to run before kubeadm runs + // BootCommands specifies extra commands to run very early in the boot process + // +optional + BootCommands []BootCommand `json:"bootCommands,omitempty"` + + // PreKubeadmCommands specifies extra commands to run before kubeadm runs // +optional PreKubeadmCommands []string `json:"preKubeadmCommands,omitempty"` @@ -720,3 +724,5 @@ type Filesystem struct { // MountPoints defines input for generated mounts in cloud-init. type MountPoints []string + +type BootCommand []string diff --git a/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml b/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml index 3d29c546acc4..b09bab5cfaf1 100644 --- a/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml +++ b/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml @@ -854,6 +854,15 @@ spec: type: string type: array type: object + bootCommands: + description: BootCommands specifies extra commands to run very early + in the boot process + items: + description: Defines each boot command to be executed + items: + type: string + type: array + type: array postKubeadmCommands: description: postKubeadmCommands specifies extra commands to run after kubeadm runs @@ -1855,6 +1864,15 @@ spec: type: string type: array type: object + bootCommands: + description: BootCommands specifies extra commands to run very early + in the boot process + items: + description: Defines each boot command to be executed + items: + type: string + type: array + type: array postKubeadmCommands: description: postKubeadmCommands specifies extra commands to run after kubeadm runs @@ -3590,6 +3608,15 @@ spec: type: string type: array type: object + bootCommands: + description: BootCommands specifies extra commands to run very early + in the boot process + items: + description: Defines each boot command to be executed + items: + type: string + type: array + type: array postKubeadmCommands: description: postKubeadmCommands specifies extra commands to run after kubeadm runs diff --git a/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml b/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml index 23cfa5bbd1f0..831e0da19bfb 100644 --- a/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml +++ b/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml @@ -878,6 +878,15 @@ spec: type: string type: array type: object + bootCommands: + description: BootCommands specifies extra commands to run very early + in the boot process + items: + description: Defines each boot command to be executed + items: + type: string + type: array + type: array postKubeadmCommands: description: postKubeadmCommands specifies extra commands to run after kubeadm runs @@ -1836,6 +1845,15 @@ spec: type: string type: array type: object + bootCommands: + description: BootCommands specifies extra commands to run very early + in the boot process + items: + description: Defines each boot command to be executed + items: + type: string + type: array + type: array postKubeadmCommands: description: postKubeadmCommands specifies extra commands to run after kubeadm runs @@ -3580,6 +3598,15 @@ spec: type: string type: array type: object + bootCommands: + description: BootCommands specifies extra commands to run very early + in the boot process + items: + description: Defines each boot command to be executed + items: + type: string + type: array + type: array postKubeadmCommands: description: postKubeadmCommands specifies extra commands to run after kubeadm runs diff --git a/bootstrap/kubeadm/internal/cloudinit/boot_commands.go b/bootstrap/kubeadm/internal/cloudinit/boot_commands.go new file mode 100644 index 000000000000..9ecc1c8361e7 --- /dev/null +++ b/bootstrap/kubeadm/internal/cloudinit/boot_commands.go @@ -0,0 +1,29 @@ +/* +Copyright 2019 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cloudinit + +const ( + bootCommandsTemplate = `{{ define "boot_commands" -}} +{{- if . }} +bootcmd:{{ range . }} + - {{ range . }}- {{ . }} + {{ end -}} +{{- end -}} +{{- end -}} +{{- end -}} +` +) diff --git a/bootstrap/kubeadm/internal/cloudinit/cloudinit.go b/bootstrap/kubeadm/internal/cloudinit/cloudinit.go index 048ad085728e..3e2fc3e4e92f 100644 --- a/bootstrap/kubeadm/internal/cloudinit/cloudinit.go +++ b/bootstrap/kubeadm/internal/cloudinit/cloudinit.go @@ -45,6 +45,7 @@ const ( // BaseUserData is shared across all the various types of files written to disk. type BaseUserData struct { Header string + BootCommands []bootstrapv1.BootCommand PreKubeadmCommands []string PostKubeadmCommands []string AdditionalFiles []bootstrapv1.File @@ -83,6 +84,10 @@ func generate(kind string, tpl string, data interface{}) ([]byte, error) { return nil, errors.Wrap(err, "failed to parse files template") } + if _, err := tm.Parse(bootCommandsTemplate); err != nil { + return nil, errors.Wrap(err, "failed to parse boot commands template") + } + if _, err := tm.Parse(commandsTemplate); err != nil { return nil, errors.Wrap(err, "failed to parse commands template") } diff --git a/bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go b/bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go index 789e9b7e8bcd..72041d2a7555 100644 --- a/bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go +++ b/bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go @@ -34,6 +34,7 @@ func TestNewInitControlPlaneAdditionalFileEncodings(t *testing.T) { cpinput := &ControlPlaneInput{ BaseUserData: BaseUserData{ Header: "test", + BootCommands: nil, PreKubeadmCommands: nil, PostKubeadmCommands: nil, AdditionalFiles: []bootstrapv1.File{ @@ -95,6 +96,7 @@ func TestNewInitControlPlaneCommands(t *testing.T) { cpinput := &ControlPlaneInput{ BaseUserData: BaseUserData{ Header: "test", + BootCommands: nil, PreKubeadmCommands: []string{`"echo $(date) ': hello world!'"`}, PostKubeadmCommands: []string{"echo $(date) ': hello world!'"}, AdditionalFiles: nil, @@ -132,6 +134,7 @@ func TestNewInitControlPlaneDiskMounts(t *testing.T) { cpinput := &ControlPlaneInput{ BaseUserData: BaseUserData{ Header: "test", + BootCommands: nil, PreKubeadmCommands: nil, PostKubeadmCommands: nil, WriteFiles: nil, @@ -195,6 +198,7 @@ func TestNewJoinControlPlaneAdditionalFileEncodings(t *testing.T) { cpinput := &ControlPlaneJoinInput{ BaseUserData: BaseUserData{ Header: "test", + BootCommands: nil, PreKubeadmCommands: nil, PostKubeadmCommands: nil, AdditionalFiles: []bootstrapv1.File{ @@ -247,6 +251,7 @@ func TestNewJoinControlPlaneExperimentalRetry(t *testing.T) { cpinput := &ControlPlaneJoinInput{ BaseUserData: BaseUserData{ Header: "test", + BootCommands: nil, PreKubeadmCommands: nil, PostKubeadmCommands: nil, UseExperimentalRetry: true, diff --git a/bootstrap/kubeadm/internal/cloudinit/controlplane_init.go b/bootstrap/kubeadm/internal/cloudinit/controlplane_init.go index c6cd12d5665e..a7412a7a8a54 100644 --- a/bootstrap/kubeadm/internal/cloudinit/controlplane_init.go +++ b/bootstrap/kubeadm/internal/cloudinit/controlplane_init.go @@ -35,6 +35,7 @@ const ( owner: root:root permissions: '0640' content: "This placeholder file is used to create the /run/cluster-api sub directory in a way that is compatible with both Linux and Windows (mkdir -p /run/cluster-api does not work with Windows)" +{{- template "boot_commands" .BootCommands }} runcmd: {{- template "commands" .PreKubeadmCommands }} - 'kubeadm init --config /run/kubeadm/kubeadm.yaml {{.KubeadmVerbosity}} && {{ .SentinelFileCommand }}' diff --git a/bootstrap/kubeadm/internal/cloudinit/controlplane_join.go b/bootstrap/kubeadm/internal/cloudinit/controlplane_join.go index b0366330b5bd..7cbd5fd00952 100644 --- a/bootstrap/kubeadm/internal/cloudinit/controlplane_join.go +++ b/bootstrap/kubeadm/internal/cloudinit/controlplane_join.go @@ -34,6 +34,7 @@ const ( owner: root:root permissions: '0640' content: "This placeholder file is used to create the /run/cluster-api sub directory in a way that is compatible with both Linux and Windows (mkdir -p /run/cluster-api does not work with Windows)" +{{- template "boot_commands" .BootCommands }} runcmd: {{- template "commands" .PreKubeadmCommands }} - {{ .KubeadmCommand }} && {{ .SentinelFileCommand }} diff --git a/bootstrap/kubeadm/internal/cloudinit/node.go b/bootstrap/kubeadm/internal/cloudinit/node.go index 80a143242161..3c26b0828e9f 100644 --- a/bootstrap/kubeadm/internal/cloudinit/node.go +++ b/bootstrap/kubeadm/internal/cloudinit/node.go @@ -29,6 +29,7 @@ const ( owner: root:root permissions: '0640' content: "This placeholder file is used to create the /run/cluster-api sub directory in a way that is compatible with both Linux and Windows (mkdir -p /run/cluster-api does not work with Windows)" +{{- template "boot_commands" .BootCommands }} runcmd: {{- template "commands" .PreKubeadmCommands }} - {{ .KubeadmCommand }} && {{ .SentinelFileCommand }} @@ -40,7 +41,6 @@ runcmd: {{- template "mounts" .Mounts}} ` ) - // NodeInput defines the context to generate a node user data. type NodeInput struct { BaseUserData diff --git a/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go b/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go index b9a6ea250e7b..130a3e56e6ae 100644 --- a/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go +++ b/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go @@ -531,6 +531,7 @@ func (r *KubeadmConfigReconciler) handleClusterNotInitialized(ctx context.Contex BaseUserData: cloudinit.BaseUserData{ AdditionalFiles: files, NTP: scope.Config.Spec.NTP, + BootCommands: scope.Config.Spec.BootCommands, PreKubeadmCommands: scope.Config.Spec.PreKubeadmCommands, PostKubeadmCommands: scope.Config.Spec.PostKubeadmCommands, Users: users, @@ -652,6 +653,7 @@ func (r *KubeadmConfigReconciler) joinWorker(ctx context.Context, scope *Scope) BaseUserData: cloudinit.BaseUserData{ AdditionalFiles: files, NTP: scope.Config.Spec.NTP, + BootCommands: scope.Config.Spec.BootCommands, PreKubeadmCommands: scope.Config.Spec.PreKubeadmCommands, PostKubeadmCommands: scope.Config.Spec.PostKubeadmCommands, Users: users, @@ -771,6 +773,7 @@ func (r *KubeadmConfigReconciler) joinControlplane(ctx context.Context, scope *S BaseUserData: cloudinit.BaseUserData{ AdditionalFiles: files, NTP: scope.Config.Spec.NTP, + BootCommands: scope.Config.Spec.BootCommands, PreKubeadmCommands: scope.Config.Spec.PreKubeadmCommands, PostKubeadmCommands: scope.Config.Spec.PostKubeadmCommands, Users: users, diff --git a/bootstrap/kubeadm/internal/ignition/clc/clc_test.go b/bootstrap/kubeadm/internal/ignition/clc/clc_test.go index 906df32a39af..9349d8eb1277 100644 --- a/bootstrap/kubeadm/internal/ignition/clc/clc_test.go +++ b/bootstrap/kubeadm/internal/ignition/clc/clc_test.go @@ -64,7 +64,6 @@ func TestRender(t *testing.T) { // Test multi-line commands as well. "cat < /etc/modules-load.d/containerd.conf\noverlay\nbr_netfilter\nEOF\n", } - tc := []struct { desc string input *cloudinit.BaseUserData @@ -73,6 +72,11 @@ func TestRender(t *testing.T) { { desc: "renders valid Ignition JSON", input: &cloudinit.BaseUserData{ + BootCommands: []bootstrapv1.BootCommand{ + { + "boot-command", "another-boot-command", + }, + }, PreKubeadmCommands: preKubeadmCommands, PostKubeadmCommands: postKubeadmCommands, KubeadmCommand: "kubeadm join", @@ -269,6 +273,11 @@ func TestRender(t *testing.T) { { desc: "multiple users with password auth", input: &cloudinit.BaseUserData{ + BootCommands: []bootstrapv1.BootCommand{ + { + "boot-command", "another-boot-command", + }, + }, PreKubeadmCommands: preKubeadmCommands, PostKubeadmCommands: postKubeadmCommands, KubeadmCommand: "kubeadm join", @@ -351,6 +360,11 @@ func TestRender(t *testing.T) { { desc: "base64 encoded content", input: &cloudinit.BaseUserData{ + BootCommands: []bootstrapv1.BootCommand{ + { + "boot-command", "another-boot-command", + }, + }, PreKubeadmCommands: preKubeadmCommands, PostKubeadmCommands: postKubeadmCommands, KubeadmCommand: "kubeadm join", @@ -434,6 +448,11 @@ func TestRender(t *testing.T) { { desc: "all file ownership combinations", input: &cloudinit.BaseUserData{ + BootCommands: []bootstrapv1.BootCommand{ + { + "boot-command", "another-boot-command", + }, + }, PreKubeadmCommands: preKubeadmCommands, PostKubeadmCommands: postKubeadmCommands, KubeadmCommand: "kubeadm join", diff --git a/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml b/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml index 0e4c0a820168..ec4b85b04248 100644 --- a/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml +++ b/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml @@ -945,6 +945,15 @@ spec: type: string type: array type: object + bootCommands: + description: BootCommands specifies extra commands to run very early + in the boot process + items: + description: Defines each boot command to be executed + items: + type: string + type: array + type: array postKubeadmCommands: description: postKubeadmCommands specifies extra commands to run after kubeadm runs @@ -2089,6 +2098,15 @@ spec: type: string type: array type: object + bootCommands: + description: BootCommands specifies extra commands to run very early + in the boot process + items: + description: Defines each boot command to be executed + items: + type: string + type: array + type: array postKubeadmCommands: description: postKubeadmCommands specifies extra commands to run after kubeadm runs @@ -4075,6 +4093,15 @@ spec: type: string type: array type: object + bootCommands: + description: BootCommands specifies extra commands to run very early + in the boot process + items: + description: Defines each boot command to be executed + items: + type: string + type: array + type: array postKubeadmCommands: description: postKubeadmCommands specifies extra commands to run after kubeadm runs diff --git a/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanetemplates.yaml b/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanetemplates.yaml index 332634f0bfa1..3c503e6bad64 100644 --- a/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanetemplates.yaml +++ b/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanetemplates.yaml @@ -897,6 +897,15 @@ spec: type: string type: array type: object + bootCommands: + description: BootCommands specifies extra commands to run very early + in the boot process + items: + description: Defines each boot command to be executed + items: + type: string + type: array + type: array postKubeadmCommands: description: postKubeadmCommands specifies extra commands to run after kubeadm runs @@ -2814,6 +2823,15 @@ spec: type: string type: array type: object + bootCommands: + description: BootCommands specifies extra commands to run very early + in the boot process + items: + description: Defines each boot command to be executed + items: + type: string + type: array + type: array postKubeadmCommands: description: postKubeadmCommands specifies extra commands to run after kubeadm runs diff --git a/controlplane/kubeadm/internal/webhooks/kubeadm_control_plane.go b/controlplane/kubeadm/internal/webhooks/kubeadm_control_plane.go index df85bb946bee..b5ea4c6d8d66 100644 --- a/controlplane/kubeadm/internal/webhooks/kubeadm_control_plane.go +++ b/controlplane/kubeadm/internal/webhooks/kubeadm_control_plane.go @@ -142,6 +142,7 @@ const ( skipPhases = "skipPhases" patches = "patches" directory = "directory" + bootCommands = "bootCommands" preKubeadmCommands = "preKubeadmCommands" postKubeadmCommands = "postKubeadmCommands" files = "files" @@ -208,6 +209,7 @@ func (webhook *KubeadmControlPlane) ValidateUpdate(_ context.Context, oldObj, ne {spec, kubeadmConfigSpec, joinConfiguration, "discovery"}, {spec, kubeadmConfigSpec, joinConfiguration, "discovery", "*"}, // spec.kubeadmConfigSpec + {spec, kubeadmConfigSpec, "bootCommands"}, {spec, kubeadmConfigSpec, preKubeadmCommands}, {spec, kubeadmConfigSpec, postKubeadmCommands}, {spec, kubeadmConfigSpec, files}, diff --git a/controlplane/kubeadm/internal/webhooks/kubeadm_control_plane_test.go b/controlplane/kubeadm/internal/webhooks/kubeadm_control_plane_test.go index c8df406d3bc3..39b062ea2a19 100644 --- a/controlplane/kubeadm/internal/webhooks/kubeadm_control_plane_test.go +++ b/controlplane/kubeadm/internal/webhooks/kubeadm_control_plane_test.go @@ -396,6 +396,9 @@ func TestKubeadmControlPlaneValidateUpdate(t *testing.T) { validUpdate := before.DeepCopy() validUpdate.Labels = map[string]string{"blue": "green"} + validUpdate.Spec.KubeadmConfigSpec.BootCommands = []bootstrapv1.BootCommand{ + {"ab", "abc"}, + } validUpdate.Spec.KubeadmConfigSpec.PreKubeadmCommands = []string{"ab", "abc"} validUpdate.Spec.KubeadmConfigSpec.PostKubeadmCommands = []string{"ab", "abc"} validUpdate.Spec.KubeadmConfigSpec.Files = []bootstrapv1.File{ diff --git a/docs/book/src/tasks/bootstrap/kubeadm-bootstrap/index.md b/docs/book/src/tasks/bootstrap/kubeadm-bootstrap/index.md index 71215b547e9d..afd9c5c25e54 100644 --- a/docs/book/src/tasks/bootstrap/kubeadm-bootstrap/index.md +++ b/docs/book/src/tasks/bootstrap/kubeadm-bootstrap/index.md @@ -182,6 +182,13 @@ The `KubeadmConfig` object supports customizing the content of the config-data. } ``` +- `KubeadmConfig.BootCommands` specifies a list of commands to be executed very early in the boot process + + ```yaml + bootCommands: + - [ cloud-init-per, once, mymkfs, mkfs, /dev/vdb ] + ``` + - `KubeadmConfig.PreKubeadmCommands` specifies a list of commands to be executed before `kubeadm init/join` ```yaml diff --git a/internal/apis/bootstrap/kubeadm/v1alpha3/kubeadmconfig_types.go b/internal/apis/bootstrap/kubeadm/v1alpha3/kubeadmconfig_types.go index 234eb28489a3..abda6abe9112 100644 --- a/internal/apis/bootstrap/kubeadm/v1alpha3/kubeadmconfig_types.go +++ b/internal/apis/bootstrap/kubeadm/v1alpha3/kubeadmconfig_types.go @@ -59,7 +59,11 @@ type KubeadmConfigSpec struct { // +optional Mounts []MountPoints `json:"mounts,omitempty"` - // preKubeadmCommands specifies extra commands to run before kubeadm runs + // BootCommands specifies extra commands to run very early in the boot process + // +optional + BootCommands []BootCommand `json:"bootCommands,omitempty"` + + // PreKubeadmCommands specifies extra commands to run before kubeadm runs // +optional PreKubeadmCommands []string `json:"preKubeadmCommands,omitempty"` @@ -342,3 +346,5 @@ type Filesystem struct { // MountPoints defines input for generated mounts in cloud-init. type MountPoints []string + +type BootCommand []string diff --git a/internal/apis/bootstrap/kubeadm/v1alpha4/kubeadmconfig_types.go b/internal/apis/bootstrap/kubeadm/v1alpha4/kubeadmconfig_types.go index 9f823e17a86f..89bc99affa0e 100644 --- a/internal/apis/bootstrap/kubeadm/v1alpha4/kubeadmconfig_types.go +++ b/internal/apis/bootstrap/kubeadm/v1alpha4/kubeadmconfig_types.go @@ -58,7 +58,11 @@ type KubeadmConfigSpec struct { // +optional Mounts []MountPoints `json:"mounts,omitempty"` - // preKubeadmCommands specifies extra commands to run before kubeadm runs + // BootCommands specifies extra commands to run before kubeadm runs + // +optional + BootCommands []BootCommand `json:"bootCommands,omitempty"` + + // PreKubeadmCommands specifies extra commands to run before kubeadm runs // +optional PreKubeadmCommands []string `json:"preKubeadmCommands,omitempty"` @@ -335,3 +339,5 @@ type Filesystem struct { // MountPoints defines input for generated mounts in cloud-init. type MountPoints []string + +type BootCommand []string From 97311d694f0e828a20d3058526b7df2a68e68de6 Mon Sep 17 00:00:00 2001 From: davidumea Date: Fri, 18 Oct 2024 11:28:15 +0200 Subject: [PATCH 02/18] fixup: go lint --- bootstrap/kubeadm/api/v1beta1/kubeadmconfig_types.go | 1 + internal/apis/bootstrap/kubeadm/v1alpha3/kubeadmconfig_types.go | 1 + internal/apis/bootstrap/kubeadm/v1alpha4/kubeadmconfig_types.go | 1 + 3 files changed, 3 insertions(+) diff --git a/bootstrap/kubeadm/api/v1beta1/kubeadmconfig_types.go b/bootstrap/kubeadm/api/v1beta1/kubeadmconfig_types.go index 30863fd7dd64..7e7cddae51d6 100644 --- a/bootstrap/kubeadm/api/v1beta1/kubeadmconfig_types.go +++ b/bootstrap/kubeadm/api/v1beta1/kubeadmconfig_types.go @@ -725,4 +725,5 @@ type Filesystem struct { // MountPoints defines input for generated mounts in cloud-init. type MountPoints []string +// BootCommand defines input for each bootcmd command in cloud-init. type BootCommand []string diff --git a/internal/apis/bootstrap/kubeadm/v1alpha3/kubeadmconfig_types.go b/internal/apis/bootstrap/kubeadm/v1alpha3/kubeadmconfig_types.go index abda6abe9112..6135e39bd44d 100644 --- a/internal/apis/bootstrap/kubeadm/v1alpha3/kubeadmconfig_types.go +++ b/internal/apis/bootstrap/kubeadm/v1alpha3/kubeadmconfig_types.go @@ -347,4 +347,5 @@ type Filesystem struct { // MountPoints defines input for generated mounts in cloud-init. type MountPoints []string +// BootCommand defines input for each bootcmd command in cloud-init. type BootCommand []string diff --git a/internal/apis/bootstrap/kubeadm/v1alpha4/kubeadmconfig_types.go b/internal/apis/bootstrap/kubeadm/v1alpha4/kubeadmconfig_types.go index 89bc99affa0e..ea1a80664645 100644 --- a/internal/apis/bootstrap/kubeadm/v1alpha4/kubeadmconfig_types.go +++ b/internal/apis/bootstrap/kubeadm/v1alpha4/kubeadmconfig_types.go @@ -340,4 +340,5 @@ type Filesystem struct { // MountPoints defines input for generated mounts in cloud-init. type MountPoints []string +// BootCommand defines input for each bootcmd command in cloud-init. type BootCommand []string From 4367074259c63343c21f2de21f392bdcdb2962e1 Mon Sep 17 00:00:00 2001 From: davidumea Date: Fri, 18 Oct 2024 11:39:00 +0200 Subject: [PATCH 03/18] fixup: lint: added missing newline --- bootstrap/kubeadm/internal/cloudinit/node.go | 1 + 1 file changed, 1 insertion(+) diff --git a/bootstrap/kubeadm/internal/cloudinit/node.go b/bootstrap/kubeadm/internal/cloudinit/node.go index 3c26b0828e9f..81a9e0a4966d 100644 --- a/bootstrap/kubeadm/internal/cloudinit/node.go +++ b/bootstrap/kubeadm/internal/cloudinit/node.go @@ -41,6 +41,7 @@ runcmd: {{- template "mounts" .Mounts}} ` ) + // NodeInput defines the context to generate a node user data. type NodeInput struct { BaseUserData From 0c23af8c913f0f86b1516d8155a8b316e12b610f Mon Sep 17 00:00:00 2001 From: davidumea Date: Fri, 18 Oct 2024 11:40:07 +0200 Subject: [PATCH 04/18] fixup: add changes from verify-gen --- .../api/v1beta1/zz_generated.deepcopy.go | 30 ++++++++++ ...strap.cluster.x-k8s.io_kubeadmconfigs.yaml | 57 ++++++++++--------- ...uster.x-k8s.io_kubeadmconfigtemplates.yaml | 57 ++++++++++--------- ...cluster.x-k8s.io_kubeadmcontrolplanes.yaml | 57 ++++++++++--------- ...x-k8s.io_kubeadmcontrolplanetemplates.yaml | 38 +++++++------ .../v1alpha3/zz_generated.conversion.go | 2 + .../v1alpha4/zz_generated.conversion.go | 2 + 7 files changed, 144 insertions(+), 99 deletions(-) diff --git a/bootstrap/kubeadm/api/v1beta1/zz_generated.deepcopy.go b/bootstrap/kubeadm/api/v1beta1/zz_generated.deepcopy.go index 3f508065e68c..11710d2eaa4f 100644 --- a/bootstrap/kubeadm/api/v1beta1/zz_generated.deepcopy.go +++ b/bootstrap/kubeadm/api/v1beta1/zz_generated.deepcopy.go @@ -68,6 +68,25 @@ func (in *APIServer) DeepCopy() *APIServer { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in BootCommand) DeepCopyInto(out *BootCommand) { + { + in := &in + *out = make(BootCommand, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BootCommand. +func (in BootCommand) DeepCopy() BootCommand { + if in == nil { + return nil + } + out := new(BootCommand) + in.DeepCopyInto(out) + return *out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *BootstrapToken) DeepCopyInto(out *BootstrapToken) { *out = *in @@ -864,6 +883,17 @@ func (in *KubeadmConfigSpec) DeepCopyInto(out *KubeadmConfigSpec) { } } } + if in.BootCommands != nil { + in, out := &in.BootCommands, &out.BootCommands + *out = make([]BootCommand, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = make(BootCommand, len(*in)) + copy(*out, *in) + } + } + } if in.PreKubeadmCommands != nil { in, out := &in.PreKubeadmCommands, &out.PreKubeadmCommands *out = make([]string, len(*in)) diff --git a/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml b/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml index b09bab5cfaf1..6033a7a41121 100644 --- a/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml +++ b/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml @@ -47,6 +47,16 @@ spec: KubeadmConfigSpec defines the desired state of KubeadmConfig. Either ClusterConfiguration and InitConfiguration should be defined or the JoinConfiguration should be defined. properties: + bootCommands: + description: BootCommands specifies extra commands to run very early + in the boot process + items: + description: BootCommand defines input for each bootcmd command + in cloud-init. + items: + type: string + type: array + type: array clusterConfiguration: description: clusterConfiguration along with InitConfiguration are the configurations necessary for the init command @@ -854,15 +864,6 @@ spec: type: string type: array type: object - bootCommands: - description: BootCommands specifies extra commands to run very early - in the boot process - items: - description: Defines each boot command to be executed - items: - type: string - type: array - type: array postKubeadmCommands: description: postKubeadmCommands specifies extra commands to run after kubeadm runs @@ -1060,6 +1061,16 @@ spec: KubeadmConfigSpec defines the desired state of KubeadmConfig. Either ClusterConfiguration and InitConfiguration should be defined or the JoinConfiguration should be defined. properties: + bootCommands: + description: BootCommands specifies extra commands to run before kubeadm + runs + items: + description: BootCommand defines input for each bootcmd command + in cloud-init. + items: + type: string + type: array + type: array clusterConfiguration: description: clusterConfiguration along with InitConfiguration are the configurations necessary for the init command @@ -1864,15 +1875,6 @@ spec: type: string type: array type: object - bootCommands: - description: BootCommands specifies extra commands to run very early - in the boot process - items: - description: Defines each boot command to be executed - items: - type: string - type: array - type: array postKubeadmCommands: description: postKubeadmCommands specifies extra commands to run after kubeadm runs @@ -2063,6 +2065,16 @@ spec: KubeadmConfigSpec defines the desired state of KubeadmConfig. Either ClusterConfiguration and InitConfiguration should be defined or the JoinConfiguration should be defined. properties: + bootCommands: + description: BootCommands specifies extra commands to run very early + in the boot process + items: + description: BootCommand defines input for each bootcmd command + in cloud-init. + items: + type: string + type: array + type: array clusterConfiguration: description: clusterConfiguration along with InitConfiguration are the configurations necessary for the init command @@ -3608,15 +3620,6 @@ spec: type: string type: array type: object - bootCommands: - description: BootCommands specifies extra commands to run very early - in the boot process - items: - description: Defines each boot command to be executed - items: - type: string - type: array - type: array postKubeadmCommands: description: postKubeadmCommands specifies extra commands to run after kubeadm runs diff --git a/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml b/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml index 831e0da19bfb..d239512056f8 100644 --- a/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml +++ b/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml @@ -53,6 +53,16 @@ spec: KubeadmConfigSpec defines the desired state of KubeadmConfig. Either ClusterConfiguration and InitConfiguration should be defined or the JoinConfiguration should be defined. properties: + bootCommands: + description: BootCommands specifies extra commands to run + very early in the boot process + items: + description: BootCommand defines input for each bootcmd + command in cloud-init. + items: + type: string + type: array + type: array clusterConfiguration: description: clusterConfiguration along with InitConfiguration are the configurations necessary for the init command @@ -878,15 +888,6 @@ spec: type: string type: array type: object - bootCommands: - description: BootCommands specifies extra commands to run very early - in the boot process - items: - description: Defines each boot command to be executed - items: - type: string - type: array - type: array postKubeadmCommands: description: postKubeadmCommands specifies extra commands to run after kubeadm runs @@ -1021,6 +1022,16 @@ spec: KubeadmConfigSpec defines the desired state of KubeadmConfig. Either ClusterConfiguration and InitConfiguration should be defined or the JoinConfiguration should be defined. properties: + bootCommands: + description: BootCommands specifies extra commands to run + before kubeadm runs + items: + description: BootCommand defines input for each bootcmd + command in cloud-init. + items: + type: string + type: array + type: array clusterConfiguration: description: clusterConfiguration along with InitConfiguration are the configurations necessary for the init command @@ -1845,15 +1856,6 @@ spec: type: string type: array type: object - bootCommands: - description: BootCommands specifies extra commands to run very early - in the boot process - items: - description: Defines each boot command to be executed - items: - type: string - type: array - type: array postKubeadmCommands: description: postKubeadmCommands specifies extra commands to run after kubeadm runs @@ -2010,6 +2012,16 @@ spec: KubeadmConfigSpec defines the desired state of KubeadmConfig. Either ClusterConfiguration and InitConfiguration should be defined or the JoinConfiguration should be defined. properties: + bootCommands: + description: BootCommands specifies extra commands to run + very early in the boot process + items: + description: BootCommand defines input for each bootcmd + command in cloud-init. + items: + type: string + type: array + type: array clusterConfiguration: description: clusterConfiguration along with InitConfiguration are the configurations necessary for the init command @@ -3598,15 +3610,6 @@ spec: type: string type: array type: object - bootCommands: - description: BootCommands specifies extra commands to run very early - in the boot process - items: - description: Defines each boot command to be executed - items: - type: string - type: array - type: array postKubeadmCommands: description: postKubeadmCommands specifies extra commands to run after kubeadm runs diff --git a/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml b/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml index ec4b85b04248..5f2a325d60ef 100644 --- a/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml +++ b/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml @@ -129,6 +129,16 @@ spec: kubeadmConfigSpec is a KubeadmConfigSpec to use for initializing and joining machines to the control plane. properties: + bootCommands: + description: BootCommands specifies extra commands to run very + early in the boot process + items: + description: BootCommand defines input for each bootcmd command + in cloud-init. + items: + type: string + type: array + type: array clusterConfiguration: description: clusterConfiguration along with InitConfiguration are the configurations necessary for the init command @@ -945,15 +955,6 @@ spec: type: string type: array type: object - bootCommands: - description: BootCommands specifies extra commands to run very early - in the boot process - items: - description: Defines each boot command to be executed - items: - type: string - type: array - type: array postKubeadmCommands: description: postKubeadmCommands specifies extra commands to run after kubeadm runs @@ -1283,6 +1284,16 @@ spec: kubeadmConfigSpec is a KubeadmConfigSpec to use for initializing and joining machines to the control plane. properties: + bootCommands: + description: BootCommands specifies extra commands to run before + kubeadm runs + items: + description: BootCommand defines input for each bootcmd command + in cloud-init. + items: + type: string + type: array + type: array clusterConfiguration: description: clusterConfiguration along with InitConfiguration are the configurations necessary for the init command @@ -2098,15 +2109,6 @@ spec: type: string type: array type: object - bootCommands: - description: BootCommands specifies extra commands to run very early - in the boot process - items: - description: Defines each boot command to be executed - items: - type: string - type: array - type: array postKubeadmCommands: description: postKubeadmCommands specifies extra commands to run after kubeadm runs @@ -2528,6 +2530,16 @@ spec: kubeadmConfigSpec is a KubeadmConfigSpec to use for initializing and joining machines to the control plane. properties: + bootCommands: + description: BootCommands specifies extra commands to run very + early in the boot process + items: + description: BootCommand defines input for each bootcmd command + in cloud-init. + items: + type: string + type: array + type: array clusterConfiguration: description: clusterConfiguration along with InitConfiguration are the configurations necessary for the init command @@ -4093,15 +4105,6 @@ spec: type: string type: array type: object - bootCommands: - description: BootCommands specifies extra commands to run very early - in the boot process - items: - description: Defines each boot command to be executed - items: - type: string - type: array - type: array postKubeadmCommands: description: postKubeadmCommands specifies extra commands to run after kubeadm runs diff --git a/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanetemplates.yaml b/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanetemplates.yaml index 3c503e6bad64..19a4ff7519b0 100644 --- a/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanetemplates.yaml +++ b/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanetemplates.yaml @@ -64,6 +64,16 @@ spec: kubeadmConfigSpec is a KubeadmConfigSpec to use for initializing and joining machines to the control plane. properties: + bootCommands: + description: BootCommands specifies extra commands to + run before kubeadm runs + items: + description: BootCommand defines input for each bootcmd + command in cloud-init. + items: + type: string + type: array + type: array clusterConfiguration: description: clusterConfiguration along with InitConfiguration are the configurations necessary for the init command @@ -897,15 +907,6 @@ spec: type: string type: array type: object - bootCommands: - description: BootCommands specifies extra commands to run very early - in the boot process - items: - description: Defines each boot command to be executed - items: - type: string - type: array - type: array postKubeadmCommands: description: postKubeadmCommands specifies extra commands to run after kubeadm runs @@ -1214,6 +1215,16 @@ spec: kubeadmConfigSpec is a KubeadmConfigSpec to use for initializing and joining machines to the control plane. properties: + bootCommands: + description: BootCommands specifies extra commands to + run very early in the boot process + items: + description: BootCommand defines input for each bootcmd + command in cloud-init. + items: + type: string + type: array + type: array clusterConfiguration: description: clusterConfiguration along with InitConfiguration are the configurations necessary for the init command @@ -2823,15 +2834,6 @@ spec: type: string type: array type: object - bootCommands: - description: BootCommands specifies extra commands to run very early - in the boot process - items: - description: Defines each boot command to be executed - items: - type: string - type: array - type: array postKubeadmCommands: description: postKubeadmCommands specifies extra commands to run after kubeadm runs diff --git a/internal/apis/bootstrap/kubeadm/v1alpha3/zz_generated.conversion.go b/internal/apis/bootstrap/kubeadm/v1alpha3/zz_generated.conversion.go index 8134a0dd27bf..9ef292f2fb60 100644 --- a/internal/apis/bootstrap/kubeadm/v1alpha3/zz_generated.conversion.go +++ b/internal/apis/bootstrap/kubeadm/v1alpha3/zz_generated.conversion.go @@ -451,6 +451,7 @@ func autoConvert_v1alpha3_KubeadmConfigSpec_To_v1beta1_KubeadmConfigSpec(in *Kub } out.DiskSetup = (*v1beta1.DiskSetup)(unsafe.Pointer(in.DiskSetup)) out.Mounts = *(*[]v1beta1.MountPoints)(unsafe.Pointer(&in.Mounts)) + out.BootCommands = *(*[]v1beta1.BootCommand)(unsafe.Pointer(&in.BootCommands)) out.PreKubeadmCommands = *(*[]string)(unsafe.Pointer(&in.PreKubeadmCommands)) out.PostKubeadmCommands = *(*[]string)(unsafe.Pointer(&in.PostKubeadmCommands)) if in.Users != nil { @@ -517,6 +518,7 @@ func autoConvert_v1beta1_KubeadmConfigSpec_To_v1alpha3_KubeadmConfigSpec(in *v1b } out.DiskSetup = (*DiskSetup)(unsafe.Pointer(in.DiskSetup)) out.Mounts = *(*[]MountPoints)(unsafe.Pointer(&in.Mounts)) + out.BootCommands = *(*[]BootCommand)(unsafe.Pointer(&in.BootCommands)) out.PreKubeadmCommands = *(*[]string)(unsafe.Pointer(&in.PreKubeadmCommands)) out.PostKubeadmCommands = *(*[]string)(unsafe.Pointer(&in.PostKubeadmCommands)) if in.Users != nil { diff --git a/internal/apis/bootstrap/kubeadm/v1alpha4/zz_generated.conversion.go b/internal/apis/bootstrap/kubeadm/v1alpha4/zz_generated.conversion.go index 0e1ff11cb46e..d40f4edd8ee4 100644 --- a/internal/apis/bootstrap/kubeadm/v1alpha4/zz_generated.conversion.go +++ b/internal/apis/bootstrap/kubeadm/v1alpha4/zz_generated.conversion.go @@ -1144,6 +1144,7 @@ func autoConvert_v1alpha4_KubeadmConfigSpec_To_v1beta1_KubeadmConfigSpec(in *Kub } out.DiskSetup = (*v1beta1.DiskSetup)(unsafe.Pointer(in.DiskSetup)) out.Mounts = *(*[]v1beta1.MountPoints)(unsafe.Pointer(&in.Mounts)) + out.BootCommands = *(*[]v1beta1.BootCommand)(unsafe.Pointer(&in.BootCommands)) out.PreKubeadmCommands = *(*[]string)(unsafe.Pointer(&in.PreKubeadmCommands)) out.PostKubeadmCommands = *(*[]string)(unsafe.Pointer(&in.PostKubeadmCommands)) if in.Users != nil { @@ -1210,6 +1211,7 @@ func autoConvert_v1beta1_KubeadmConfigSpec_To_v1alpha4_KubeadmConfigSpec(in *v1b } out.DiskSetup = (*DiskSetup)(unsafe.Pointer(in.DiskSetup)) out.Mounts = *(*[]MountPoints)(unsafe.Pointer(&in.Mounts)) + out.BootCommands = *(*[]BootCommand)(unsafe.Pointer(&in.BootCommands)) out.PreKubeadmCommands = *(*[]string)(unsafe.Pointer(&in.PreKubeadmCommands)) out.PostKubeadmCommands = *(*[]string)(unsafe.Pointer(&in.PostKubeadmCommands)) if in.Users != nil { From 504dfd5641b7ef9d2d21214326549055d23f061b Mon Sep 17 00:00:00 2001 From: davidumea Date: Fri, 18 Oct 2024 14:40:13 +0200 Subject: [PATCH 05/18] fixup: filter tests --- controlplane/kubeadm/internal/filters_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/controlplane/kubeadm/internal/filters_test.go b/controlplane/kubeadm/internal/filters_test.go index db78d4b06a4f..56b208d21aee 100644 --- a/controlplane/kubeadm/internal/filters_test.go +++ b/controlplane/kubeadm/internal/filters_test.go @@ -548,7 +548,7 @@ func TestMatchInitOrJoinConfiguration(t *testing.T) { }, JoinConfiguration: nil, Files: nil, - ... // 10 identical fields + ... // 11 identical fields }`)) }) t.Run("returns true if JoinConfiguration is equal", func(t *testing.T) { @@ -673,7 +673,7 @@ func TestMatchInitOrJoinConfiguration(t *testing.T) { }, Files: nil, DiskSetup: nil, - ... // 9 identical fields + ... // 10 identical fields }`)) }) t.Run("returns false if some other configurations are not equal", func(t *testing.T) { @@ -734,7 +734,7 @@ func TestMatchInitOrJoinConfiguration(t *testing.T) { + Files: []v1beta1.File{}, DiskSetup: nil, Mounts: nil, - ... // 8 identical fields + ... // 9 identical fields }`)) }) } @@ -920,7 +920,7 @@ func TestMatchesKubeadmBootstrapConfig(t *testing.T) { }, JoinConfiguration: nil, Files: nil, - ... // 10 identical fields + ... // 11 identical fields }`)) }) t.Run("returns true if JoinConfiguration is equal", func(t *testing.T) { @@ -1045,7 +1045,7 @@ func TestMatchesKubeadmBootstrapConfig(t *testing.T) { }, Files: nil, DiskSetup: nil, - ... // 9 identical fields + ... // 10 identical fields }`)) }) t.Run("returns false if some other configurations are not equal", func(t *testing.T) { @@ -1106,7 +1106,7 @@ func TestMatchesKubeadmBootstrapConfig(t *testing.T) { + Files: []v1beta1.File{}, DiskSetup: nil, Mounts: nil, - ... // 8 identical fields + ... // 9 identical fields }`)) }) t.Run("should match on labels and annotations", func(t *testing.T) { From 19d52df391254a04058dbead92751bc95f1ee794 Mon Sep 17 00:00:00 2001 From: davidumea Date: Fri, 18 Oct 2024 15:45:48 +0200 Subject: [PATCH 06/18] fixup: clearer documentation for BootCommands, PreKubeadmCommands and PostKubeadmCommands --- bootstrap/kubeadm/api/v1beta1/kubeadmconfig_types.go | 11 ++++++++--- .../bootstrap/kubeadm/v1alpha3/kubeadmconfig_types.go | 11 ++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/bootstrap/kubeadm/api/v1beta1/kubeadmconfig_types.go b/bootstrap/kubeadm/api/v1beta1/kubeadmconfig_types.go index 7e7cddae51d6..8f1823ddee76 100644 --- a/bootstrap/kubeadm/api/v1beta1/kubeadmconfig_types.go +++ b/bootstrap/kubeadm/api/v1beta1/kubeadmconfig_types.go @@ -75,15 +75,20 @@ type KubeadmConfigSpec struct { // +optional Mounts []MountPoints `json:"mounts,omitempty"` - // BootCommands specifies extra commands to run very early in the boot process + // BootCommands specifies extra commands to run very early in the boot process via the cloud-init bootcmd + // module. This is typically run in the cloud-init.service systemd unit. This has no effect in Ignition. // +optional BootCommands []BootCommand `json:"bootCommands,omitempty"` - // PreKubeadmCommands specifies extra commands to run before kubeadm runs + // PreKubeadmCommands specifies extra commands to run before kubeadm runs. + // With cloud-init, this is prepended to the runcmd module configuration, and is typically executed in + // the cloud-final.service systemd unit. In Ignition, this is prepended to /etc/kubeadm.sh. // +optional PreKubeadmCommands []string `json:"preKubeadmCommands,omitempty"` - // postKubeadmCommands specifies extra commands to run after kubeadm runs + // PostKubeadmCommands specifies extra commands to run after kubeadm runs. + // With cloud-init, this is appended to the runcmd module configuration, and is typically executed in + // the cloud-final.service systemd unit. In Ignition, this is appended to /etc/kubeadm.sh. // +optional PostKubeadmCommands []string `json:"postKubeadmCommands,omitempty"` diff --git a/internal/apis/bootstrap/kubeadm/v1alpha3/kubeadmconfig_types.go b/internal/apis/bootstrap/kubeadm/v1alpha3/kubeadmconfig_types.go index 6135e39bd44d..82a71e7b94c2 100644 --- a/internal/apis/bootstrap/kubeadm/v1alpha3/kubeadmconfig_types.go +++ b/internal/apis/bootstrap/kubeadm/v1alpha3/kubeadmconfig_types.go @@ -59,15 +59,20 @@ type KubeadmConfigSpec struct { // +optional Mounts []MountPoints `json:"mounts,omitempty"` - // BootCommands specifies extra commands to run very early in the boot process + // BootCommands specifies extra commands to run very early in the boot process via the cloud-init bootcmd + // module. This is typically run in the cloud-init.service systemd unit. This has no effect in Ignition. // +optional BootCommands []BootCommand `json:"bootCommands,omitempty"` - // PreKubeadmCommands specifies extra commands to run before kubeadm runs + // PreKubeadmCommands specifies extra commands to run before kubeadm runs. + // With cloud-init, this is prepended to the runcmd module configuration, and is typically executed in + // the cloud-final.service systemd unit. In Ignition, this is prepended to /etc/kubeadm.sh. // +optional PreKubeadmCommands []string `json:"preKubeadmCommands,omitempty"` - // postKubeadmCommands specifies extra commands to run after kubeadm runs + // PostKubeadmCommands specifies extra commands to run after kubeadm runs. + // With cloud-init, this is appended to the runcmd module configuration, and is typically executed in + // the cloud-final.service systemd unit. In Ignition, this is appended to /etc/kubeadm.sh. // +optional PostKubeadmCommands []string `json:"postKubeadmCommands,omitempty"` From 51068a24c905b76b5dcee75dc62dcf5461d9443b Mon Sep 17 00:00:00 2001 From: davidumea Date: Fri, 18 Oct 2024 15:54:01 +0200 Subject: [PATCH 07/18] fixup: verify: reflect new documentation in the crds --- ...strap.cluster.x-k8s.io_kubeadmconfigs.yaml | 34 ++++++++++++------- ...uster.x-k8s.io_kubeadmconfigtemplates.yaml | 34 ++++++++++++------- ...cluster.x-k8s.io_kubeadmcontrolplanes.yaml | 34 ++++++++++++------- ...x-k8s.io_kubeadmcontrolplanetemplates.yaml | 17 ++++++---- 4 files changed, 77 insertions(+), 42 deletions(-) diff --git a/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml b/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml index 6033a7a41121..17df1493a5d6 100644 --- a/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml +++ b/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml @@ -48,8 +48,9 @@ spec: Either ClusterConfiguration and InitConfiguration should be defined or the JoinConfiguration should be defined. properties: bootCommands: - description: BootCommands specifies extra commands to run very early - in the boot process + description: |- + BootCommands specifies extra commands to run very early in the boot process via the cloud-init bootcmd + module. This is typically run in the cloud-init.service systemd unit. This has no effect in Ignition. items: description: BootCommand defines input for each bootcmd command in cloud-init. @@ -865,14 +866,18 @@ spec: type: array type: object postKubeadmCommands: - description: postKubeadmCommands specifies extra commands to run after - kubeadm runs + description: |- + PostKubeadmCommands specifies extra commands to run after kubeadm runs. + With cloud-init, this is appended to the runcmd module configuration, and is typically executed in + the cloud-final.service systemd unit. In Ignition, this is appended to /etc/kubeadm.sh. items: type: string type: array preKubeadmCommands: - description: preKubeadmCommands specifies extra commands to run before - kubeadm runs + description: |- + PreKubeadmCommands specifies extra commands to run before kubeadm runs. + With cloud-init, this is prepended to the runcmd module configuration, and is typically executed in + the cloud-final.service systemd unit. In Ignition, this is prepended to /etc/kubeadm.sh. items: type: string type: array @@ -2066,8 +2071,9 @@ spec: Either ClusterConfiguration and InitConfiguration should be defined or the JoinConfiguration should be defined. properties: bootCommands: - description: BootCommands specifies extra commands to run very early - in the boot process + description: |- + BootCommands specifies extra commands to run very early in the boot process via the cloud-init bootcmd + module. This is typically run in the cloud-init.service systemd unit. This has no effect in Ignition. items: description: BootCommand defines input for each bootcmd command in cloud-init. @@ -3621,14 +3627,18 @@ spec: type: array type: object postKubeadmCommands: - description: postKubeadmCommands specifies extra commands to run after - kubeadm runs + description: |- + PostKubeadmCommands specifies extra commands to run after kubeadm runs. + With cloud-init, this is appended to the runcmd module configuration, and is typically executed in + the cloud-final.service systemd unit. In Ignition, this is appended to /etc/kubeadm.sh. items: type: string type: array preKubeadmCommands: - description: preKubeadmCommands specifies extra commands to run before - kubeadm runs + description: |- + PreKubeadmCommands specifies extra commands to run before kubeadm runs. + With cloud-init, this is prepended to the runcmd module configuration, and is typically executed in + the cloud-final.service systemd unit. In Ignition, this is prepended to /etc/kubeadm.sh. items: type: string type: array diff --git a/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml b/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml index d239512056f8..fb8fef173cbb 100644 --- a/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml +++ b/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml @@ -54,8 +54,9 @@ spec: Either ClusterConfiguration and InitConfiguration should be defined or the JoinConfiguration should be defined. properties: bootCommands: - description: BootCommands specifies extra commands to run - very early in the boot process + description: |- + BootCommands specifies extra commands to run very early in the boot process via the cloud-init bootcmd + module. This is typically run in the cloud-init.service systemd unit. This has no effect in Ignition. items: description: BootCommand defines input for each bootcmd command in cloud-init. @@ -889,14 +890,18 @@ spec: type: array type: object postKubeadmCommands: - description: postKubeadmCommands specifies extra commands - to run after kubeadm runs + description: |- + PostKubeadmCommands specifies extra commands to run after kubeadm runs. + With cloud-init, this is appended to the runcmd module configuration, and is typically executed in + the cloud-final.service systemd unit. In Ignition, this is appended to /etc/kubeadm.sh. items: type: string type: array preKubeadmCommands: - description: preKubeadmCommands specifies extra commands to - run before kubeadm runs + description: |- + PreKubeadmCommands specifies extra commands to run before kubeadm runs. + With cloud-init, this is prepended to the runcmd module configuration, and is typically executed in + the cloud-final.service systemd unit. In Ignition, this is prepended to /etc/kubeadm.sh. items: type: string type: array @@ -2013,8 +2018,9 @@ spec: Either ClusterConfiguration and InitConfiguration should be defined or the JoinConfiguration should be defined. properties: bootCommands: - description: BootCommands specifies extra commands to run - very early in the boot process + description: |- + BootCommands specifies extra commands to run very early in the boot process via the cloud-init bootcmd + module. This is typically run in the cloud-init.service systemd unit. This has no effect in Ignition. items: description: BootCommand defines input for each bootcmd command in cloud-init. @@ -3611,14 +3617,18 @@ spec: type: array type: object postKubeadmCommands: - description: postKubeadmCommands specifies extra commands - to run after kubeadm runs + description: |- + PostKubeadmCommands specifies extra commands to run after kubeadm runs. + With cloud-init, this is appended to the runcmd module configuration, and is typically executed in + the cloud-final.service systemd unit. In Ignition, this is appended to /etc/kubeadm.sh. items: type: string type: array preKubeadmCommands: - description: preKubeadmCommands specifies extra commands to - run before kubeadm runs + description: |- + PreKubeadmCommands specifies extra commands to run before kubeadm runs. + With cloud-init, this is prepended to the runcmd module configuration, and is typically executed in + the cloud-final.service systemd unit. In Ignition, this is prepended to /etc/kubeadm.sh. items: type: string type: array diff --git a/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml b/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml index 5f2a325d60ef..bd1fba5aed92 100644 --- a/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml +++ b/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml @@ -130,8 +130,9 @@ spec: to use for initializing and joining machines to the control plane. properties: bootCommands: - description: BootCommands specifies extra commands to run very - early in the boot process + description: |- + BootCommands specifies extra commands to run very early in the boot process via the cloud-init bootcmd + module. This is typically run in the cloud-init.service systemd unit. This has no effect in Ignition. items: description: BootCommand defines input for each bootcmd command in cloud-init. @@ -956,14 +957,18 @@ spec: type: array type: object postKubeadmCommands: - description: postKubeadmCommands specifies extra commands to run - after kubeadm runs + description: |- + PostKubeadmCommands specifies extra commands to run after kubeadm runs. + With cloud-init, this is appended to the runcmd module configuration, and is typically executed in + the cloud-final.service systemd unit. In Ignition, this is appended to /etc/kubeadm.sh. items: type: string type: array preKubeadmCommands: - description: preKubeadmCommands specifies extra commands to run - before kubeadm runs + description: |- + PreKubeadmCommands specifies extra commands to run before kubeadm runs. + With cloud-init, this is prepended to the runcmd module configuration, and is typically executed in + the cloud-final.service systemd unit. In Ignition, this is prepended to /etc/kubeadm.sh. items: type: string type: array @@ -2531,8 +2536,9 @@ spec: to use for initializing and joining machines to the control plane. properties: bootCommands: - description: BootCommands specifies extra commands to run very - early in the boot process + description: |- + BootCommands specifies extra commands to run very early in the boot process via the cloud-init bootcmd + module. This is typically run in the cloud-init.service systemd unit. This has no effect in Ignition. items: description: BootCommand defines input for each bootcmd command in cloud-init. @@ -4106,14 +4112,18 @@ spec: type: array type: object postKubeadmCommands: - description: postKubeadmCommands specifies extra commands to run - after kubeadm runs + description: |- + PostKubeadmCommands specifies extra commands to run after kubeadm runs. + With cloud-init, this is appended to the runcmd module configuration, and is typically executed in + the cloud-final.service systemd unit. In Ignition, this is appended to /etc/kubeadm.sh. items: type: string type: array preKubeadmCommands: - description: preKubeadmCommands specifies extra commands to run - before kubeadm runs + description: |- + PreKubeadmCommands specifies extra commands to run before kubeadm runs. + With cloud-init, this is prepended to the runcmd module configuration, and is typically executed in + the cloud-final.service systemd unit. In Ignition, this is prepended to /etc/kubeadm.sh. items: type: string type: array diff --git a/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanetemplates.yaml b/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanetemplates.yaml index 19a4ff7519b0..41bcab7aacd7 100644 --- a/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanetemplates.yaml +++ b/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanetemplates.yaml @@ -1216,8 +1216,9 @@ spec: to use for initializing and joining machines to the control plane. properties: bootCommands: - description: BootCommands specifies extra commands to - run very early in the boot process + description: |- + BootCommands specifies extra commands to run very early in the boot process via the cloud-init bootcmd + module. This is typically run in the cloud-init.service systemd unit. This has no effect in Ignition. items: description: BootCommand defines input for each bootcmd command in cloud-init. @@ -2835,14 +2836,18 @@ spec: type: array type: object postKubeadmCommands: - description: postKubeadmCommands specifies extra commands - to run after kubeadm runs + description: |- + PostKubeadmCommands specifies extra commands to run after kubeadm runs. + With cloud-init, this is appended to the runcmd module configuration, and is typically executed in + the cloud-final.service systemd unit. In Ignition, this is appended to /etc/kubeadm.sh. items: type: string type: array preKubeadmCommands: - description: preKubeadmCommands specifies extra commands - to run before kubeadm runs + description: |- + PreKubeadmCommands specifies extra commands to run before kubeadm runs. + With cloud-init, this is prepended to the runcmd module configuration, and is typically executed in + the cloud-final.service systemd unit. In Ignition, this is prepended to /etc/kubeadm.sh. items: type: string type: array From 8ed017157257cfd07a27c348adbbac02fbe11fba Mon Sep 17 00:00:00 2001 From: davidumea Date: Tue, 22 Oct 2024 09:19:12 +0200 Subject: [PATCH 08/18] fixup: restore v1alpha3,v1alpha4 and add conversions --- ...strap.cluster.x-k8s.io_kubeadmconfigs.yaml | 33 +++---------------- ...uster.x-k8s.io_kubeadmconfigtemplates.yaml | 33 +++---------------- ...cluster.x-k8s.io_kubeadmcontrolplanes.yaml | 33 +++---------------- ...x-k8s.io_kubeadmcontrolplanetemplates.yaml | 10 ------ .../bootstrap/kubeadm/v1alpha3/conversion.go | 2 ++ .../kubeadm/v1alpha3/kubeadmconfig_types.go | 16 ++------- .../v1alpha3/zz_generated.conversion.go | 3 +- .../bootstrap/kubeadm/v1alpha4/conversion.go | 2 ++ .../kubeadm/v1alpha4/kubeadmconfig_types.go | 7 ---- .../v1alpha4/zz_generated.conversion.go | 3 +- 10 files changed, 20 insertions(+), 122 deletions(-) diff --git a/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml b/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml index 17df1493a5d6..a4c3a9d47f0e 100644 --- a/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml +++ b/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml @@ -47,17 +47,6 @@ spec: KubeadmConfigSpec defines the desired state of KubeadmConfig. Either ClusterConfiguration and InitConfiguration should be defined or the JoinConfiguration should be defined. properties: - bootCommands: - description: |- - BootCommands specifies extra commands to run very early in the boot process via the cloud-init bootcmd - module. This is typically run in the cloud-init.service systemd unit. This has no effect in Ignition. - items: - description: BootCommand defines input for each bootcmd command - in cloud-init. - items: - type: string - type: array - type: array clusterConfiguration: description: clusterConfiguration along with InitConfiguration are the configurations necessary for the init command @@ -866,18 +855,14 @@ spec: type: array type: object postKubeadmCommands: - description: |- - PostKubeadmCommands specifies extra commands to run after kubeadm runs. - With cloud-init, this is appended to the runcmd module configuration, and is typically executed in - the cloud-final.service systemd unit. In Ignition, this is appended to /etc/kubeadm.sh. + description: PostKubeadmCommands specifies extra commands to run after + kubeadm runs items: type: string type: array preKubeadmCommands: - description: |- - PreKubeadmCommands specifies extra commands to run before kubeadm runs. - With cloud-init, this is prepended to the runcmd module configuration, and is typically executed in - the cloud-final.service systemd unit. In Ignition, this is prepended to /etc/kubeadm.sh. + description: PreKubeadmCommands specifies extra commands to run before + kubeadm runs items: type: string type: array @@ -1066,16 +1051,6 @@ spec: KubeadmConfigSpec defines the desired state of KubeadmConfig. Either ClusterConfiguration and InitConfiguration should be defined or the JoinConfiguration should be defined. properties: - bootCommands: - description: BootCommands specifies extra commands to run before kubeadm - runs - items: - description: BootCommand defines input for each bootcmd command - in cloud-init. - items: - type: string - type: array - type: array clusterConfiguration: description: clusterConfiguration along with InitConfiguration are the configurations necessary for the init command diff --git a/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml b/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml index fb8fef173cbb..b3a2c4193d76 100644 --- a/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml +++ b/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml @@ -53,17 +53,6 @@ spec: KubeadmConfigSpec defines the desired state of KubeadmConfig. Either ClusterConfiguration and InitConfiguration should be defined or the JoinConfiguration should be defined. properties: - bootCommands: - description: |- - BootCommands specifies extra commands to run very early in the boot process via the cloud-init bootcmd - module. This is typically run in the cloud-init.service systemd unit. This has no effect in Ignition. - items: - description: BootCommand defines input for each bootcmd - command in cloud-init. - items: - type: string - type: array - type: array clusterConfiguration: description: clusterConfiguration along with InitConfiguration are the configurations necessary for the init command @@ -890,18 +879,14 @@ spec: type: array type: object postKubeadmCommands: - description: |- - PostKubeadmCommands specifies extra commands to run after kubeadm runs. - With cloud-init, this is appended to the runcmd module configuration, and is typically executed in - the cloud-final.service systemd unit. In Ignition, this is appended to /etc/kubeadm.sh. + description: PostKubeadmCommands specifies extra commands + to run after kubeadm runs items: type: string type: array preKubeadmCommands: - description: |- - PreKubeadmCommands specifies extra commands to run before kubeadm runs. - With cloud-init, this is prepended to the runcmd module configuration, and is typically executed in - the cloud-final.service systemd unit. In Ignition, this is prepended to /etc/kubeadm.sh. + description: PreKubeadmCommands specifies extra commands to + run before kubeadm runs items: type: string type: array @@ -1027,16 +1012,6 @@ spec: KubeadmConfigSpec defines the desired state of KubeadmConfig. Either ClusterConfiguration and InitConfiguration should be defined or the JoinConfiguration should be defined. properties: - bootCommands: - description: BootCommands specifies extra commands to run - before kubeadm runs - items: - description: BootCommand defines input for each bootcmd - command in cloud-init. - items: - type: string - type: array - type: array clusterConfiguration: description: clusterConfiguration along with InitConfiguration are the configurations necessary for the init command diff --git a/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml b/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml index bd1fba5aed92..698b9ec46c64 100644 --- a/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml +++ b/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml @@ -129,17 +129,6 @@ spec: kubeadmConfigSpec is a KubeadmConfigSpec to use for initializing and joining machines to the control plane. properties: - bootCommands: - description: |- - BootCommands specifies extra commands to run very early in the boot process via the cloud-init bootcmd - module. This is typically run in the cloud-init.service systemd unit. This has no effect in Ignition. - items: - description: BootCommand defines input for each bootcmd command - in cloud-init. - items: - type: string - type: array - type: array clusterConfiguration: description: clusterConfiguration along with InitConfiguration are the configurations necessary for the init command @@ -957,18 +946,14 @@ spec: type: array type: object postKubeadmCommands: - description: |- - PostKubeadmCommands specifies extra commands to run after kubeadm runs. - With cloud-init, this is appended to the runcmd module configuration, and is typically executed in - the cloud-final.service systemd unit. In Ignition, this is appended to /etc/kubeadm.sh. + description: PostKubeadmCommands specifies extra commands to run + after kubeadm runs items: type: string type: array preKubeadmCommands: - description: |- - PreKubeadmCommands specifies extra commands to run before kubeadm runs. - With cloud-init, this is prepended to the runcmd module configuration, and is typically executed in - the cloud-final.service systemd unit. In Ignition, this is prepended to /etc/kubeadm.sh. + description: PreKubeadmCommands specifies extra commands to run + before kubeadm runs items: type: string type: array @@ -1289,16 +1274,6 @@ spec: kubeadmConfigSpec is a KubeadmConfigSpec to use for initializing and joining machines to the control plane. properties: - bootCommands: - description: BootCommands specifies extra commands to run before - kubeadm runs - items: - description: BootCommand defines input for each bootcmd command - in cloud-init. - items: - type: string - type: array - type: array clusterConfiguration: description: clusterConfiguration along with InitConfiguration are the configurations necessary for the init command diff --git a/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanetemplates.yaml b/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanetemplates.yaml index 41bcab7aacd7..2b44af5320ca 100644 --- a/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanetemplates.yaml +++ b/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanetemplates.yaml @@ -64,16 +64,6 @@ spec: kubeadmConfigSpec is a KubeadmConfigSpec to use for initializing and joining machines to the control plane. properties: - bootCommands: - description: BootCommands specifies extra commands to - run before kubeadm runs - items: - description: BootCommand defines input for each bootcmd - command in cloud-init. - items: - type: string - type: array - type: array clusterConfiguration: description: clusterConfiguration along with InitConfiguration are the configurations necessary for the init command diff --git a/internal/apis/bootstrap/kubeadm/v1alpha3/conversion.go b/internal/apis/bootstrap/kubeadm/v1alpha3/conversion.go index 4d02942935a3..3bc99558d336 100644 --- a/internal/apis/bootstrap/kubeadm/v1alpha3/conversion.go +++ b/internal/apis/bootstrap/kubeadm/v1alpha3/conversion.go @@ -55,6 +55,8 @@ func MergeRestoredKubeadmConfigSpec(dst *bootstrapv1.KubeadmConfigSpec, restored } } + dst.BootCommands = restored.BootCommands + dst.Ignition = restored.Ignition if restored.ClusterConfiguration != nil { diff --git a/internal/apis/bootstrap/kubeadm/v1alpha3/kubeadmconfig_types.go b/internal/apis/bootstrap/kubeadm/v1alpha3/kubeadmconfig_types.go index 82a71e7b94c2..d3e66d4cf33b 100644 --- a/internal/apis/bootstrap/kubeadm/v1alpha3/kubeadmconfig_types.go +++ b/internal/apis/bootstrap/kubeadm/v1alpha3/kubeadmconfig_types.go @@ -59,20 +59,11 @@ type KubeadmConfigSpec struct { // +optional Mounts []MountPoints `json:"mounts,omitempty"` - // BootCommands specifies extra commands to run very early in the boot process via the cloud-init bootcmd - // module. This is typically run in the cloud-init.service systemd unit. This has no effect in Ignition. - // +optional - BootCommands []BootCommand `json:"bootCommands,omitempty"` - - // PreKubeadmCommands specifies extra commands to run before kubeadm runs. - // With cloud-init, this is prepended to the runcmd module configuration, and is typically executed in - // the cloud-final.service systemd unit. In Ignition, this is prepended to /etc/kubeadm.sh. + // PreKubeadmCommands specifies extra commands to run before kubeadm runs // +optional PreKubeadmCommands []string `json:"preKubeadmCommands,omitempty"` - // PostKubeadmCommands specifies extra commands to run after kubeadm runs. - // With cloud-init, this is appended to the runcmd module configuration, and is typically executed in - // the cloud-final.service systemd unit. In Ignition, this is appended to /etc/kubeadm.sh. + // PostKubeadmCommands specifies extra commands to run after kubeadm runs // +optional PostKubeadmCommands []string `json:"postKubeadmCommands,omitempty"` @@ -351,6 +342,3 @@ type Filesystem struct { // MountPoints defines input for generated mounts in cloud-init. type MountPoints []string - -// BootCommand defines input for each bootcmd command in cloud-init. -type BootCommand []string diff --git a/internal/apis/bootstrap/kubeadm/v1alpha3/zz_generated.conversion.go b/internal/apis/bootstrap/kubeadm/v1alpha3/zz_generated.conversion.go index 9ef292f2fb60..48a378086ddd 100644 --- a/internal/apis/bootstrap/kubeadm/v1alpha3/zz_generated.conversion.go +++ b/internal/apis/bootstrap/kubeadm/v1alpha3/zz_generated.conversion.go @@ -451,7 +451,6 @@ func autoConvert_v1alpha3_KubeadmConfigSpec_To_v1beta1_KubeadmConfigSpec(in *Kub } out.DiskSetup = (*v1beta1.DiskSetup)(unsafe.Pointer(in.DiskSetup)) out.Mounts = *(*[]v1beta1.MountPoints)(unsafe.Pointer(&in.Mounts)) - out.BootCommands = *(*[]v1beta1.BootCommand)(unsafe.Pointer(&in.BootCommands)) out.PreKubeadmCommands = *(*[]string)(unsafe.Pointer(&in.PreKubeadmCommands)) out.PostKubeadmCommands = *(*[]string)(unsafe.Pointer(&in.PostKubeadmCommands)) if in.Users != nil { @@ -518,7 +517,7 @@ func autoConvert_v1beta1_KubeadmConfigSpec_To_v1alpha3_KubeadmConfigSpec(in *v1b } out.DiskSetup = (*DiskSetup)(unsafe.Pointer(in.DiskSetup)) out.Mounts = *(*[]MountPoints)(unsafe.Pointer(&in.Mounts)) - out.BootCommands = *(*[]BootCommand)(unsafe.Pointer(&in.BootCommands)) + // WARNING: in.BootCommands requires manual conversion: does not exist in peer-type out.PreKubeadmCommands = *(*[]string)(unsafe.Pointer(&in.PreKubeadmCommands)) out.PostKubeadmCommands = *(*[]string)(unsafe.Pointer(&in.PostKubeadmCommands)) if in.Users != nil { diff --git a/internal/apis/bootstrap/kubeadm/v1alpha4/conversion.go b/internal/apis/bootstrap/kubeadm/v1alpha4/conversion.go index 3f9597aa6784..fa2caf92bfe4 100644 --- a/internal/apis/bootstrap/kubeadm/v1alpha4/conversion.go +++ b/internal/apis/bootstrap/kubeadm/v1alpha4/conversion.go @@ -54,6 +54,8 @@ func MergeRestoredKubeadmConfigSpec(dst *bootstrapv1.KubeadmConfigSpec, restored } } + dst.BootCommands = restored.BootCommands + dst.Ignition = restored.Ignition if restored.ClusterConfiguration != nil { diff --git a/internal/apis/bootstrap/kubeadm/v1alpha4/kubeadmconfig_types.go b/internal/apis/bootstrap/kubeadm/v1alpha4/kubeadmconfig_types.go index ea1a80664645..6850aeccfc92 100644 --- a/internal/apis/bootstrap/kubeadm/v1alpha4/kubeadmconfig_types.go +++ b/internal/apis/bootstrap/kubeadm/v1alpha4/kubeadmconfig_types.go @@ -58,10 +58,6 @@ type KubeadmConfigSpec struct { // +optional Mounts []MountPoints `json:"mounts,omitempty"` - // BootCommands specifies extra commands to run before kubeadm runs - // +optional - BootCommands []BootCommand `json:"bootCommands,omitempty"` - // PreKubeadmCommands specifies extra commands to run before kubeadm runs // +optional PreKubeadmCommands []string `json:"preKubeadmCommands,omitempty"` @@ -339,6 +335,3 @@ type Filesystem struct { // MountPoints defines input for generated mounts in cloud-init. type MountPoints []string - -// BootCommand defines input for each bootcmd command in cloud-init. -type BootCommand []string diff --git a/internal/apis/bootstrap/kubeadm/v1alpha4/zz_generated.conversion.go b/internal/apis/bootstrap/kubeadm/v1alpha4/zz_generated.conversion.go index d40f4edd8ee4..ecddbbb13496 100644 --- a/internal/apis/bootstrap/kubeadm/v1alpha4/zz_generated.conversion.go +++ b/internal/apis/bootstrap/kubeadm/v1alpha4/zz_generated.conversion.go @@ -1144,7 +1144,6 @@ func autoConvert_v1alpha4_KubeadmConfigSpec_To_v1beta1_KubeadmConfigSpec(in *Kub } out.DiskSetup = (*v1beta1.DiskSetup)(unsafe.Pointer(in.DiskSetup)) out.Mounts = *(*[]v1beta1.MountPoints)(unsafe.Pointer(&in.Mounts)) - out.BootCommands = *(*[]v1beta1.BootCommand)(unsafe.Pointer(&in.BootCommands)) out.PreKubeadmCommands = *(*[]string)(unsafe.Pointer(&in.PreKubeadmCommands)) out.PostKubeadmCommands = *(*[]string)(unsafe.Pointer(&in.PostKubeadmCommands)) if in.Users != nil { @@ -1211,7 +1210,7 @@ func autoConvert_v1beta1_KubeadmConfigSpec_To_v1alpha4_KubeadmConfigSpec(in *v1b } out.DiskSetup = (*DiskSetup)(unsafe.Pointer(in.DiskSetup)) out.Mounts = *(*[]MountPoints)(unsafe.Pointer(&in.Mounts)) - out.BootCommands = *(*[]BootCommand)(unsafe.Pointer(&in.BootCommands)) + // WARNING: in.BootCommands requires manual conversion: does not exist in peer-type out.PreKubeadmCommands = *(*[]string)(unsafe.Pointer(&in.PreKubeadmCommands)) out.PostKubeadmCommands = *(*[]string)(unsafe.Pointer(&in.PostKubeadmCommands)) if in.Users != nil { From 332e78d21eb185072433edc72235649f26e190a6 Mon Sep 17 00:00:00 2001 From: davidumea Date: Tue, 22 Oct 2024 10:21:05 +0200 Subject: [PATCH 09/18] fixup: non-nil values for bootcommands in cloudinit tests --- bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go b/bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go index 72041d2a7555..fa012bbb522e 100644 --- a/bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go +++ b/bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go @@ -96,7 +96,9 @@ func TestNewInitControlPlaneCommands(t *testing.T) { cpinput := &ControlPlaneInput{ BaseUserData: BaseUserData{ Header: "test", - BootCommands: nil, + BootCommands: []bootstrapv1.BootCommand{ + {"echo", "hello"}, + }, PreKubeadmCommands: []string{`"echo $(date) ': hello world!'"`}, PostKubeadmCommands: []string{"echo $(date) ': hello world!'"}, AdditionalFiles: nil, @@ -198,7 +200,9 @@ func TestNewJoinControlPlaneAdditionalFileEncodings(t *testing.T) { cpinput := &ControlPlaneJoinInput{ BaseUserData: BaseUserData{ Header: "test", - BootCommands: nil, + BootCommands: []bootstrapv1.BootCommand{ + {"echo", "hello"}, + }, PreKubeadmCommands: nil, PostKubeadmCommands: nil, AdditionalFiles: []bootstrapv1.File{ From 28edd6c1e9414d58c172679f74af473c5fdafb2c Mon Sep 17 00:00:00 2001 From: davidumea Date: Tue, 22 Oct 2024 10:29:48 +0200 Subject: [PATCH 10/18] fixup: lint --- bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go b/bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go index fa012bbb522e..73b4efb98b44 100644 --- a/bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go +++ b/bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go @@ -95,10 +95,10 @@ func TestNewInitControlPlaneCommands(t *testing.T) { cpinput := &ControlPlaneInput{ BaseUserData: BaseUserData{ - Header: "test", BootCommands: []bootstrapv1.BootCommand{ {"echo", "hello"}, }, + Header: "test", PreKubeadmCommands: []string{`"echo $(date) ': hello world!'"`}, PostKubeadmCommands: []string{"echo $(date) ': hello world!'"}, AdditionalFiles: nil, @@ -199,10 +199,10 @@ func TestNewJoinControlPlaneAdditionalFileEncodings(t *testing.T) { cpinput := &ControlPlaneJoinInput{ BaseUserData: BaseUserData{ - Header: "test", BootCommands: []bootstrapv1.BootCommand{ {"echo", "hello"}, }, + Header: "test", PreKubeadmCommands: nil, PostKubeadmCommands: nil, AdditionalFiles: []bootstrapv1.File{ From 8918ff37ce05f5793621094c5e9ca990dbd03c10 Mon Sep 17 00:00:00 2001 From: davidumea Date: Tue, 5 Nov 2024 09:53:36 +0100 Subject: [PATCH 11/18] fixup: verify crds --- .../crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml | 2 +- .../bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml | 2 +- .../controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml | 2 +- ...trolplane.cluster.x-k8s.io_kubeadmcontrolplanetemplates.yaml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml b/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml index a4c3a9d47f0e..4db060b14506 100644 --- a/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml +++ b/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml @@ -1862,7 +1862,7 @@ spec: type: string type: array preKubeadmCommands: - description: preKubeadmCommands specifies extra commands to run before + description: PreKubeadmCommands specifies extra commands to run before kubeadm runs items: type: string diff --git a/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml b/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml index b3a2c4193d76..7ad34d763935 100644 --- a/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml +++ b/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml @@ -1843,7 +1843,7 @@ spec: type: string type: array preKubeadmCommands: - description: preKubeadmCommands specifies extra commands to + description: PreKubeadmCommands specifies extra commands to run before kubeadm runs items: type: string diff --git a/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml b/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml index 698b9ec46c64..bad79f6c5726 100644 --- a/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml +++ b/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml @@ -2096,7 +2096,7 @@ spec: type: string type: array preKubeadmCommands: - description: preKubeadmCommands specifies extra commands to run + description: PreKubeadmCommands specifies extra commands to run before kubeadm runs items: type: string diff --git a/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanetemplates.yaml b/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanetemplates.yaml index 2b44af5320ca..04fdaec45b88 100644 --- a/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanetemplates.yaml +++ b/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanetemplates.yaml @@ -904,7 +904,7 @@ spec: type: string type: array preKubeadmCommands: - description: preKubeadmCommands specifies extra commands + description: PreKubeadmCommands specifies extra commands to run before kubeadm runs items: type: string From 94835dc3c15ca8672705154c5a8f4c0d2a1782f8 Mon Sep 17 00:00:00 2001 From: davidumea Date: Mon, 25 Nov 2024 17:34:16 +0100 Subject: [PATCH 12/18] fixup: use yaml names in go doc comments --- bootstrap/kubeadm/api/v1beta1/kubeadmconfig_types.go | 6 +++--- .../bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml | 12 ++++++------ ...trap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml | 12 ++++++------ ...lplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml | 12 ++++++------ ...luster.x-k8s.io_kubeadmcontrolplanetemplates.yaml | 8 ++++---- .../kubeadm/v1alpha3/kubeadmconfig_types.go | 4 ++-- .../kubeadm/v1alpha4/kubeadmconfig_types.go | 2 +- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/bootstrap/kubeadm/api/v1beta1/kubeadmconfig_types.go b/bootstrap/kubeadm/api/v1beta1/kubeadmconfig_types.go index 8f1823ddee76..208e06a68c8a 100644 --- a/bootstrap/kubeadm/api/v1beta1/kubeadmconfig_types.go +++ b/bootstrap/kubeadm/api/v1beta1/kubeadmconfig_types.go @@ -75,18 +75,18 @@ type KubeadmConfigSpec struct { // +optional Mounts []MountPoints `json:"mounts,omitempty"` - // BootCommands specifies extra commands to run very early in the boot process via the cloud-init bootcmd + // bootCommands specifies extra commands to run very early in the boot process via the cloud-init bootcmd // module. This is typically run in the cloud-init.service systemd unit. This has no effect in Ignition. // +optional BootCommands []BootCommand `json:"bootCommands,omitempty"` - // PreKubeadmCommands specifies extra commands to run before kubeadm runs. + // preKubeadmCommands specifies extra commands to run before kubeadm runs. // With cloud-init, this is prepended to the runcmd module configuration, and is typically executed in // the cloud-final.service systemd unit. In Ignition, this is prepended to /etc/kubeadm.sh. // +optional PreKubeadmCommands []string `json:"preKubeadmCommands,omitempty"` - // PostKubeadmCommands specifies extra commands to run after kubeadm runs. + // postKubeadmCommands specifies extra commands to run after kubeadm runs. // With cloud-init, this is appended to the runcmd module configuration, and is typically executed in // the cloud-final.service systemd unit. In Ignition, this is appended to /etc/kubeadm.sh. // +optional diff --git a/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml b/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml index 4db060b14506..72bb8af89fff 100644 --- a/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml +++ b/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml @@ -855,13 +855,13 @@ spec: type: array type: object postKubeadmCommands: - description: PostKubeadmCommands specifies extra commands to run after + description: postKubeadmCommands specifies extra commands to run after kubeadm runs items: type: string type: array preKubeadmCommands: - description: PreKubeadmCommands specifies extra commands to run before + description: preKubeadmCommands specifies extra commands to run before kubeadm runs items: type: string @@ -1862,7 +1862,7 @@ spec: type: string type: array preKubeadmCommands: - description: PreKubeadmCommands specifies extra commands to run before + description: preKubeadmCommands specifies extra commands to run before kubeadm runs items: type: string @@ -2047,7 +2047,7 @@ spec: properties: bootCommands: description: |- - BootCommands specifies extra commands to run very early in the boot process via the cloud-init bootcmd + bootCommands specifies extra commands to run very early in the boot process via the cloud-init bootcmd module. This is typically run in the cloud-init.service systemd unit. This has no effect in Ignition. items: description: BootCommand defines input for each bootcmd command @@ -3603,7 +3603,7 @@ spec: type: object postKubeadmCommands: description: |- - PostKubeadmCommands specifies extra commands to run after kubeadm runs. + postKubeadmCommands specifies extra commands to run after kubeadm runs. With cloud-init, this is appended to the runcmd module configuration, and is typically executed in the cloud-final.service systemd unit. In Ignition, this is appended to /etc/kubeadm.sh. items: @@ -3611,7 +3611,7 @@ spec: type: array preKubeadmCommands: description: |- - PreKubeadmCommands specifies extra commands to run before kubeadm runs. + preKubeadmCommands specifies extra commands to run before kubeadm runs. With cloud-init, this is prepended to the runcmd module configuration, and is typically executed in the cloud-final.service systemd unit. In Ignition, this is prepended to /etc/kubeadm.sh. items: diff --git a/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml b/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml index 7ad34d763935..2bee123a354f 100644 --- a/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml +++ b/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml @@ -879,13 +879,13 @@ spec: type: array type: object postKubeadmCommands: - description: PostKubeadmCommands specifies extra commands + description: postKubeadmCommands specifies extra commands to run after kubeadm runs items: type: string type: array preKubeadmCommands: - description: PreKubeadmCommands specifies extra commands to + description: preKubeadmCommands specifies extra commands to run before kubeadm runs items: type: string @@ -1843,7 +1843,7 @@ spec: type: string type: array preKubeadmCommands: - description: PreKubeadmCommands specifies extra commands to + description: preKubeadmCommands specifies extra commands to run before kubeadm runs items: type: string @@ -1994,7 +1994,7 @@ spec: properties: bootCommands: description: |- - BootCommands specifies extra commands to run very early in the boot process via the cloud-init bootcmd + bootCommands specifies extra commands to run very early in the boot process via the cloud-init bootcmd module. This is typically run in the cloud-init.service systemd unit. This has no effect in Ignition. items: description: BootCommand defines input for each bootcmd @@ -3593,7 +3593,7 @@ spec: type: object postKubeadmCommands: description: |- - PostKubeadmCommands specifies extra commands to run after kubeadm runs. + postKubeadmCommands specifies extra commands to run after kubeadm runs. With cloud-init, this is appended to the runcmd module configuration, and is typically executed in the cloud-final.service systemd unit. In Ignition, this is appended to /etc/kubeadm.sh. items: @@ -3601,7 +3601,7 @@ spec: type: array preKubeadmCommands: description: |- - PreKubeadmCommands specifies extra commands to run before kubeadm runs. + preKubeadmCommands specifies extra commands to run before kubeadm runs. With cloud-init, this is prepended to the runcmd module configuration, and is typically executed in the cloud-final.service systemd unit. In Ignition, this is prepended to /etc/kubeadm.sh. items: diff --git a/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml b/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml index bad79f6c5726..1d592b829bab 100644 --- a/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml +++ b/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml @@ -946,13 +946,13 @@ spec: type: array type: object postKubeadmCommands: - description: PostKubeadmCommands specifies extra commands to run + description: postKubeadmCommands specifies extra commands to run after kubeadm runs items: type: string type: array preKubeadmCommands: - description: PreKubeadmCommands specifies extra commands to run + description: preKubeadmCommands specifies extra commands to run before kubeadm runs items: type: string @@ -2096,7 +2096,7 @@ spec: type: string type: array preKubeadmCommands: - description: PreKubeadmCommands specifies extra commands to run + description: preKubeadmCommands specifies extra commands to run before kubeadm runs items: type: string @@ -2512,7 +2512,7 @@ spec: properties: bootCommands: description: |- - BootCommands specifies extra commands to run very early in the boot process via the cloud-init bootcmd + bootCommands specifies extra commands to run very early in the boot process via the cloud-init bootcmd module. This is typically run in the cloud-init.service systemd unit. This has no effect in Ignition. items: description: BootCommand defines input for each bootcmd command @@ -4088,7 +4088,7 @@ spec: type: object postKubeadmCommands: description: |- - PostKubeadmCommands specifies extra commands to run after kubeadm runs. + postKubeadmCommands specifies extra commands to run after kubeadm runs. With cloud-init, this is appended to the runcmd module configuration, and is typically executed in the cloud-final.service systemd unit. In Ignition, this is appended to /etc/kubeadm.sh. items: @@ -4096,7 +4096,7 @@ spec: type: array preKubeadmCommands: description: |- - PreKubeadmCommands specifies extra commands to run before kubeadm runs. + preKubeadmCommands specifies extra commands to run before kubeadm runs. With cloud-init, this is prepended to the runcmd module configuration, and is typically executed in the cloud-final.service systemd unit. In Ignition, this is prepended to /etc/kubeadm.sh. items: diff --git a/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanetemplates.yaml b/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanetemplates.yaml index 04fdaec45b88..a8415f605c12 100644 --- a/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanetemplates.yaml +++ b/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanetemplates.yaml @@ -904,7 +904,7 @@ spec: type: string type: array preKubeadmCommands: - description: PreKubeadmCommands specifies extra commands + description: preKubeadmCommands specifies extra commands to run before kubeadm runs items: type: string @@ -1207,7 +1207,7 @@ spec: properties: bootCommands: description: |- - BootCommands specifies extra commands to run very early in the boot process via the cloud-init bootcmd + bootCommands specifies extra commands to run very early in the boot process via the cloud-init bootcmd module. This is typically run in the cloud-init.service systemd unit. This has no effect in Ignition. items: description: BootCommand defines input for each bootcmd @@ -2827,7 +2827,7 @@ spec: type: object postKubeadmCommands: description: |- - PostKubeadmCommands specifies extra commands to run after kubeadm runs. + postKubeadmCommands specifies extra commands to run after kubeadm runs. With cloud-init, this is appended to the runcmd module configuration, and is typically executed in the cloud-final.service systemd unit. In Ignition, this is appended to /etc/kubeadm.sh. items: @@ -2835,7 +2835,7 @@ spec: type: array preKubeadmCommands: description: |- - PreKubeadmCommands specifies extra commands to run before kubeadm runs. + preKubeadmCommands specifies extra commands to run before kubeadm runs. With cloud-init, this is prepended to the runcmd module configuration, and is typically executed in the cloud-final.service systemd unit. In Ignition, this is prepended to /etc/kubeadm.sh. items: diff --git a/internal/apis/bootstrap/kubeadm/v1alpha3/kubeadmconfig_types.go b/internal/apis/bootstrap/kubeadm/v1alpha3/kubeadmconfig_types.go index d3e66d4cf33b..234eb28489a3 100644 --- a/internal/apis/bootstrap/kubeadm/v1alpha3/kubeadmconfig_types.go +++ b/internal/apis/bootstrap/kubeadm/v1alpha3/kubeadmconfig_types.go @@ -59,11 +59,11 @@ type KubeadmConfigSpec struct { // +optional Mounts []MountPoints `json:"mounts,omitempty"` - // PreKubeadmCommands specifies extra commands to run before kubeadm runs + // preKubeadmCommands specifies extra commands to run before kubeadm runs // +optional PreKubeadmCommands []string `json:"preKubeadmCommands,omitempty"` - // PostKubeadmCommands specifies extra commands to run after kubeadm runs + // postKubeadmCommands specifies extra commands to run after kubeadm runs // +optional PostKubeadmCommands []string `json:"postKubeadmCommands,omitempty"` diff --git a/internal/apis/bootstrap/kubeadm/v1alpha4/kubeadmconfig_types.go b/internal/apis/bootstrap/kubeadm/v1alpha4/kubeadmconfig_types.go index 6850aeccfc92..9f823e17a86f 100644 --- a/internal/apis/bootstrap/kubeadm/v1alpha4/kubeadmconfig_types.go +++ b/internal/apis/bootstrap/kubeadm/v1alpha4/kubeadmconfig_types.go @@ -58,7 +58,7 @@ type KubeadmConfigSpec struct { // +optional Mounts []MountPoints `json:"mounts,omitempty"` - // PreKubeadmCommands specifies extra commands to run before kubeadm runs + // preKubeadmCommands specifies extra commands to run before kubeadm runs // +optional PreKubeadmCommands []string `json:"preKubeadmCommands,omitempty"` From 84e06c67764d83a36b0d05f9669a5aa23727dcf6 Mon Sep 17 00:00:00 2001 From: davidumea Date: Mon, 25 Nov 2024 17:35:32 +0100 Subject: [PATCH 13/18] fixup: removed extra linebreak --- internal/apis/bootstrap/kubeadm/v1alpha3/conversion.go | 1 - internal/apis/bootstrap/kubeadm/v1alpha4/conversion.go | 1 - 2 files changed, 2 deletions(-) diff --git a/internal/apis/bootstrap/kubeadm/v1alpha3/conversion.go b/internal/apis/bootstrap/kubeadm/v1alpha3/conversion.go index 3bc99558d336..569065e9d69a 100644 --- a/internal/apis/bootstrap/kubeadm/v1alpha3/conversion.go +++ b/internal/apis/bootstrap/kubeadm/v1alpha3/conversion.go @@ -56,7 +56,6 @@ func MergeRestoredKubeadmConfigSpec(dst *bootstrapv1.KubeadmConfigSpec, restored } dst.BootCommands = restored.BootCommands - dst.Ignition = restored.Ignition if restored.ClusterConfiguration != nil { diff --git a/internal/apis/bootstrap/kubeadm/v1alpha4/conversion.go b/internal/apis/bootstrap/kubeadm/v1alpha4/conversion.go index fa2caf92bfe4..4447e8143f37 100644 --- a/internal/apis/bootstrap/kubeadm/v1alpha4/conversion.go +++ b/internal/apis/bootstrap/kubeadm/v1alpha4/conversion.go @@ -55,7 +55,6 @@ func MergeRestoredKubeadmConfigSpec(dst *bootstrapv1.KubeadmConfigSpec, restored } dst.BootCommands = restored.BootCommands - dst.Ignition = restored.Ignition if restored.ClusterConfiguration != nil { From bd63a0517c529fdf84a5dcdcbe1c936ccab891b7 Mon Sep 17 00:00:00 2001 From: davidumea Date: Tue, 26 Nov 2024 08:53:46 +0100 Subject: [PATCH 14/18] fixup: remove bootcommands from testing AdditionalFileEncodings --- bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go b/bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go index 73b4efb98b44..66954dc259fc 100644 --- a/bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go +++ b/bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go @@ -199,9 +199,7 @@ func TestNewJoinControlPlaneAdditionalFileEncodings(t *testing.T) { cpinput := &ControlPlaneJoinInput{ BaseUserData: BaseUserData{ - BootCommands: []bootstrapv1.BootCommand{ - {"echo", "hello"}, - }, + BootCommands: nil, Header: "test", PreKubeadmCommands: nil, PostKubeadmCommands: nil, From a4f3bdbc53b27837ca95cd7ca67419b2e0afe85d Mon Sep 17 00:00:00 2001 From: davidumea Date: Tue, 26 Nov 2024 11:49:21 +0100 Subject: [PATCH 15/18] fixup: make sure bootcommands show up in generated output --- .../kubeadm/internal/cloudinit/cloudinit_test.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go b/bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go index 66954dc259fc..8611115dc0a8 100644 --- a/bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go +++ b/bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go @@ -96,7 +96,7 @@ func TestNewInitControlPlaneCommands(t *testing.T) { cpinput := &ControlPlaneInput{ BaseUserData: BaseUserData{ BootCommands: []bootstrapv1.BootCommand{ - {"echo", "hello"}, + {"echo", "$(date) hello world!"}, }, Header: "test", PreKubeadmCommands: []string{`"echo $(date) ': hello world!'"`}, @@ -121,6 +121,15 @@ func TestNewInitControlPlaneCommands(t *testing.T) { out, err := NewInitControlPlane(cpinput) g.Expect(err).ToNot(HaveOccurred()) + expectedBootCommands := []string{ + `echo`, + `$(date) hello world!`, + } + g.Expect(out).To(ContainSubstring(`bootcmd:`)) + for _, f := range expectedBootCommands { + g.Expect(out).To(ContainSubstring(f)) + } + expectedCommands := []string{ `"\"echo $(date) ': hello world!'\""`, `"echo $(date) ': hello world!'"`, From 4673fb00ebea48e1538f75b5d2d18865c83eccaf Mon Sep 17 00:00:00 2001 From: davidumea Date: Tue, 26 Nov 2024 12:00:42 +0100 Subject: [PATCH 16/18] fixup: add test for join cp commands --- .../internal/cloudinit/cloudinit_test.go | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go b/bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go index 8611115dc0a8..771378cb660c 100644 --- a/bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go +++ b/bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go @@ -331,3 +331,51 @@ func Test_useKubeadmBootstrapScriptPre1_31(t *testing.T) { }) } } + +func TestNewJoinControlPlaneCommands(t *testing.T) { + g := NewWithT(t) + + cpinput := &ControlPlaneJoinInput{ + BaseUserData: BaseUserData{ + BootCommands: []bootstrapv1.BootCommand{ + {"echo", "$(date) hello world!"}, + }, + Header: "test", + PreKubeadmCommands: []string{`"echo $(date) ': hello world!'"`}, + PostKubeadmCommands: []string{"echo $(date) ': hello world!'"}, + AdditionalFiles: nil, + WriteFiles: nil, + Users: nil, + NTP: nil, + }, + Certificates: secret.Certificates{}, + JoinConfiguration: "my-join-config", + } + + for _, certificate := range cpinput.Certificates { + certificate.KeyPair = &certs.KeyPair{ + Cert: []byte("some certificate"), + Key: []byte("some key"), + } + } + + out, err := NewJoinControlPlane(cpinput) + g.Expect(err).ToNot(HaveOccurred()) + + expectedBootCommands := []string{ + `echo`, + `$(date) hello world!`, + } + g.Expect(out).To(ContainSubstring(`bootcmd:`)) + for _, f := range expectedBootCommands { + g.Expect(out).To(ContainSubstring(f)) + } + + expectedCommands := []string{ + `"\"echo $(date) ': hello world!'\""`, + `"echo $(date) ': hello world!'"`, + } + for _, f := range expectedCommands { + g.Expect(out).To(ContainSubstring(f)) + } +} From c059138ee09e711bfcd7ec4fe2898ee66af8ceb5 Mon Sep 17 00:00:00 2001 From: davidumea Date: Tue, 26 Nov 2024 12:17:39 +0100 Subject: [PATCH 17/18] fixup: add test for join node commands --- .../internal/cloudinit/cloudinit_test.go | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go b/bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go index 771378cb660c..6b727b050835 100644 --- a/bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go +++ b/bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go @@ -379,3 +379,43 @@ func TestNewJoinControlPlaneCommands(t *testing.T) { g.Expect(out).To(ContainSubstring(f)) } } + +func TestNewJoinNodeCommands(t *testing.T) { + g := NewWithT(t) + + nodeinput := &NodeInput{ + BaseUserData: BaseUserData{ + BootCommands: []bootstrapv1.BootCommand{ + {"echo", "$(date) hello world!"}, + }, + Header: "test", + PreKubeadmCommands: []string{`"echo $(date) ': hello world!'"`}, + PostKubeadmCommands: []string{"echo $(date) ': hello world!'"}, + AdditionalFiles: nil, + WriteFiles: nil, + Users: nil, + NTP: nil, + }, + JoinConfiguration: "my-join-config", + } + + out, err := NewNode(nodeinput) + g.Expect(err).ToNot(HaveOccurred()) + + expectedBootCommands := []string{ + `echo`, + `$(date) hello world!`, + } + g.Expect(out).To(ContainSubstring(`bootcmd:`)) + for _, f := range expectedBootCommands { + g.Expect(out).To(ContainSubstring(f)) + } + + expectedCommands := []string{ + `"\"echo $(date) ': hello world!'\""`, + `"echo $(date) ': hello world!'"`, + } + for _, f := range expectedCommands { + g.Expect(out).To(ContainSubstring(f)) + } +} From 6fb468d53a18804bc2b585138a12a68f008efa7e Mon Sep 17 00:00:00 2001 From: davidumea Date: Tue, 3 Dec 2024 11:45:01 +0100 Subject: [PATCH 18/18] fixup: ensure commands show up in the right section --- .../internal/cloudinit/cloudinit_test.go | 96 ++++++++----------- 1 file changed, 42 insertions(+), 54 deletions(-) diff --git a/bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go b/bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go index 6b727b050835..78e6b55a4010 100644 --- a/bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go +++ b/bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go @@ -96,11 +96,11 @@ func TestNewInitControlPlaneCommands(t *testing.T) { cpinput := &ControlPlaneInput{ BaseUserData: BaseUserData{ BootCommands: []bootstrapv1.BootCommand{ - {"echo", "$(date) hello world!"}, + {"echo", "$(date) hello BootCommands!"}, }, Header: "test", - PreKubeadmCommands: []string{`"echo $(date) ': hello world!'"`}, - PostKubeadmCommands: []string{"echo $(date) ': hello world!'"}, + PreKubeadmCommands: []string{`"echo $(date) ': hello PreKubeadmCommands!'"`}, + PostKubeadmCommands: []string{"echo $(date) ': hello PostKubeadmCommands!'"}, AdditionalFiles: nil, WriteFiles: nil, Users: nil, @@ -121,22 +121,18 @@ func TestNewInitControlPlaneCommands(t *testing.T) { out, err := NewInitControlPlane(cpinput) g.Expect(err).ToNot(HaveOccurred()) - expectedBootCommands := []string{ - `echo`, - `$(date) hello world!`, - } - g.Expect(out).To(ContainSubstring(`bootcmd:`)) - for _, f := range expectedBootCommands { - g.Expect(out).To(ContainSubstring(f)) - } + expectedBootCmd := `bootcmd: + - - echo + - $(date) hello BootCommands!` - expectedCommands := []string{ - `"\"echo $(date) ': hello world!'\""`, - `"echo $(date) ': hello world!'"`, - } - for _, f := range expectedCommands { - g.Expect(out).To(ContainSubstring(f)) - } + g.Expect(out).To(ContainSubstring(expectedBootCmd)) + + expectedRunCmd := `runcmd: + - "\"echo $(date) ': hello PreKubeadmCommands!'\"" + - 'kubeadm init --config /run/kubeadm/kubeadm.yaml && echo success > /run/cluster-api/bootstrap-success.complete' + - "echo $(date) ': hello PostKubeadmCommands!'"` + + g.Expect(out).To(ContainSubstring(expectedRunCmd)) } func TestNewInitControlPlaneDiskMounts(t *testing.T) { @@ -338,11 +334,11 @@ func TestNewJoinControlPlaneCommands(t *testing.T) { cpinput := &ControlPlaneJoinInput{ BaseUserData: BaseUserData{ BootCommands: []bootstrapv1.BootCommand{ - {"echo", "$(date) hello world!"}, + {"echo", "$(date) hello BootCommands!"}, }, Header: "test", - PreKubeadmCommands: []string{`"echo $(date) ': hello world!'"`}, - PostKubeadmCommands: []string{"echo $(date) ': hello world!'"}, + PreKubeadmCommands: []string{`"echo $(date) ': hello PreKubeadmCommands!'"`}, + PostKubeadmCommands: []string{"echo $(date) ': hello PostKubeadmCommands!'"}, AdditionalFiles: nil, WriteFiles: nil, Users: nil, @@ -362,22 +358,18 @@ func TestNewJoinControlPlaneCommands(t *testing.T) { out, err := NewJoinControlPlane(cpinput) g.Expect(err).ToNot(HaveOccurred()) - expectedBootCommands := []string{ - `echo`, - `$(date) hello world!`, - } - g.Expect(out).To(ContainSubstring(`bootcmd:`)) - for _, f := range expectedBootCommands { - g.Expect(out).To(ContainSubstring(f)) - } + expectedBootCmd := `bootcmd: + - - echo + - $(date) hello BootCommands!` - expectedCommands := []string{ - `"\"echo $(date) ': hello world!'\""`, - `"echo $(date) ': hello world!'"`, - } - for _, f := range expectedCommands { - g.Expect(out).To(ContainSubstring(f)) - } + g.Expect(out).To(ContainSubstring(expectedBootCmd)) + + expectedRunCmd := `runcmd: + - "\"echo $(date) ': hello PreKubeadmCommands!'\"" + - kubeadm join --config /run/kubeadm/kubeadm-join-config.yaml && echo success > /run/cluster-api/bootstrap-success.complete + - "echo $(date) ': hello PostKubeadmCommands!'"` + + g.Expect(out).To(ContainSubstring(expectedRunCmd)) } func TestNewJoinNodeCommands(t *testing.T) { @@ -386,11 +378,11 @@ func TestNewJoinNodeCommands(t *testing.T) { nodeinput := &NodeInput{ BaseUserData: BaseUserData{ BootCommands: []bootstrapv1.BootCommand{ - {"echo", "$(date) hello world!"}, + {"echo", "$(date) hello BootCommands!"}, }, Header: "test", - PreKubeadmCommands: []string{`"echo $(date) ': hello world!'"`}, - PostKubeadmCommands: []string{"echo $(date) ': hello world!'"}, + PreKubeadmCommands: []string{`"echo $(date) ': hello PreKubeadmCommands!'"`}, + PostKubeadmCommands: []string{"echo $(date) ': hello PostKubeadmCommands!'"}, AdditionalFiles: nil, WriteFiles: nil, Users: nil, @@ -402,20 +394,16 @@ func TestNewJoinNodeCommands(t *testing.T) { out, err := NewNode(nodeinput) g.Expect(err).ToNot(HaveOccurred()) - expectedBootCommands := []string{ - `echo`, - `$(date) hello world!`, - } - g.Expect(out).To(ContainSubstring(`bootcmd:`)) - for _, f := range expectedBootCommands { - g.Expect(out).To(ContainSubstring(f)) - } + expectedBootCmd := `bootcmd: + - - echo + - $(date) hello BootCommands!` - expectedCommands := []string{ - `"\"echo $(date) ': hello world!'\""`, - `"echo $(date) ': hello world!'"`, - } - for _, f := range expectedCommands { - g.Expect(out).To(ContainSubstring(f)) - } + g.Expect(out).To(ContainSubstring(expectedBootCmd)) + + expectedRunCmd := `runcmd: + - "\"echo $(date) ': hello PreKubeadmCommands!'\"" + - kubeadm join --config /run/kubeadm/kubeadm-join-config.yaml && echo success > /run/cluster-api/bootstrap-success.complete + - "echo $(date) ': hello PostKubeadmCommands!'"` + + g.Expect(out).To(ContainSubstring(expectedRunCmd)) }