Skip to content

Commit

Permalink
Refactor into pkg using an options input and add Loki App
Browse files Browse the repository at this point in the history
Signed-off-by: Alistair Hey <alistair@heyal.co.uk>
  • Loading branch information
Waterdrips authored and alexellis committed Jun 8, 2020
1 parent eaec3d4 commit 3b6845b
Show file tree
Hide file tree
Showing 36 changed files with 827 additions and 655 deletions.
11 changes: 7 additions & 4 deletions cmd/apps/argocd_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
"fmt"
"strings"

"github.com/alexellis/arkade/pkg/config"
"github.com/alexellis/arkade/pkg/k8s"

"github.com/alexellis/arkade/pkg"

"github.com/spf13/cobra"
Expand All @@ -22,30 +25,30 @@ func MakeInstallArgoCD() *cobra.Command {
}

command.RunE = func(command *cobra.Command, args []string) error {
kubeConfigPath := getDefaultKubeconfig()
kubeConfigPath := config.GetDefaultKubeconfig()

if command.Flags().Changed("kubeconfig") {
kubeConfigPath, _ = command.Flags().GetString("kubeconfig")
}

fmt.Printf("Using kubeconfig: %s\n", kubeConfigPath)

arch := getNodeArchitecture()
arch := k8s.GetNodeArchitecture()
fmt.Printf("Node architecture: %q\n", arch)

if arch != IntelArch {
return fmt.Errorf(OnlyIntelArch)
}

_, err := kubectlTask("create", "ns",
_, err := k8s.KubectlTask("create", "ns",
"argocd")
if err != nil {
if !strings.Contains(err.Error(), "exists") {
return err
}
}

_, err = kubectlTask("apply", "-f",
_, err = k8s.KubectlTask("apply", "-f",
"https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml", "-n", "argocd")
if err != nil {
return err
Expand Down
30 changes: 11 additions & 19 deletions cmd/apps/certmanager_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"os"
"path"

"github.com/alexellis/arkade/pkg/k8s"

"github.com/alexellis/arkade/pkg"
"github.com/alexellis/arkade/pkg/config"
"github.com/alexellis/arkade/pkg/env"
Expand All @@ -32,7 +34,7 @@ func MakeInstallCertManager() *cobra.Command {
certManager.RunE = func(command *cobra.Command, args []string) error {
wait, _ := command.Flags().GetBool("wait")
const certManagerVersion = "v0.12.0"
kubeConfigPath := getDefaultKubeconfig()
kubeConfigPath := config.GetDefaultKubeconfig()

if command.Flags().Changed("kubeconfig") {
kubeConfigPath, _ = command.Flags().GetString("kubeconfig")
Expand Down Expand Up @@ -68,21 +70,13 @@ func MakeInstallCertManager() *cobra.Command {
return err
}

err = addHelmRepo("jetstack", "https://charts.jetstack.io", helm3)
updateRepo, _ := certManager.Flags().GetBool("update-repo")
err = helm.AddHelmRepo("jetstack", "https://charts.jetstack.io", updateRepo, helm3)
if err != nil {
return err
}

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

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

nsRes, nsErr := kubectlTask("create", "namespace", namespace)
nsRes, nsErr := k8s.KubectlTask("create", "namespace", namespace)
if nsErr != nil {
return nsErr
}
Expand All @@ -93,14 +87,14 @@ func MakeInstallCertManager() *cobra.Command {

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

err = fetchChart(chartPath, "jetstack/cert-manager", certManagerVersion, helm3)
err = helm.FetchChart("jetstack/cert-manager", certManagerVersion, helm3)
if err != nil {
return err
}

log.Printf("Applying CRD\n")
crdsURL := "https://raw.githubusercontent.com/jetstack/cert-manager/release-0.12/deploy/manifests/00-crds.yaml"
res, err := kubectlTask("apply", "--validate=false", "-f",
res, err := k8s.KubectlTask("apply", "--validate=false", "-f",
crdsURL)
if err != nil {
return err
Expand All @@ -114,9 +108,7 @@ func MakeInstallCertManager() *cobra.Command {
overrides := map[string]string{}

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

err := helm3Upgrade(outputPath, "jetstack/cert-manager", namespace,
err := helm.Helm3Upgrade("jetstack/cert-manager", namespace,
"values.yaml",
"v0.12.0",

This comment has been minimized.

Copy link
@alexellis

alexellis Jul 17, 2020

Owner

@Waterdrips shouldn't this be using certManagerVersion?

This comment has been minimized.

Copy link
@Waterdrips

Waterdrips Jul 17, 2020

Author Contributor

yep - Didnt spot that as it wasnt being changed. Want a pr?

This comment has been minimized.

Copy link
@alexellis

alexellis Jul 17, 2020

Owner

Please

overrides,
Expand All @@ -126,12 +118,12 @@ func MakeInstallCertManager() *cobra.Command {
return err
}
} else {
err = templateChart(chartPath, "cert-manager", namespace, outputPath, "values.yaml", nil)
err = helm.TemplateChart(chartPath, "cert-manager", namespace, outputPath, "values.yaml", nil)
if err != nil {
return err
}

applyRes, applyErr := kubectlTask("apply", "-R", "-f", outputPath)
applyRes, applyErr := k8s.KubectlTask("apply", "-R", "-f", outputPath)
if applyErr != nil {
return applyErr
}
Expand Down
21 changes: 9 additions & 12 deletions cmd/apps/chart_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"path"
"strings"

"github.com/alexellis/arkade/pkg/k8s"

"github.com/alexellis/arkade/pkg"
"github.com/alexellis/arkade/pkg/config"
"github.com/alexellis/arkade/pkg/env"
Expand Down Expand Up @@ -59,7 +61,7 @@ before using the generic helm chart installer command.`,
return fmt.Errorf("--repo-name required")
}

kubeConfigPath := getDefaultKubeconfig()
kubeConfigPath := config.GetDefaultKubeconfig()

if command.Flags().Changed("kubeconfig") {
kubeConfigPath, _ = command.Flags().GetString("kubeconfig")
Expand Down Expand Up @@ -88,33 +90,28 @@ before using the generic helm chart installer command.`,
}

if len(chartRepoURL) > 0 {
err = addHelmRepo(chartPrefix, chartRepoURL, false)
err = helm.AddHelmRepo(chartPrefix, chartRepoURL, true, false)
if err != nil {
return err
}
}

err = updateHelmRepos(false)
if err != nil {
return err
}

res, kcErr := kubectlTask("get", "namespace", namespace)
res, kcErr := k8s.KubectlTask("get", "namespace", namespace)

if kcErr != nil {
return err
}

if res.ExitCode != 0 {
err = kubectl("create", "namespace", namespace)
err = k8s.Kubectl("create", "namespace", namespace)
if err != nil {
return err
}
}

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

err = fetchChart(chartPath, chartRepoName, defaultVersion, false)
err = helm.FetchChart(chartRepoName, defaultVersion, false)
if err != nil {
return err
}
Expand All @@ -135,12 +132,12 @@ before using the generic helm chart installer command.`,
}
}

err = templateChart(chartPath, chartName, namespace, outputPath, "values.yaml", setMap)
err = helm.TemplateChart(chartPath, chartName, namespace, outputPath, "values.yaml", setMap)
if err != nil {
return err
}

err = kubectl("apply", "--namespace", namespace, "-R", "-f", outputPath)
err = k8s.Kubectl("apply", "--namespace", namespace, "-R", "-f", outputPath)
if err != nil {
return err
}
Expand Down
21 changes: 8 additions & 13 deletions cmd/apps/cronconnector_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"os"
"path"

"github.com/alexellis/arkade/pkg/k8s"

"github.com/alexellis/arkade/pkg"
"github.com/alexellis/arkade/pkg/config"
"github.com/alexellis/arkade/pkg/env"
Expand All @@ -29,7 +31,7 @@ func MakeInstallCronConnector() *cobra.Command {
"Use custom flags or override existing flags \n(example --set key=value)")

command.RunE = func(command *cobra.Command, args []string) error {
kubeConfigPath := getDefaultKubeconfig()
kubeConfigPath := config.GetDefaultKubeconfig()

if command.Flags().Changed("kubeconfig") {
kubeConfigPath, _ = command.Flags().GetString("kubeconfig")
Expand Down Expand Up @@ -62,20 +64,13 @@ func MakeInstallCronConnector() *cobra.Command {
return err
}

err = addHelmRepo("openfaas", "https://openfaas.github.io/faas-netes/", false)
err = helm.AddHelmRepo("openfaas", "https://openfaas.github.io/faas-netes/", updateRepo, false)
if err != nil {
return err
}

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

chartPath := path.Join(os.TempDir(), "charts")
err = fetchChart(chartPath, "openfaas/cron-connector", defaultVersion, false)
err = helm.FetchChart("openfaas/cron-connector", defaultVersion, false)

if err != nil {
return err
Expand All @@ -92,15 +87,15 @@ func MakeInstallCronConnector() *cobra.Command {
return err
}

arch := getNodeArchitecture()
arch := k8s.GetNodeArchitecture()
fmt.Printf("Node architecture: %q\n", arch)

fmt.Println("Chart path: ", chartPath)

outputPath := path.Join(chartPath, "cron-connector/rendered")

ns := namespace
err = templateChart(chartPath,
err = helm.TemplateChart(chartPath,
"cron-connector",
ns,
outputPath,
Expand All @@ -111,7 +106,7 @@ func MakeInstallCronConnector() *cobra.Command {
return err
}

err = kubectl("apply", "-R", "-f", outputPath)
err = k8s.Kubectl("apply", "-R", "-f", outputPath)

if err != nil {
return err
Expand Down
30 changes: 11 additions & 19 deletions cmd/apps/crossplane_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"path"
"strings"

"github.com/alexellis/arkade/pkg/k8s"

"github.com/alexellis/arkade/pkg"
"github.com/alexellis/arkade/pkg/config"
"github.com/alexellis/arkade/pkg/env"
Expand All @@ -33,7 +35,7 @@ schedule workloads to any Kubernetes cluster`,

crossplane.RunE = func(command *cobra.Command, args []string) error {
wait, _ := command.Flags().GetBool("wait")
kubeConfigPath := getDefaultKubeconfig()
kubeConfigPath := config.GetDefaultKubeconfig()

if command.Flags().Changed("kubeconfig") {
kubeConfigPath, _ = command.Flags().GetString("kubeconfig")
Expand All @@ -52,7 +54,7 @@ schedule workloads to any Kubernetes cluster`,
return fmt.Errorf(`to override the namespace, install crossplane via helm manually`)
}

arch := getNodeArchitecture()
arch := k8s.GetNodeArchitecture()
if !strings.Contains(arch, "64") {
return fmt.Errorf(`crossplane is currently only supported on 64-bit architectures`)
}
Expand All @@ -76,50 +78,40 @@ schedule workloads to any Kubernetes cluster`,
return err
}

err = addHelmRepo("crossplane-alpha", "https://charts.crossplane.io/alpha", helm3)
updateRepo, _ := crossplane.Flags().GetBool("update-repo")
err = helm.AddHelmRepo("crossplane-alpha", "https://charts.crossplane.io/alpha", updateRepo, helm3)
if err != nil {
return err
}

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

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

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

err = fetchChart(chartPath, "crossplane-alpha/crossplane", defaultVersion, helm3)
err = helm.FetchChart("crossplane-alpha/crossplane", defaultVersion, helm3)
if err != nil {
return err
}

if helm3 {

outputPath := path.Join(chartPath, "crossplane")

_, nsErr := kubectlTask("create", "namespace", "crossplane-system")
_, nsErr := k8s.KubectlTask("create", "namespace", "crossplane-system")
if nsErr != nil && !strings.Contains(nsErr.Error(), "AlreadyExists") {
return nsErr
}

err := helm3Upgrade(outputPath, "crossplane-alpha/crossplane",
err := helm.Helm3Upgrade("crossplane-alpha/crossplane",
namespace, "values.yaml", "", map[string]string{}, wait)
if err != nil {
return err
}

} else {
outputPath := path.Join(chartPath, "crossplane-alpha/crossplane")
err = templateChart(chartPath, "crossplane", namespace, outputPath, "values.yaml", map[string]string{})
err = helm.TemplateChart(chartPath, "crossplane", namespace, outputPath, "values.yaml", map[string]string{})
if err != nil {
return err
}

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

0 comments on commit 3b6845b

Please sign in to comment.