Skip to content

Commit

Permalink
Re-add the --wait flag to the helm3 installation
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Waterdrips authored and alexellis committed Feb 21, 2020
1 parent 17f05fb commit fa2f0d1
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 38 deletions.
5 changes: 3 additions & 2 deletions cmd/apps/certmanager_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/apps/chart_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/apps/cronconnector_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -105,7 +105,6 @@ func MakeInstallCronConnector() *cobra.Command {
ns,
outputPath,
"values.yaml",
"",
overrides)

if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/apps/crossplane_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/apps/inletsoperator_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/apps/istio_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions cmd/apps/kafkaconnector_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -122,7 +122,6 @@ func MakeInstallKafkaConnector() *cobra.Command {
ns,
outputPath,
"values.yaml",
"",
overrides)

if err != nil {
Expand Down
22 changes: 11 additions & 11 deletions cmd/apps/kubernetes_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
}
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)

Expand All @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions cmd/apps/metricsserver_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -97,7 +97,6 @@ func MakeInstallMetricsServer() *cobra.Command {
namespace,
outputPath,
"values.yaml",
"",
overrides)

if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions cmd/apps/minio_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -125,7 +125,6 @@ func MakeInstallMinio() *cobra.Command {
ns,
outputPath,
"values.yaml",
"",
overrides)

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/apps/mongodb_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions cmd/apps/nginx_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -134,7 +134,6 @@ func MakeInstallNginx() *cobra.Command {
ns,
outputPath,
"values.yaml",
"",
overrides)

if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/apps/openfaas_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/spf13/cobra"
)

const latestVersion = ""

func MakeInstallOpenFaaS() *cobra.Command {
var openfaas = &cobra.Command{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -219,7 +220,6 @@ func MakeInstallOpenFaaS() *cobra.Command {
namespace,
outputPath,
"values"+valuesSuffix+".yaml",
"",
overrides)

if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions cmd/apps/postgres_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -105,7 +105,6 @@ func MakeInstallPostgresql() *cobra.Command {
ns,
outputPath,
"values.yaml",
"",
overrides)

if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions cmd/apps/registry_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -121,7 +121,7 @@ func MakeInstallRegistry() *cobra.Command {

err := helm3Upgrade(outputPath, "stable/docker-registry", ns,
"values.yaml",
"",
defaultVersion,
overrides)

if err != nil {
Expand All @@ -135,7 +135,6 @@ func MakeInstallRegistry() *cobra.Command {
ns,
outputPath,
"values.yaml",
"",
overrides)

if err != nil {
Expand Down

0 comments on commit fa2f0d1

Please sign in to comment.