Skip to content

Commit

Permalink
refactor: use a single preKubeadmCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoshkin committed Jun 11, 2024
1 parent 103b263 commit 395a503
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
},
{
Expand Down Expand Up @@ -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",
),
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -132,10 +130,7 @@ func (p *kubeVIPFromConfigMapProvider) GenerateFilesAndCommands(
},
)

preKubeadmCommands = []string{
setHostAliasesScriptOnRemoteCommand,
configureForKubeVIPScriptOnRemotePreKubeadmCommand,
}
preKubeadmCommands = []string{configureForKubeVIPScriptOnRemotePreKubeadmCommand}
postKubeadmCommands = []string{configureForKubeVIPScriptOnRemotePostKubeadmCommand}

return files, preKubeadmCommands, postKubeadmCommands, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func Test_GenerateFilesAndCommands(t *testing.T) {
},
},
expectedPreKubeadmCommands: []string{
setHostAliasesScriptOnRemoteCommand, configureForKubeVIPScriptOnRemotePreKubeadmCommand,
configureForKubeVIPScriptOnRemotePreKubeadmCommand,
},
expectedPostKubeadmCommands: []string{
configureForKubeVIPScriptOnRemotePostKubeadmCommand,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,21 @@ function set_host_aliases() {

function print_usage {
cat >&2 <<EOF
Usage: ${SCRIPT_NAME} [use-super-admin.conf|use-admin.conf|set-host-aliases]
Usage: ${SCRIPT_NAME} [set-host-aliases|use-super-admin.conf|use-admin.conf]
EOF
}

function run_cmd() {
while [ -n "$1" ]; do
while [ $# -gt 0 ]; do
case $1 in
use-super-admin.conf)
use_super_admin_conf
shift
break
;;
use-admin.conf)
use_admin_conf
shift
break
;;
set-host-aliases)
set_host_aliases
shift
break
;;
-h | --help)
print_usage
Expand All @@ -59,7 +53,6 @@ function run_cmd() {
exit 1
;;
esac
echo "$1"
shift
done
}
Expand Down

0 comments on commit 395a503

Please sign in to comment.