Skip to content

Commit

Permalink
test: Support helm without tiller
Browse files Browse the repository at this point in the history
Use 'helm template' to avoid needing tiller installed. Run "helm init"
when deploying so that "helm repo" can succeed. These changes allow
the CI to run locally (via 'test/vagrant-local-start.sh').

These changes should also make it easy to move CI to helm version 3.

Signed-off-by: Jarno Rajahalme <jarno@covalent.io>
  • Loading branch information
jrajahalme committed Feb 28, 2020
1 parent 64c4792 commit 0788071
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 20 deletions.
26 changes: 20 additions & 6 deletions test/helpers/kubectl.go
Expand Up @@ -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.
Expand Down
33 changes: 19 additions & 14 deletions test/k8sT/Updates.go
Expand Up @@ -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")
Expand All @@ -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,
Expand All @@ -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)
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
},
)
Expand All @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions test/provision/k8s_install.sh
Expand Up @@ -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 <<EOF > /etc/systemd/system/serial-getty@ttyS0.service
Expand Down

0 comments on commit 0788071

Please sign in to comment.