From fa2f0d1a9198eb39edba562b7b99a4b37fcaae86 Mon Sep 17 00:00:00 2001 From: Alistair Hey Date: Thu, 20 Feb 2020 14:50:44 +0000 Subject: [PATCH] Re-add the --wait flag to the helm3 installation This commit re-adds the wait flag to helm3 installation and sets the default --version to empty string, this installs the latest chart version by default. When we need a specific version we can set it (see cert-manager) Signed-off-by: Alistair Hey --- cmd/apps/certmanager_app.go | 5 +++-- cmd/apps/chart_app.go | 6 ++++-- cmd/apps/cronconnector_app.go | 3 +-- cmd/apps/crossplane_app.go | 4 ++-- cmd/apps/inletsoperator_app.go | 4 ++-- cmd/apps/istio_app.go | 2 +- cmd/apps/kafkaconnector_app.go | 3 +-- cmd/apps/kubernetes_exec.go | 22 +++++++++++----------- cmd/apps/metricsserver_app.go | 3 +-- cmd/apps/minio_app.go | 3 +-- cmd/apps/mongodb_app.go | 2 +- cmd/apps/nginx_app.go | 3 +-- cmd/apps/openfaas_app.go | 4 ++-- cmd/apps/postgres_app.go | 3 +-- cmd/apps/registry_app.go | 5 ++--- 15 files changed, 34 insertions(+), 38 deletions(-) diff --git a/cmd/apps/certmanager_app.go b/cmd/apps/certmanager_app.go index 69fe7e6a..71ac7970 100644 --- a/cmd/apps/certmanager_app.go +++ b/cmd/apps/certmanager_app.go @@ -27,6 +27,7 @@ func MakeInstallCertManager() *cobra.Command { certManager.Flags().Bool("helm3", true, "Use helm3, if set to false uses helm2") certManager.RunE = func(command *cobra.Command, args []string) error { + const certManagerVersion = "v0.12.0" kubeConfigPath := getDefaultKubeconfig() if command.Flags().Changed("kubeconfig") { @@ -88,7 +89,7 @@ func MakeInstallCertManager() *cobra.Command { chartPath := path.Join(os.TempDir(), "charts") - err = fetchChart(chartPath, "jetstack/cert-manager", helm3) + err = fetchChart(chartPath, "jetstack/cert-manager", certManagerVersion, helm3) if err != nil { return err } @@ -120,7 +121,7 @@ func MakeInstallCertManager() *cobra.Command { return err } } else { - err = templateChart(chartPath, "cert-manager", namespace, outputPath, "values.yaml", "v0.12.0", nil) + err = templateChart(chartPath, "cert-manager", namespace, outputPath, "values.yaml", nil) if err != nil { return err } diff --git a/cmd/apps/chart_app.go b/cmd/apps/chart_app.go index 7a178354..fa9c100b 100644 --- a/cmd/apps/chart_app.go +++ b/cmd/apps/chart_app.go @@ -14,6 +14,8 @@ import ( "github.com/spf13/cobra" ) +const defaultVersion = "" // If we don't set version then we get latest + func MakeInstallChart() *cobra.Command { var chartCmd = &cobra.Command{ Use: "chart", @@ -109,7 +111,7 @@ before using the generic helm chart installer command.`, chartPath := path.Join(os.TempDir(), "charts") - err = fetchChart(chartPath, chartRepoName, false) + err = fetchChart(chartPath, chartRepoName, defaultVersion, false) if err != nil { return err } @@ -130,7 +132,7 @@ before using the generic helm chart installer command.`, } } - err = templateChart(chartPath, chartName, namespace, outputPath, "values.yaml", "", setMap) + err = templateChart(chartPath, chartName, namespace, outputPath, "values.yaml", setMap) if err != nil { return err } diff --git a/cmd/apps/cronconnector_app.go b/cmd/apps/cronconnector_app.go index 3b9ae73b..596d30a3 100644 --- a/cmd/apps/cronconnector_app.go +++ b/cmd/apps/cronconnector_app.go @@ -75,7 +75,7 @@ func MakeInstallCronConnector() *cobra.Command { } chartPath := path.Join(os.TempDir(), "charts") - err = fetchChart(chartPath, "openfaas/cron-connector", false) + err = fetchChart(chartPath, "openfaas/cron-connector", defaultVersion, false) if err != nil { return err @@ -105,7 +105,6 @@ func MakeInstallCronConnector() *cobra.Command { ns, outputPath, "values.yaml", - "", overrides) if err != nil { diff --git a/cmd/apps/crossplane_app.go b/cmd/apps/crossplane_app.go index 395fcca9..854f0169 100644 --- a/cmd/apps/crossplane_app.go +++ b/cmd/apps/crossplane_app.go @@ -88,7 +88,7 @@ schedule workloads to any Kubernetes cluster`, chartPath := path.Join(os.TempDir(), "charts") - err = fetchChart(chartPath, "crossplane-alpha/crossplane", helm3) + err = fetchChart(chartPath, "crossplane-alpha/crossplane", defaultVersion, helm3) if err != nil { return err } @@ -110,7 +110,7 @@ schedule workloads to any Kubernetes cluster`, } else { outputPath := path.Join(chartPath, "crossplane-alpha/crossplane") - err = templateChart(chartPath, "crossplane", namespace, outputPath, "values.yaml", "", map[string]string{}) + err = templateChart(chartPath, "crossplane", namespace, outputPath, "values.yaml", map[string]string{}) if err != nil { return err } diff --git a/cmd/apps/inletsoperator_app.go b/cmd/apps/inletsoperator_app.go index 8659748f..9da11cd7 100644 --- a/cmd/apps/inletsoperator_app.go +++ b/cmd/apps/inletsoperator_app.go @@ -95,7 +95,7 @@ func MakeInstallInletsOperator() *cobra.Command { chartPath := path.Join(os.TempDir(), "charts") - err = fetchChart(chartPath, "inlets/inlets-operator", helm3) + err = fetchChart(chartPath, "inlets/inlets-operator", defaultVersion, helm3) if err != nil { return err } @@ -156,7 +156,7 @@ func MakeInstallInletsOperator() *cobra.Command { } else { outputPath := path.Join(chartPath, "inlets-operator/rendered") - err = templateChart(chartPath, "inlets-operator", namespace, outputPath, "values.yaml", "", overrides) + err = templateChart(chartPath, "inlets-operator", namespace, outputPath, "values.yaml", overrides) if err != nil { return err } diff --git a/cmd/apps/istio_app.go b/cmd/apps/istio_app.go index ed7fa98f..ee24aeed 100644 --- a/cmd/apps/istio_app.go +++ b/cmd/apps/istio_app.go @@ -97,7 +97,7 @@ func MakeInstallIstio() *cobra.Command { chartPath := path.Join(os.TempDir(), "charts") - err = fetchChart(chartPath, "istio/istio", helm3) + err = fetchChart(chartPath, "istio/istio", defaultVersion, helm3) if err != nil { return fmt.Errorf("unable fetch chart %s", err) diff --git a/cmd/apps/kafkaconnector_app.go b/cmd/apps/kafkaconnector_app.go index c28bf825..282c9564 100644 --- a/cmd/apps/kafkaconnector_app.go +++ b/cmd/apps/kafkaconnector_app.go @@ -76,7 +76,7 @@ func MakeInstallKafkaConnector() *cobra.Command { } chartPath := path.Join(os.TempDir(), "charts") - err = fetchChart(chartPath, "openfaas/kafka-connector", false) + err = fetchChart(chartPath, "openfaas/kafka-connector", defaultVersion, false) if err != nil { return err @@ -122,7 +122,6 @@ func MakeInstallKafkaConnector() *cobra.Command { ns, outputPath, "values.yaml", - "", overrides) if err != nil { diff --git a/cmd/apps/kubernetes_exec.go b/cmd/apps/kubernetes_exec.go index f26c0152..701a2bd3 100644 --- a/cmd/apps/kubernetes_exec.go +++ b/cmd/apps/kubernetes_exec.go @@ -11,8 +11,12 @@ import ( "github.com/alexellis/k3sup/pkg/env" ) -func fetchChart(path, chart string, helm3 bool) error { +func fetchChart(path, chart, version string, helm3 bool) error { + versionStr := "" + if len(version) > 0 { + versionStr = "--version " + version + } subdir := "" if helm3 { subdir = "helm3" @@ -25,7 +29,7 @@ func fetchChart(path, chart string, helm3 bool) error { } task := execute.ExecTask{ - Command: fmt.Sprintf("%s fetch %s --untar --untardir %s", env.LocalBinary("helm", subdir), chart, path), + Command: fmt.Sprintf("%s fetch %s --untar --untardir %s %s", env.LocalBinary("helm", subdir), chart, path, versionStr), Env: os.Environ(), StreamStdio: true, } @@ -60,11 +64,12 @@ func helm3Upgrade(basePath, chart, namespace, values, version string, overrides - args := []string{"upgrade", "--install", chartName, chart, "--namespace", namespace, } + args := []string{"upgrade", "--install", chartName, chart, "--namespace", namespace, "--wait"} if len(version) > 0 { args = append(args, "--version", version) } + fmt.Println("VALUES", values) if len(values) > 0 { args = append(args, "--values") @@ -106,7 +111,7 @@ func helm3Upgrade(basePath, chart, namespace, values, version string, overrides return nil } -func templateChart(basePath, chart, namespace, outputPath, values, version string, overrides map[string]string) error { +func templateChart(basePath, chart, namespace, outputPath, values string, overrides map[string]string) error { rmErr := os.RemoveAll(outputPath) @@ -131,14 +136,9 @@ func templateChart(basePath, chart, namespace, outputPath, values, version strin valuesStr = "--values " + path.Join(chartRoot, values) } - versionStr := "" - if len(version) > 0 { - versionStr = "--version " + version - } - task := execute.ExecTask{ - Command: fmt.Sprintf("%s template %s --name %s --namespace %s --output-dir %s %s %s %s", - env.LocalBinary("helm", ""), chart, chart, namespace, outputPath, valuesStr, overridesStr, versionStr), + Command: fmt.Sprintf("%s template %s --name %s --namespace %s --output-dir %s %s %s", + env.LocalBinary("helm", ""), chart, chart, namespace, outputPath, valuesStr, overridesStr), Env: os.Environ(), Cwd: basePath, StreamStdio: true, diff --git a/cmd/apps/metricsserver_app.go b/cmd/apps/metricsserver_app.go index c028524d..50edfa69 100644 --- a/cmd/apps/metricsserver_app.go +++ b/cmd/apps/metricsserver_app.go @@ -67,7 +67,7 @@ func MakeInstallMetricsServer() *cobra.Command { } chartPath := path.Join(os.TempDir(), "charts") - err = fetchChart(chartPath, "stable/metrics-server", helm3) + err = fetchChart(chartPath, "stable/metrics-server", defaultVersion, helm3) if err != nil { return err @@ -97,7 +97,6 @@ func MakeInstallMetricsServer() *cobra.Command { namespace, outputPath, "values.yaml", - "", overrides) if err != nil { diff --git a/cmd/apps/minio_app.go b/cmd/apps/minio_app.go index 6d799a9b..379a89d0 100644 --- a/cmd/apps/minio_app.go +++ b/cmd/apps/minio_app.go @@ -75,7 +75,7 @@ func MakeInstallMinio() *cobra.Command { } chartPath := path.Join(os.TempDir(), "charts") - err = fetchChart(chartPath, "stable/minio", false) + err = fetchChart(chartPath, "stable/minio", defaultVersion, false) if err != nil { return err @@ -125,7 +125,6 @@ func MakeInstallMinio() *cobra.Command { ns, outputPath, "values.yaml", - "", overrides) if err != nil { diff --git a/cmd/apps/mongodb_app.go b/cmd/apps/mongodb_app.go index 385430ca..97b6f193 100644 --- a/cmd/apps/mongodb_app.go +++ b/cmd/apps/mongodb_app.go @@ -78,7 +78,7 @@ func MakeInstallMongoDB() *cobra.Command { chartPath := path.Join(os.TempDir(), "charts") - err = fetchChart(chartPath, "stable/mongodb", helm3) + err = fetchChart(chartPath, "stable/mongodb", defaultVersion, helm3) if err != nil { return fmt.Errorf("unable fetch chart %s", err) diff --git a/cmd/apps/nginx_app.go b/cmd/apps/nginx_app.go index da25ffae..881a65fb 100644 --- a/cmd/apps/nginx_app.go +++ b/cmd/apps/nginx_app.go @@ -78,7 +78,7 @@ func MakeInstallNginx() *cobra.Command { } chartPath := path.Join(os.TempDir(), "charts") - err = fetchChart(chartPath, "stable/nginx-ingress", helm3) + err = fetchChart(chartPath, "stable/nginx-ingress", defaultVersion, helm3) if err != nil { return err @@ -134,7 +134,6 @@ func MakeInstallNginx() *cobra.Command { ns, outputPath, "values.yaml", - "", overrides) if err != nil { diff --git a/cmd/apps/openfaas_app.go b/cmd/apps/openfaas_app.go index 8768bffc..7a02d00b 100644 --- a/cmd/apps/openfaas_app.go +++ b/cmd/apps/openfaas_app.go @@ -17,6 +17,7 @@ import ( "github.com/spf13/cobra" ) +const latestVersion = "" func MakeInstallOpenFaaS() *cobra.Command { var openfaas = &cobra.Command{ @@ -137,7 +138,7 @@ func MakeInstallOpenFaaS() *cobra.Command { chartPath := path.Join(os.TempDir(), "charts") - err = fetchChart(chartPath, "openfaas/openfaas", helm3) + err = fetchChart(chartPath, "openfaas/openfaas", defaultVersion, helm3) if err != nil { return err @@ -219,7 +220,6 @@ func MakeInstallOpenFaaS() *cobra.Command { namespace, outputPath, "values"+valuesSuffix+".yaml", - "", overrides) if err != nil { diff --git a/cmd/apps/postgres_app.go b/cmd/apps/postgres_app.go index 0cd26dcb..4516364c 100644 --- a/cmd/apps/postgres_app.go +++ b/cmd/apps/postgres_app.go @@ -73,7 +73,7 @@ func MakeInstallPostgresql() *cobra.Command { } chartPath := path.Join(os.TempDir(), "charts") - err = fetchChart(chartPath, "stable/postgresql", false) + err = fetchChart(chartPath, "stable/postgresql", defaultVersion, false) if err != nil { return err @@ -105,7 +105,6 @@ func MakeInstallPostgresql() *cobra.Command { ns, outputPath, "values.yaml", - "", overrides) if err != nil { diff --git a/cmd/apps/registry_app.go b/cmd/apps/registry_app.go index 90f2f7d8..903320c6 100644 --- a/cmd/apps/registry_app.go +++ b/cmd/apps/registry_app.go @@ -98,7 +98,7 @@ func MakeInstallRegistry() *cobra.Command { } chartPath := path.Join(os.TempDir(), "charts") - err = fetchChart(chartPath, "stable/docker-registry", helm3) + err = fetchChart(chartPath, "stable/docker-registry", defaultVersion, helm3) if err != nil { return err @@ -121,7 +121,7 @@ func MakeInstallRegistry() *cobra.Command { err := helm3Upgrade(outputPath, "stable/docker-registry", ns, "values.yaml", - "", + defaultVersion, overrides) if err != nil { @@ -135,7 +135,6 @@ func MakeInstallRegistry() *cobra.Command { ns, outputPath, "values.yaml", - "", overrides) if err != nil {