From 395a503c169feaf10b5dc1adb1c0a76bdeae2866 Mon Sep 17 00:00:00 2001 From: Dimitri Koshkin Date: Tue, 11 Jun 2024 13:50:03 -0700 Subject: [PATCH] refactor: use a single preKubeadmCommand --- .../mutation/controlplanevirtualip/inject_test.go | 6 ++---- .../controlplanevirtualip/providers/kubevip.go | 9 ++------- .../controlplanevirtualip/providers/kubevip_test.go | 2 +- .../providers/templates/configure-for-kube-vip.sh | 11 ++--------- 4 files changed, 7 insertions(+), 21 deletions(-) diff --git a/pkg/handlers/generic/mutation/controlplanevirtualip/inject_test.go b/pkg/handlers/generic/mutation/controlplanevirtualip/inject_test.go index 56763e650..ff242a1be 100644 --- a/pkg/handlers/generic/mutation/controlplanevirtualip/inject_test.go +++ b/pkg/handlers/generic/mutation/controlplanevirtualip/inject_test.go @@ -82,8 +82,7 @@ var _ = Describe("Generate ControlPlane virtual IP patches", func() { Operation: "add", Path: "/spec/template/spec/kubeadmConfigSpec/preKubeadmCommands", ValueMatcher: gomega.ContainElements( - "/bin/bash /etc/caren/configure-for-kube-vip.sh set-host-aliases", - "/bin/bash /etc/caren/configure-for-kube-vip.sh use-super-admin.conf", + "/bin/bash /etc/caren/configure-for-kube-vip.sh set-host-aliases use-super-admin.conf", ), }, { @@ -162,8 +161,7 @@ var _ = Describe("Generate ControlPlane virtual IP patches", func() { Operation: "add", Path: "/spec/template/spec/kubeadmConfigSpec/preKubeadmCommands", ValueMatcher: gomega.ContainElements( - "/bin/bash /etc/caren/configure-for-kube-vip.sh set-host-aliases", - "/bin/bash /etc/caren/configure-for-kube-vip.sh use-super-admin.conf", + "/bin/bash /etc/caren/configure-for-kube-vip.sh set-host-aliases use-super-admin.conf", ), }, { diff --git a/pkg/handlers/generic/mutation/controlplanevirtualip/providers/kubevip.go b/pkg/handlers/generic/mutation/controlplanevirtualip/providers/kubevip.go index 90098a1df..dab6bebf8 100644 --- a/pkg/handlers/generic/mutation/controlplanevirtualip/providers/kubevip.go +++ b/pkg/handlers/generic/mutation/controlplanevirtualip/providers/kubevip.go @@ -31,11 +31,9 @@ var ( "configure-for-kube-vip.sh") configureForKubeVIPScriptOnRemotePreKubeadmCommand = "/bin/bash " + - configureForKubeVIPScriptOnRemote + " use-super-admin.conf" + configureForKubeVIPScriptOnRemote + " set-host-aliases use-super-admin.conf" configureForKubeVIPScriptOnRemotePostKubeadmCommand = "/bin/bash " + configureForKubeVIPScriptOnRemote + " use-admin.conf" - - setHostAliasesScriptOnRemoteCommand = "/bin/bash " + configureForKubeVIPScriptOnRemote + " set-host-aliases" ) //go:embed templates/configure-for-kube-vip.sh @@ -132,10 +130,7 @@ func (p *kubeVIPFromConfigMapProvider) GenerateFilesAndCommands( }, ) - preKubeadmCommands = []string{ - setHostAliasesScriptOnRemoteCommand, - configureForKubeVIPScriptOnRemotePreKubeadmCommand, - } + preKubeadmCommands = []string{configureForKubeVIPScriptOnRemotePreKubeadmCommand} postKubeadmCommands = []string{configureForKubeVIPScriptOnRemotePostKubeadmCommand} return files, preKubeadmCommands, postKubeadmCommands, nil diff --git a/pkg/handlers/generic/mutation/controlplanevirtualip/providers/kubevip_test.go b/pkg/handlers/generic/mutation/controlplanevirtualip/providers/kubevip_test.go index 4297b2cef..312d06afa 100644 --- a/pkg/handlers/generic/mutation/controlplanevirtualip/providers/kubevip_test.go +++ b/pkg/handlers/generic/mutation/controlplanevirtualip/providers/kubevip_test.go @@ -68,7 +68,7 @@ func Test_GenerateFilesAndCommands(t *testing.T) { }, }, expectedPreKubeadmCommands: []string{ - setHostAliasesScriptOnRemoteCommand, configureForKubeVIPScriptOnRemotePreKubeadmCommand, + configureForKubeVIPScriptOnRemotePreKubeadmCommand, }, expectedPostKubeadmCommands: []string{ configureForKubeVIPScriptOnRemotePostKubeadmCommand, diff --git a/pkg/handlers/generic/mutation/controlplanevirtualip/providers/templates/configure-for-kube-vip.sh b/pkg/handlers/generic/mutation/controlplanevirtualip/providers/templates/configure-for-kube-vip.sh index 985dff842..cc9a1b1ee 100644 --- a/pkg/handlers/generic/mutation/controlplanevirtualip/providers/templates/configure-for-kube-vip.sh +++ b/pkg/handlers/generic/mutation/controlplanevirtualip/providers/templates/configure-for-kube-vip.sh @@ -28,27 +28,21 @@ function set_host_aliases() { function print_usage { cat >&2 <