diff --git a/test/helpers/kubectl.go b/test/helpers/kubectl.go index cbd73171dcac..a439c4975ae8 100644 --- a/test/helpers/kubectl.go +++ b/test/helpers/kubectl.go @@ -1561,22 +1561,36 @@ func (kub *Kubectl) CiliumInstall(filename string, options map[string]string) er return nil } +// ApplyHelm runs the helm command with the given options. +func (kub *Kubectl) ApplyHelm(repo, helmName, version, namespace string, options map[string]string) (*CmdRes, error) { + dir, _ := filepath.Split(repo) + kub.RunHelm("fetch", repo, "", version, "", map[string]string{}, fmt.Sprintf("--untar --untardir=%s", dir)) + return kub.RunHelm("template", repo, helmName, "", namespace, options, fmt.Sprintf("| kubectl --namespace=%s apply -f -", namespace)) +} + // RunHelm runs the helm command with the given options. -func (kub *Kubectl) RunHelm(action, repo, helmName, version, namespace string, options map[string]string) (*CmdRes, error) { +func (kub *Kubectl) RunHelm(action, repo, helmName, version, namespace string, options map[string]string, pipe string) (*CmdRes, error) { err := kub.overwriteHelmOptions(options) if err != nil { return nil, err } optionsString := "" + if helmName != "" { + optionsString += fmt.Sprintf(" --name=%s ", helmName) + } + if version != "" { + optionsString += fmt.Sprintf(" --version=%s ", version) + } + if namespace != "" { + optionsString += fmt.Sprintf(" --namespace=%s ", namespace) + } for k, v := range options { optionsString += fmt.Sprintf(" --set %s=%s ", k, v) } - - return kub.ExecMiddle(fmt.Sprintf("helm %s %s %s "+ - "--version=%s "+ - "--namespace=%s "+ - "%s", action, helmName, repo, version, namespace, optionsString)), nil + cmdStr := fmt.Sprintf("helm %s %s %s %s", action, repo, optionsString, pipe) + kub.Executor.Logger().Warningf("Executing command: %s", cmdStr) + return kub.ExecMiddle(fmt.Sprintf("helm %s %s %s %s", action, repo, optionsString, pipe)), nil } // CiliumUninstall uninstalls Cilium with the provided Helm options. diff --git a/test/k8sT/Updates.go b/test/k8sT/Updates.go index 04b462d78bfb..459c4d2acdb4 100644 --- a/test/k8sT/Updates.go +++ b/test/k8sT/Updates.go @@ -140,7 +140,6 @@ func InstallAndValidateCiliumUpgrades(kubectl *helpers.Kubectl, oldHelmChartVers app1Service := "app1-service" cleanupCiliumState := func(helmPath, chartVersion, imageName, imageTag, registry string) { - _ = kubectl.ExecMiddle("helm delete cilium --namespace=" + helpers.CiliumNamespace) _ = kubectl.ExecMiddle(fmt.Sprintf("kubectl delete configmap --namespace=%s cilium-config", helpers.CiliumNamespace)) _ = kubectl.ExecMiddle(fmt.Sprintf("kubectl delete serviceaccount --namespace=%s cilium cilium-operator", helpers.CiliumNamespace)) _ = kubectl.ExecMiddle("kubectl delete clusterrole cilium cilium-operator cilium-psp cilium-operator-psp") @@ -161,8 +160,7 @@ func InstallAndValidateCiliumUpgrades(kubectl *helpers.Kubectl, oldHelmChartVers if imageName != "" { opts["agent.image"] = imageName } - cmd, err := kubectl.RunHelm( - "install", + cmd, err := kubectl.ApplyHelm( helmPath, "cilium", chartVersion, @@ -175,7 +173,7 @@ func InstallAndValidateCiliumUpgrades(kubectl *helpers.Kubectl, oldHelmChartVers ExpectWithOffset(1, err).To(BeNil(), "Cilium %q was not able to be deployed", chartVersion) err = kubectl.WaitForCiliumInitContainerToFinish() ExpectWithOffset(1, err).To(BeNil(), "Cilium %q was not able to be clean up environment", chartVersion) - cmd = kubectl.ExecMiddle("helm delete cilium --namespace=" + helpers.CiliumNamespace) + cmd = kubectl.ExecMiddle(fmt.Sprintf("kubectl delete daemonset --namespace=%s cilium", helpers.CiliumNamespace)) ExpectWithOffset(1, cmd).To(helpers.CMDSuccess(), "Cilium %q was not able to be deleted", chartVersion) ExpectAllPodsTerminated(kubectl) } @@ -225,8 +223,7 @@ func InstallAndValidateCiliumUpgrades(kubectl *helpers.Kubectl, oldHelmChartVers cleanupCiliumState("cilium/cilium", oldHelmChartVersion, "cilium", oldImageVersion, "docker.io/cilium") By("Deploying Cilium %s", oldHelmChartVersion) - cmd, err = kubectl.RunHelm( - "install", + cmd, err = kubectl.ApplyHelm( "cilium/cilium", "cilium", oldHelmChartVersion, @@ -373,8 +370,7 @@ func InstallAndValidateCiliumUpgrades(kubectl *helpers.Kubectl, oldHelmChartVers } By("Install Cilium pre-flight check DaemonSet") - cmd, err = kubectl.RunHelm( - "install", + cmd, err = kubectl.ApplyHelm( filepath.Join(kubectl.BasePath(), helpers.HelmTemplate), "cilium-preflight", newHelmChartVersion, @@ -384,6 +380,7 @@ func InstallAndValidateCiliumUpgrades(kubectl *helpers.Kubectl, oldHelmChartVers "agent.enabled": "false ", "config.enabled": "false ", "operator.enabled": "false ", + "preflight.image": "cilium-dev", "global.tag": newImageVersion, }, ) @@ -393,7 +390,7 @@ func InstallAndValidateCiliumUpgrades(kubectl *helpers.Kubectl, oldHelmChartVers // Once they are installed we can remove it By("Removing Cilium pre-flight check DaemonSet") - cmd = kubectl.ExecMiddle("helm delete cilium-preflight --namespace=" + helpers.CiliumNamespace) + cmd = kubectl.ExecMiddle(fmt.Sprintf("kubectl delete daemonset --namespace=%s cilium-pre-flight-check", helpers.CiliumNamespace)) ExpectWithOffset(1, cmd).To(helpers.CMDSuccess(), "Unable to delete preflight") err = kubectl.WaitforPods(helpers.CiliumNamespace, "-l k8s-app=cilium", timeout) @@ -410,8 +407,7 @@ func InstallAndValidateCiliumUpgrades(kubectl *helpers.Kubectl, oldHelmChartVers if oldHelmChartVersion == "1.6-dev" { opts["agent.keepDeprecatedLabels"] = "true" } - cmd, err = kubectl.RunHelm( - "upgrade", + cmd, err = kubectl.ApplyHelm( filepath.Join(kubectl.BasePath(), helpers.HelmTemplate), "cilium", newHelmChartVersion, @@ -439,9 +435,18 @@ func InstallAndValidateCiliumUpgrades(kubectl *helpers.Kubectl, oldHelmChartVers checkNoInteruptsInSVCFlows() By("Downgrading cilium to %s image", oldHelmChartVersion) - // rollback cilium 1 because it's the version that we have started - // cilium with in this updates test. - cmd = kubectl.ExecMiddle("helm rollback cilium 1 --namespace=" + helpers.CiliumNamespace) + cmd, err = kubectl.ApplyHelm( + "cilium/cilium", + "cilium", + oldHelmChartVersion, + helpers.CiliumNamespace, + map[string]string{ + "global.tag": oldImageVersion, + "global.registry": "docker.io/cilium", + "agent.image": "cilium", + }, + ) + ExpectWithOffset(1, err).To(BeNil(), "Cilium %q was not able to be deployed", oldHelmChartVersion) ExpectWithOffset(1, cmd).To(helpers.CMDSuccess(), "Cilium %q was not able to be deployed", oldHelmChartVersion) err = helpers.WithTimeout( diff --git a/test/provision/k8s_install.sh b/test/provision/k8s_install.sh index 2ded35fbfe34..038084410fdc 100755 --- a/test/provision/k8s_install.sh +++ b/test/provision/k8s_install.sh @@ -48,6 +48,7 @@ if [[ ! $(helm version | grep ${HELM_VERSION}) ]]; then tar xzvf helm-v${HELM_VERSION}-linux-amd64.tar.gz mv linux-amd64/helm /usr/local/bin/ fi +su - vagrant -c 'helm init --client-only' # Install serial ttyS0 server cat < /etc/systemd/system/serial-getty@ttyS0.service