diff --git a/controllers/cloudinit/cloudinit_common_test.go b/controllers/cloudinit/cloudinit_common_test.go index 3e36b3d..25c9418 100644 --- a/controllers/cloudinit/cloudinit_common_test.go +++ b/controllers/cloudinit/cloudinit_common_test.go @@ -78,9 +78,9 @@ func TestCloudConfigInput(t *testing.T) { g.Expect(err).NotTo(HaveOccurred()) if confinement == "classic" { - g.Expect(c.RunCommands).To(ContainElement(fmt.Sprintf(`/capi-scripts/00-install-microk8s.sh "--channel 1.25/%s --classic" ""`, risk))) + g.Expect(c.RunCommands).To(ContainElement(fmt.Sprintf(`/capi-scripts/00-install-microk8s.sh "--channel 1.25/%s --classic" false`, risk))) } else { - g.Expect(c.RunCommands).To(ContainElement(fmt.Sprintf(`/capi-scripts/00-install-microk8s.sh "--channel 1.25-strict/%s" ""`, risk))) + g.Expect(c.RunCommands).To(ContainElement(fmt.Sprintf(`/capi-scripts/00-install-microk8s.sh "--channel 1.25-strict/%s" false`, risk))) } _, err = cloudinit.GenerateCloudConfig(c) @@ -128,7 +128,7 @@ func TestCloudConfigInput(t *testing.T) { c, err := tc.makeCloudConfig() g.Expect(err).NotTo(HaveOccurred()) - g.Expect(c.RunCommands).To(ContainElement(`/capi-scripts/00-install-microk8s.sh "--channel 1.25 --classic" "--disable-default-cni"`)) + g.Expect(c.RunCommands).To(ContainElement(`/capi-scripts/00-install-microk8s.sh "--channel 1.25 --classic" true`)) _, err = cloudinit.GenerateCloudConfig(c) g.Expect(err).NotTo(HaveOccurred()) }) diff --git a/controllers/cloudinit/controlplane_init.go b/controllers/cloudinit/controlplane_init.go index ae1d7a6..461a6a2 100644 --- a/controllers/cloudinit/controlplane_init.go +++ b/controllers/cloudinit/controlplane_init.go @@ -120,9 +120,6 @@ func NewInitControlPlane(input *ControlPlaneInitInput) (*CloudConfig, error) { } installArgs := createInstallArgs(input.Confinement, input.RiskLevel, kubernetesVersion) - // extra arguments passed to 00-install-microk8s.sh - extraArgs := createExtraArgs(input.DisableDefaultCNI) - cloudConfig := NewBaseCloudConfig() cloudConfig.WriteFiles = append( cloudConfig.WriteFiles, @@ -146,7 +143,7 @@ func NewInitControlPlane(input *ControlPlaneInitInput) (*CloudConfig, error) { fmt.Sprintf("%s %q %q", scriptPath(snapstoreHTTPProxyScript), input.SnapstoreHTTPProxy, input.SnapstoreHTTPSProxy), fmt.Sprintf("%s %q %q", scriptPath(snapstoreProxyScript), input.SnapstoreProxyDomain, input.SnapstoreProxyId), scriptPath(disableHostServicesScript), - fmt.Sprintf("%s %q %q", scriptPath(installMicroK8sScript), installArgs, extraArgs), + fmt.Sprintf("%s %q %v", scriptPath(installMicroK8sScript), installArgs, input.DisableDefaultCNI), fmt.Sprintf("%s %q %q %q", scriptPath(configureContainerdProxyScript), input.ContainerdHTTPProxy, input.ContainerdHTTPSProxy, input.ContainerdNoProxy), scriptPath(configureKubeletScript), scriptPath(waitAPIServerScript), diff --git a/controllers/cloudinit/controlplane_init_test.go b/controllers/cloudinit/controlplane_init_test.go index ec0e809..67535f9 100644 --- a/controllers/cloudinit/controlplane_init_test.go +++ b/controllers/cloudinit/controlplane_init_test.go @@ -48,7 +48,7 @@ func TestControlPlaneInit(t *testing.T) { `/capi-scripts/00-configure-snapstore-http-proxy.sh "" ""`, `/capi-scripts/00-configure-snapstore-proxy.sh "" ""`, `/capi-scripts/00-disable-host-services.sh`, - `/capi-scripts/00-install-microk8s.sh "--channel 1.25 --classic" "--disable-default-cni"`, + `/capi-scripts/00-install-microk8s.sh "--channel 1.25 --classic" true`, `/capi-scripts/10-configure-containerd-proxy.sh "" "" ""`, `/capi-scripts/10-configure-kubelet.sh`, `/capi-scripts/50-wait-apiserver.sh`, diff --git a/controllers/cloudinit/controlplane_join.go b/controllers/cloudinit/controlplane_join.go index 9feb066..3dcd0c6 100644 --- a/controllers/cloudinit/controlplane_join.go +++ b/controllers/cloudinit/controlplane_join.go @@ -102,9 +102,6 @@ func NewJoinControlPlane(input *ControlPlaneJoinInput) (*CloudConfig, error) { } installArgs := createInstallArgs(input.Confinement, input.RiskLevel, kubernetesVersion) - // extra arguments passed to 00-install-microk8s.sh - extraArgs := createExtraArgs(input.DisableDefaultCNI) - cloudConfig := NewBaseCloudConfig() cloudConfig.WriteFiles = append(cloudConfig.WriteFiles, input.ExtraWriteFiles...) if args := input.ExtraKubeletArgs; len(args) > 0 { @@ -128,7 +125,7 @@ func NewJoinControlPlane(input *ControlPlaneJoinInput) (*CloudConfig, error) { fmt.Sprintf("%s %q %q", scriptPath(snapstoreHTTPProxyScript), input.SnapstoreHTTPProxy, input.SnapstoreHTTPSProxy), fmt.Sprintf("%s %q %q", scriptPath(snapstoreProxyScript), input.SnapstoreProxyDomain, input.SnapstoreProxyId), scriptPath(disableHostServicesScript), - fmt.Sprintf("%s %q %q", scriptPath(installMicroK8sScript), installArgs, extraArgs), + fmt.Sprintf("%s %q %v", scriptPath(installMicroK8sScript), installArgs, input.DisableDefaultCNI), fmt.Sprintf("%s %q %q %q", scriptPath(configureContainerdProxyScript), input.ContainerdHTTPProxy, input.ContainerdHTTPSProxy, input.ContainerdNoProxy), scriptPath(configureKubeletScript), scriptPath(waitAPIServerScript), diff --git a/controllers/cloudinit/controlplane_join_test.go b/controllers/cloudinit/controlplane_join_test.go index 4afe9aa..21ad7d5 100644 --- a/controllers/cloudinit/controlplane_join_test.go +++ b/controllers/cloudinit/controlplane_join_test.go @@ -46,7 +46,7 @@ func TestControlPlaneJoin(t *testing.T) { `/capi-scripts/00-configure-snapstore-http-proxy.sh "" ""`, `/capi-scripts/00-configure-snapstore-proxy.sh "" ""`, `/capi-scripts/00-disable-host-services.sh`, - `/capi-scripts/00-install-microk8s.sh "--channel 1.25 --classic" "--disable-default-cni"`, + `/capi-scripts/00-install-microk8s.sh "--channel 1.25 --classic" true`, `/capi-scripts/10-configure-containerd-proxy.sh "" "" ""`, `/capi-scripts/10-configure-kubelet.sh`, `/capi-scripts/50-wait-apiserver.sh`, diff --git a/controllers/cloudinit/scripts/00-install-microk8s.sh b/controllers/cloudinit/scripts/00-install-microk8s.sh old mode 100644 new mode 100755 index 82fb99d..1061fff --- a/controllers/cloudinit/scripts/00-install-microk8s.sh +++ b/controllers/cloudinit/scripts/00-install-microk8s.sh @@ -1,19 +1,15 @@ #!/bin/bash -xe # Usage: -# $0 $microk8s_snap_args [--disable-default-cni] +# $0 $microk8s_snap_args $disable_default_cni +# +# Arguments: +# $microk8s_snap_args Arguments to pass to snap install +# $disable_default_cni Boolean flag to disable the default CNI # # Assumptions: # - snapd is installed -DISABLE_DEFAULT_CNI=false - -for arg in "$@"; do - if [ "$arg" == "--disable-default-cni" ]; then - DISABLE_DEFAULT_CNI=true - fi -done - if snap list microk8s; then echo "MicroK8s is already installed, will not install" exit 0 @@ -24,6 +20,6 @@ while ! snap install microk8s ${1}; do sleep 5 done -if [ "$DISABLE_DEFAULT_CNI" == "true" ]; then +if [ "${2}" == "true" ]; then mv /var/snap/microk8s/current/args/cni-network/cni.yaml /var/snap/microk8s/current/args/cni-network/cni.yaml.old -fi \ No newline at end of file +fi diff --git a/controllers/cloudinit/utils.go b/controllers/cloudinit/utils.go index 5ea1869..3a79f7e 100644 --- a/controllers/cloudinit/utils.go +++ b/controllers/cloudinit/utils.go @@ -43,15 +43,6 @@ func createInstallArgs(confinement string, riskLevel string, kubernetesVersion * return installArgs } -func createExtraArgs(disableDefaultCNI bool) string { - var extraArgs string - if disableDefaultCNI { - extraArgs = "--disable-default-cni" - } - - return extraArgs -} - func WriteFilesFromAPI(files []bootstrapclusterxk8siov1beta1.CloudInitWriteFile) []File { if len(files) == 0 { return nil diff --git a/controllers/cloudinit/worker_join.go b/controllers/cloudinit/worker_join.go index ead270a..515abb3 100644 --- a/controllers/cloudinit/worker_join.go +++ b/controllers/cloudinit/worker_join.go @@ -112,7 +112,7 @@ func NewJoinWorker(input *WorkerInput) (*CloudConfig, error) { fmt.Sprintf("%s %q %q", scriptPath(snapstoreHTTPProxyScript), input.SnapstoreHTTPProxy, input.SnapstoreHTTPSProxy), fmt.Sprintf("%s %q %q", scriptPath(snapstoreProxyScript), input.SnapstoreProxyDomain, input.SnapstoreProxyId), scriptPath(disableHostServicesScript), - fmt.Sprintf("%s %q %q", scriptPath(installMicroK8sScript), installArgs, ""), // no extra args + fmt.Sprintf("%s %q %v", scriptPath(installMicroK8sScript), installArgs, false), fmt.Sprintf("%s %q %q %q", scriptPath(configureContainerdProxyScript), input.ContainerdHTTPProxy, input.ContainerdHTTPSProxy, input.ContainerdNoProxy), scriptPath(configureKubeletScript), scriptPath(waitAPIServerScript), diff --git a/controllers/cloudinit/worker_join_test.go b/controllers/cloudinit/worker_join_test.go index 30947e4..43a2450 100644 --- a/controllers/cloudinit/worker_join_test.go +++ b/controllers/cloudinit/worker_join_test.go @@ -42,7 +42,7 @@ func TestWorkerJoin(t *testing.T) { `/capi-scripts/00-configure-snapstore-http-proxy.sh "" ""`, `/capi-scripts/00-configure-snapstore-proxy.sh "" ""`, `/capi-scripts/00-disable-host-services.sh`, - `/capi-scripts/00-install-microk8s.sh "--channel 1.24 --classic" ""`, + `/capi-scripts/00-install-microk8s.sh "--channel 1.24 --classic" false`, `/capi-scripts/10-configure-containerd-proxy.sh "" "" ""`, `/capi-scripts/10-configure-kubelet.sh`, `/capi-scripts/50-wait-apiserver.sh`,