Skip to content

Commit

Permalink
updated repo for jenkins, minio and grafana
Browse files Browse the repository at this point in the history
Signed-off-by: Nitishkumar Singh <[email protected]>

updated grafana, minio and jenkins to new style

Signed-off-by: Nitishkumar Singh <[email protected]>

removed additional commented code

Signed-off-by: Nitishkumar Singh <[email protected]>

included set options

Signed-off-by: Nitishkumar Singh <[email protected]>
  • Loading branch information
nitishkumar71 committed Dec 5, 2020
1 parent 55e27c5 commit d7e46d6
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 74 deletions.
73 changes: 52 additions & 21 deletions cmd/apps/grafana_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import (
"os"
"path"

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

"github.com/alexellis/arkade/pkg"
"github.com/alexellis/arkade/pkg/apps"
"github.com/alexellis/arkade/pkg/config"
"github.com/alexellis/arkade/pkg/env"
"github.com/alexellis/arkade/pkg/helm"
"github.com/alexellis/arkade/pkg/k8s"
"github.com/alexellis/arkade/pkg/types"
"github.com/spf13/cobra"
)

Expand All @@ -30,19 +31,36 @@ func MakeInstallGrafana() *cobra.Command {
grafana.Flags().StringP("namespace", "n", "grafana", "The namespace to install grafana")
grafana.Flags().Bool("update-repo", true, "Update the helm repo")
grafana.Flags().Bool("persistence", false, "Make grafana persistent")
grafana.Flags().StringArray("set", []string{},
"Use custom flags or override existing flags \n(example --set persistence.enabled=true)")

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

const chartVersion = "5.0.4"

// Get all flags
kubeConfigPath, _ := command.Flags().GetString("kubeconfig")
kubeConfigPath, err := command.Flags().GetString("kubeconfig")
if err != nil {
return fmt.Errorf("error with --kubeconfig usage: %s", err)
}
if err := config.SetKubeconfig(kubeConfigPath); err != nil {
return err
}
wait, _ := command.Flags().GetBool("wait")
persistence, _ := command.Flags().GetBool("persistence")
namespace, _ := command.Flags().GetString("namespace")

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

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

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

// initialize client env
userPath, err := config.InitUserDir()
Expand All @@ -62,10 +80,9 @@ func MakeInstallGrafana() *cobra.Command {
return err
}

updateRepo, _ := grafana.Flags().GetBool("update-repo")
err = helm.AddHelmRepo("stable", "https://charts.helm.sh/stable", updateRepo)
updateRepo, err := grafana.Flags().GetBool("update-repo")
if err != nil {
return err
return fmt.Errorf("error with --update-repo usage: %s", err)
}

// create the namespace
Expand All @@ -79,12 +96,6 @@ func MakeInstallGrafana() *cobra.Command {
log.Printf("[Warning] unable to create namespace %s, may already exist: %s", namespace, nsRes.Stderr)
}

// download the chart
err = helm.FetchChart("stable/grafana", chartVersion)
if err != nil {
return err
}

// define the values to override
// due the missing arm support. datasource and dashboard sidecars are not possible
overrides := map[string]string{
Expand All @@ -97,13 +108,33 @@ func MakeInstallGrafana() *cobra.Command {
overrides["persistence.size"] = "2Gi"
}

// install the chart
err = helm.Helm3Upgrade("stable/grafana", namespace,
"values.yaml",
chartVersion,
overrides,
wait)
// set custom flags
customFlags, err := grafana.Flags().GetStringArray("set")
if err != nil {
return fmt.Errorf("error with --set usage: %s", err)
}

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

grafanaAppOptions := types.DefaultInstallOptions().
WithNamespace(namespace).
WithHelmPath(path.Join(userPath, ".helm")).
WithHelmRepo("grafana/grafana").
WithHelmURL("https://grafana.github.io/helm-charts/").
WithHelmRepoVersion(chartVersion).
WithOverrides(overrides).
WithHelmUpdateRepo(updateRepo).
WithKubeconfigPath(kubeConfigPath).
WithWait(wait)

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

_, err = apps.MakeInstallChart(grafanaAppOptions)
if err != nil {
return err
}
Expand Down
57 changes: 33 additions & 24 deletions cmd/apps/jenkins_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (
"strconv"
"strings"

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

"github.com/alexellis/arkade/pkg"
"github.com/alexellis/arkade/pkg/config"
Expand All @@ -36,13 +38,20 @@ func MakeInstallJenkins() *cobra.Command {
"Use custom flags or override existing flags \n(example --set persistence.enabled=true)")

jenkins.RunE = func(command *cobra.Command, args []string) error {
kubeConfigPath := config.GetDefaultKubeconfig()
wait, _ := command.Flags().GetBool("wait")
wait, err := command.Flags().GetBool("wait")
if err != nil {
return fmt.Errorf("error with --wait usage: %s", err)
}

kubeConfigPath, err := command.Flags().GetString("kubeconfig")
if err != nil {
return fmt.Errorf("error with kubeconfig path: %s", err)
}

if command.Flags().Changed("kubeconfig") {
kubeConfigPath, _ = command.Flags().GetString("kubeconfig")
updateRepo, err := jenkins.Flags().GetBool("update-repo")
if err != nil {
return fmt.Errorf("error with update-repo usage: %s", err)
}
updateRepo, _ := jenkins.Flags().GetBool("update-repo")

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

Expand All @@ -65,27 +74,17 @@ func MakeInstallJenkins() *cobra.Command {

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

ns, _ := jenkins.Flags().GetString("namespace")

_, err = helm.TryDownloadHelm(userPath, clientArch, clientOS)
ns, err := jenkins.Flags().GetString("namespace")
if err != nil {
return err
return fmt.Errorf("error with namespace usage: %s", err)
}

err = helm.AddHelmRepo("stable", "https://charts.helm.sh/stable", updateRepo)
persistence, err := jenkins.Flags().GetBool("persistence")
if err != nil {
return err
return fmt.Errorf("error with persistence usage: %s", err)
}

err = helm.FetchChart("stable/jenkins", defaultVersion)

if err != nil {
return err
}

persistence, _ := jenkins.Flags().GetBool("persistence")
overrides := map[string]string{}

overrides["persistence.enabled"] = strings.ToLower(strconv.FormatBool(persistence))

customFlags, err := jenkins.Flags().GetStringArray("set")
Expand All @@ -97,12 +96,22 @@ func MakeInstallJenkins() *cobra.Command {
return err
}

err = helm.Helm3Upgrade("stable/jenkins", ns,
"values.yaml",
defaultVersion,
overrides,
wait)
jenkinsAppOptions := types.DefaultInstallOptions().
WithNamespace(ns).
WithHelmPath(path.Join(userPath, ".helm")).
WithHelmRepo("jenkins/jenkins").
WithHelmURL("https://charts.jenkins.io/").
WithOverrides(overrides).
WithHelmUpdateRepo(updateRepo).
WithKubeconfigPath(kubeConfigPath).
WithWait(wait)

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

_, err = apps.MakeInstallChart(jenkinsAppOptions)
if err != nil {
return err
}
Expand Down
73 changes: 44 additions & 29 deletions cmd/apps/minio_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (
"strconv"
"strings"

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

"github.com/alexellis/arkade/pkg"
"github.com/alexellis/arkade/pkg/config"
Expand Down Expand Up @@ -40,14 +42,21 @@ func MakeInstallMinio() *cobra.Command {
"Use custom flags or override existing flags \n(example --set persistence.enabled=true)")

minio.RunE = func(command *cobra.Command, args []string) error {
kubeConfigPath, _ := command.Flags().GetString("kubeconfig")
kubeConfigPath, err := command.Flags().GetString("kubeconfig")
if err != nil {
return fmt.Errorf("error with --kubeconfig usage: %s", err)
}
fmt.Printf("Using kubeconfig: %s\n", kubeConfigPath)
if err := config.SetKubeconfig(kubeConfigPath); err != nil {
return err

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

updateRepo, _ := minio.Flags().GetBool("update-repo")
updateRepo, err := minio.Flags().GetBool("update-repo")
if err != nil {
return fmt.Errorf("error with --update-repo usage: %s", err)
}

arch := k8s.GetNodeArchitecture()
fmt.Printf("Node architecture: %q\n", arch)
Expand All @@ -68,34 +77,26 @@ func MakeInstallMinio() *cobra.Command {

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

ns, _ := minio.Flags().GetString("namespace")

if ns != "default" {
return fmt.Errorf("please use the helm chart if you'd like to change the namespace to %s", ns)
ns, err := minio.Flags().GetString("namespace")
if err != nil {
return fmt.Errorf("error with --namespace usage: %s", err)
}

_, err = helm.TryDownloadHelm(userPath, clientArch, clientOS)
persistence, err := minio.Flags().GetBool("persistence")
if err != nil {
return err
return fmt.Errorf("error with --persistence usage: %s", err)
}

err = helm.AddHelmRepo("stable", "https://charts.helm.sh/stable", updateRepo)
overrides := map[string]string{}
accessKey, err := minio.Flags().GetString("access-key")
if err != nil {
return err
return fmt.Errorf("error with --access-key usage: %s", err)
}

err = helm.FetchChart("stable/minio", defaultVersion)

secretKey, err := minio.Flags().GetString("secret-key")
if err != nil {
return err
return fmt.Errorf("error with --secret-key usage: %s", err)
}

persistence, _ := minio.Flags().GetBool("persistence")

overrides := map[string]string{}
accessKey, _ := minio.Flags().GetString("access-key")
secretKey, _ := minio.Flags().GetString("secret-key")

gen, err := password.NewGenerator(&password.GeneratorInput{
Symbols: "+/",
})
Expand All @@ -121,7 +122,11 @@ func MakeInstallMinio() *cobra.Command {

overrides["persistence.enabled"] = strings.ToLower(strconv.FormatBool(persistence))

if dist, _ := minio.Flags().GetBool("distributed"); dist {
dist, err := minio.Flags().GetBool("distributed")
if err != nil {
return fmt.Errorf("error with --distributed usage: %s", err)
}
if dist {
overrides["mode"] = "distributed"
}

Expand All @@ -134,12 +139,22 @@ func MakeInstallMinio() *cobra.Command {
return err
}

err = helm.Helm3Upgrade("stable/minio", ns,
"values.yaml",
defaultVersion,
overrides,
wait)
minioAppOptions := types.DefaultInstallOptions().
WithNamespace(ns).
WithHelmPath(path.Join(userPath, ".helm")).
WithHelmRepo("minio/minio").
WithHelmURL("https://helm.min.io/").
WithOverrides(overrides).
WithHelmUpdateRepo(updateRepo).
WithKubeconfigPath(kubeConfigPath).
WithWait(wait)

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

_, err = apps.MakeInstallChart(minioAppOptions)
if err != nil {
return err
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ func (o *InstallerOptions) WithHelmRepo(s string) *InstallerOptions {
return o
}

func (o *InstallerOptions) WithHelmRepoVersion(s string) *InstallerOptions {
o.Helm.Repo.Version = s
return o
}

func (o *InstallerOptions) WithHelmURL(s string) *InstallerOptions {
o.Helm.Repo.URL = s
return o
Expand Down

0 comments on commit d7e46d6

Please sign in to comment.