Skip to content

Commit

Permalink
Convert cert-manager to use helm3 by default
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Feb 11, 2020
1 parent b98a9e8 commit 6953993
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 25 deletions.
57 changes: 38 additions & 19 deletions cmd/apps/certmanager_app.go
Expand Up @@ -24,6 +24,7 @@ func MakeInstallCertManager() *cobra.Command {

certManager.Flags().StringP("namespace", "n", "cert-manager", "The namespace to install cert-manager")
certManager.Flags().Bool("update-repo", true, "Update the helm repo")
certManager.Flags().Bool("helm3", true, "Use helm3, if set to false uses helm2")

certManager.RunE = func(command *cobra.Command, args []string) error {
kubeConfigPath := getDefaultKubeconfig()
Expand All @@ -33,7 +34,11 @@ func MakeInstallCertManager() *cobra.Command {
}

fmt.Printf("Using kubeconfig: %s\n", kubeConfigPath)
helm3, _ := command.Flags().GetBool("helm3")

if helm3 {
fmt.Println("Using helm3")
}
namespace, _ := command.Flags().GetString("namespace")

if namespace != "cert-manager" {
Expand All @@ -53,20 +58,20 @@ func MakeInstallCertManager() *cobra.Command {

os.Setenv("HELM_HOME", path.Join(userPath, ".helm"))

_, err = helm.TryDownloadHelm(userPath, clientArch, clientOS, false)
_, err = helm.TryDownloadHelm(userPath, clientArch, clientOS, helm3)
if err != nil {
return err
}

err = addHelmRepo("jetstack", "https://charts.jetstack.io", false)
err = addHelmRepo("jetstack", "https://charts.jetstack.io", helm3)
if err != nil {
return err
}

updateRepo, _ := certManager.Flags().GetBool("update-repo")

if updateRepo {
err = updateHelmRepos(false)
err = updateHelmRepos(helm3)
if err != nil {
return err
}
Expand All @@ -83,14 +88,7 @@ func MakeInstallCertManager() *cobra.Command {

chartPath := path.Join(os.TempDir(), "charts")

err = fetchChart(chartPath, "jetstack/cert-manager", false)
if err != nil {
return err
}

outputPath := path.Join(chartPath, "cert-manager/rendered")

err = templateChart(chartPath, "cert-manager", namespace, outputPath, "values.yaml", nil)
err = fetchChart(chartPath, "jetstack/cert-manager", helm3)
if err != nil {
return err
}
Expand All @@ -104,16 +102,37 @@ func MakeInstallCertManager() *cobra.Command {
}

if res.ExitCode > 0 {
return fmt.Errorf("Error applying CRD from: %s, error: %s", crdsURL, res.Stderr)
return fmt.Errorf("error applying CRD from: %s, error: %s", crdsURL, res.Stderr)
}

applyRes, applyErr := kubectlTask("apply", "-R", "-f", outputPath)
if applyErr != nil {
return applyErr
}
outputPath := path.Join(chartPath, "cert-manager/rendered")
overrides := map[string]string{}
wait := false

if helm3 {
outputPath := path.Join(chartPath, "cert-manager")

err := helm3Upgrade(outputPath, "jetstack/cert-manager", namespace,
"values.yaml",
overrides, wait)

if applyRes.ExitCode > 0 {
return fmt.Errorf("Error applying templated YAML files, error: %s", applyRes.Stderr)
if err != nil {
return err
}
} else {
err = templateChart(chartPath, "cert-manager", namespace, outputPath, "values.yaml", nil)
if err != nil {
return err
}

applyRes, applyErr := kubectlTask("apply", "-R", "-f", outputPath)
if applyErr != nil {
return applyErr
}

if applyRes.ExitCode > 0 {
return fmt.Errorf("error applying templated YAML files, error: %s", applyRes.Stderr)
}
}

fmt.Println(certManagerInstallMsg)
Expand All @@ -134,4 +153,4 @@ kubectl logs -n cert-manager deploy/cert-manager -f`
const certManagerInstallMsg = `=======================================================================
= cert-manager has been installed. =
=======================================================================` +
"\n\n" + CertManagerInfoMsg + "\n\n" + pkg.ThanksForUsing
"\n\n" + CertManagerInfoMsg + "\n\n" + pkg.ThanksForUsing
4 changes: 2 additions & 2 deletions cmd/apps/crossplane_app.go
Expand Up @@ -26,7 +26,7 @@ schedule workloads to any Kubernetes cluster`,

crossplane.Flags().StringP("namespace", "n", "crossplane-system", "The namespace used for installation")
crossplane.Flags().Bool("update-repo", true, "Update the helm repo")
crossplane.Flags().Bool("helm3", false, "Use helm3 instead of the default helm2")
crossplane.Flags().Bool("helm3", false, "Use helm3, if set to false uses helm2")

crossplane.RunE = func(command *cobra.Command, args []string) error {
kubeConfigPath := getDefaultKubeconfig()
Expand Down Expand Up @@ -146,4 +146,4 @@ Learn more about Crossplane: https://crossplaneio.github.io/docs/`
const crossplaneInstallMsg = `=======================================================================
= Crossplane has been installed. =
=======================================================================` +
"\n\n" + CrossplanInfoMsg + "\n\n" + pkg.ThanksForUsing
"\n\n" + CrossplanInfoMsg + "\n\n" + pkg.ThanksForUsing
2 changes: 1 addition & 1 deletion cmd/apps/inletsoperator_app.go
Expand Up @@ -34,7 +34,7 @@ func MakeInstallInletsOperator() *cobra.Command {
inletsOperator.Flags().Bool("update-repo", true, "Update the helm repo")

inletsOperator.Flags().String("pro-client-image", "", "Docker image for inlets-pro's client")
inletsOperator.Flags().Bool("helm3", true, "Use helm3 instead of the default helm2")
inletsOperator.Flags().Bool("helm3", true, "Use helm3, if set to false uses helm2")
inletsOperator.Flags().StringArray("set", []string{}, "Use custom flags or override existing flags \n(example --set=image=org/repo:tag)")

inletsOperator.RunE = func(command *cobra.Command, args []string) error {
Expand Down
2 changes: 1 addition & 1 deletion cmd/apps/metricsserver_app.go
Expand Up @@ -23,7 +23,7 @@ func MakeInstallMetricsServer() *cobra.Command {
}

metricsServer.Flags().StringP("namespace", "n", "kube-system", "The namespace used for installation")
metricsServer.Flags().Bool("helm3", false, "Use helm3 instead of the default helm2")
metricsServer.Flags().Bool("helm3", false, "Use helm3, if set to false uses helm2")

metricsServer.RunE = func(command *cobra.Command, args []string) error {
kubeConfigPath := getDefaultKubeconfig()
Expand Down
2 changes: 1 addition & 1 deletion cmd/apps/nginx_app.go
Expand Up @@ -25,7 +25,7 @@ func MakeInstallNginx() *cobra.Command {
nginx.Flags().StringP("namespace", "n", "default", "The namespace used for installation")
nginx.Flags().Bool("update-repo", true, "Update the helm repo")
nginx.Flags().Bool("host-mode", false, "If we should install nginx-ingress in host mode.")
nginx.Flags().Bool("helm3", true, "Use helm3 instead of the default helm2")
nginx.Flags().Bool("helm3", true, "Use helm3, if set to false uses helm2")

nginx.RunE = func(command *cobra.Command, args []string) error {
kubeConfigPath := getDefaultKubeconfig()
Expand Down
2 changes: 1 addition & 1 deletion cmd/apps/openfaas_app.go
Expand Up @@ -42,7 +42,7 @@ func MakeInstallOpenFaaS() *cobra.Command {
openfaas.Flags().Int("queue-workers", 1, "Replicas of queue-worker")
openfaas.Flags().Int("gateways", 1, "Replicas of gateway")

openfaas.Flags().Bool("helm3", false, "Use helm3 instead of the default helm2")
openfaas.Flags().Bool("helm3", false, "Use helm3, if set to false uses helm2")

openfaas.Flags().StringArray("set", []string{}, "Use custom flags or override existing flags \n(example --set=gateway.replicas=2)")

Expand Down

0 comments on commit 6953993

Please sign in to comment.