Skip to content

Commit

Permalink
Add traefik2 app
Browse files Browse the repository at this point in the history
This commit moves over to helm3 and applies the feedback from
the PR review on #23

Tested on k3d and got an LB as expected with Traefik 2.

Co-authored-by: Bryan Bautista <braybaut@gmail.com>

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
braybaut authored and alexellis committed Mar 7, 2020
1 parent 17fb795 commit 1bb8afe
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 0 deletions.
153 changes: 153 additions & 0 deletions cmd/apps/traefik2_app.go
@@ -0,0 +1,153 @@
package apps

import (
"fmt"
"os"
"path"

"github.com/alexellis/arkade/pkg"
"github.com/alexellis/arkade/pkg/config"
"github.com/alexellis/arkade/pkg/env"
"github.com/alexellis/arkade/pkg/helm"
execute "github.com/alexellis/go-execute/pkg/v1"

"github.com/spf13/cobra"
)

func MakeInstallTraefik2() *cobra.Command {
var traefik2 = &cobra.Command{
Use: "traefik2",
Short: "Install traefik2",
Long: "Install traefik2",
Example: ` arkade app install traefik2`,
SilenceUsage: true,
}

traefik2.Flags().StringP("namespace", "n", "kube-system", "The namespace used for installation")
traefik2.Flags().Bool("update-repo", true, "Update the helm repo")
traefik2.Flags().Bool("load-balancer", true, "Use a load-balancer for the IngressController")
traefik2.Flags().Bool("dashboard", false, "Expose dashboard if you want access to dashboard from the browser")
traefik2.Flags().StringArray("set", []string{},
"Use custom flags or override existing flags \n(example --set key=value)")
traefik2.Flags().Bool("wait", false, "Wait for the chart to be installed")

traefik2.RunE = func(command *cobra.Command, args []string) error {

kubeConfigPath := getDefaultKubeconfig()
if command.Flags().Changed("kubeconfig") {
kubeConfigPath, _ = command.Flags().GetString("kubeconfig")
}
fmt.Printf("Using kubeconfig: %s\n", kubeConfigPath)

updateRepo, _ := traefik2.Flags().GetBool("update-repo")
namespace, _ := traefik2.Flags().GetString("namespace")
userPath, err := config.InitUserDir()
if err != nil {
return err
}

_, clientOS := env.GetClientArch()
clientArch, clientOS := env.GetClientArch()
fmt.Printf("Client: %q\n", clientOS)
helm3 := true

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

err = addHelmRepo("traefik", "https://containous.github.io/traefik-helm-chart", helm3)
if err != nil {
return fmt.Errorf("Unable to add repo %s", err)
}

if updateRepo {
err = updateHelmRepos(helm3)
if err != nil {
return err
}
}

chartPath := path.Join(os.TempDir(), "charts")
err = fetchChart(chartPath, "traefik/traefik", "", helm3)
if err != nil {
return fmt.Errorf("Unable fetch chart: %s", err)
}

overrides := map[string]string{}
lb, _ := command.Flags().GetBool("load-balancer")
dashboard, _ := command.Flags().GetBool("dashboard")
wait, _ := command.Flags().GetBool("wait")

svc := "NodePort"
if lb {
svc = "LoadBalancer"
}
overrides["service.type"] = svc

overrides["additional.checkNewVersion"] = "false"
overrides["additional.sendAnonymousUsage"] = "false"

if dashboard {
overrides["dashboard.ingressRoute"] = "true"
}

customFlags, err := command.Flags().GetStringArray("set")
if err != nil {
return fmt.Errorf("error with --set usage: %s", err)
}

if err := mergeFlags(overrides, customFlags); err != nil {
return err
}

outputPath := path.Join(chartPath, "traefik")
err = helm3Upgrade(outputPath, "traefik/traefik", namespace,
"values.yaml",
"",
overrides,
wait)

if err != nil {
return err
}

fmt.Println(traefikInstallMsg)
return nil
}

return traefik2
}

func installTraefik2(parts ...string) (execute.ExecResult, error) {

task := execute.ExecTask{
Command: "helm",
Args: parts,
StreamStdio: true,
}
res, err := task.Execute()
if err != nil {
return res, err
}
if res.ExitCode != 0 {
return res, fmt.Errorf("exit code %d, stderr: %s", res.ExitCode, res.Stderr)
}
return res, nil
}

const Traefik2InfoMsg = `# Get started at: https://docs.traefik.io/v2.0/
# Install with an optional dashboard
arkade install traefik2 --dashboard
# Find your LoadBalancer IP:
kubectl get svc -n kube-system traefik
`

const traefikInstallMsg = `=======================================================================
= traefik2 has been installed =
=======================================================================
` + pkg.ThanksForUsing + Traefik2InfoMsg
3 changes: 3 additions & 0 deletions cmd/info.go
Expand Up @@ -83,6 +83,9 @@ arkade info --help`,
case "docker-registry-ingress":
fmt.Printf("Info for app: %s\n", appName)
fmt.Println(apps.RegistryIngressInfoMsg)
case "traefik2":
fmt.Printf("Info for app: %s\n", appName)
fmt.Println(apps.Traefik2InfoMsg)
default:
return fmt.Errorf("no info available for app: %s", appName)
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/install.go
Expand Up @@ -56,6 +56,7 @@ command.`,
command.AddCommand(apps.MakeInstallMongoDB())
command.AddCommand(apps.MakeInstallRegistry())
command.AddCommand(apps.MakeInstallRegistryIngress())
command.AddCommand(apps.MakeInstallTraefik2())

command.AddCommand(MakeInfo())

Expand All @@ -81,5 +82,6 @@ func getApps() []string {
"mongodb",
"docker-registry",
"docker-registry-ingress",
"traefik2",
}
}

0 comments on commit 1bb8afe

Please sign in to comment.