Skip to content

Commit

Permalink
Add support for specifying arbitrary helm values for installing Rancher
Browse files Browse the repository at this point in the history
  • Loading branch information
aruiz14 committed Jan 17, 2025
1 parent 612983c commit a09bbc2
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
28 changes: 25 additions & 3 deletions cmd/dartboard/subcommands/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func Deploy(cli *cli.Context) error {
return GetAccess(cli)
}

func chartInstall(kubeConf string, chart chart, vals map[string]any) error {
func chartInstall(kubeConf string, chart chart, vals map[string]any, extraArgs ...string) error {
var err error

name := chart.name
Expand All @@ -126,7 +126,7 @@ func chartInstall(kubeConf string, chart chart, vals map[string]any) error {

log.Printf("Installing chart %q (%s)\n", namespace+"/"+name, path)

if err = helm.Install(kubeConf, path, name, namespace, vals); err != nil {
if err = helm.Install(kubeConf, path, name, namespace, vals, extraArgs...); err != nil {
return fmt.Errorf("chart %s: %w", name, err)
}
return nil
Expand Down Expand Up @@ -190,7 +190,29 @@ func chartInstallRancher(r *dart.Dart, rancherImageTag string, cluster *tofu.Clu

chartVals := getRancherValsJSON(r.ChartVariables.RancherImageOverride, rancherImageTag, r.ChartVariables.AdminPassword, rancherClusterName, rancherClusterURL, r.ChartVariables.RancherReplicas)

return chartInstall(cluster.Kubeconfig, chartRancher, chartVals)
var extraArgs []string
if r.ChartVariables.Values != "" {
p, err := writeValuesFile(r.ChartVariables.Values)
if err != nil {
return fmt.Errorf("writing extra values file: %w", err)
}
defer os.Remove(p)

extraArgs = append(extraArgs, "-f", p)
}

return chartInstall(cluster.Kubeconfig, chartRancher, chartVals, extraArgs...)
}

func writeValuesFile(content string) (string, error) {
p, err := os.CreateTemp("", "values-*.yaml")
if err != nil {
return "", err
}
if _, err := io.WriteString(p, content); err != nil {
return "", err
}
return p.Name(), nil
}

func chartInstallRancherIngress(cluster *tofu.Cluster) error {
Expand Down
4 changes: 4 additions & 0 deletions darts/aws_full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ chart_variables:
# rancher_image_override: rancher/rancher
# rancher_image_tag_override: v2.8.6-debug-1

# Set arbitrary helm values (in yaml format) for installing Rancher
# values: |
# features: "my-feature-flag=true"

test_variables:
# test_config_maps: 2000
# test_secrets: 2000
Expand Down
4 changes: 4 additions & 0 deletions darts/k3d_full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ chart_variables:
# rancher_image_override: rancher/rancher
# rancher_image_tag_override: v2.8.6-debug-1

# Set arbitrary helm values (in yaml format) for installing Rancher
# values: |
# features: "my-feature-flag=true"

test_variables:
# test_config_maps: 2000
# test_secrets: 2000
Expand Down
1 change: 1 addition & 0 deletions internal/dart/recipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type ChartVariables struct {
RancherMonitoringVersion string `yaml:"rancher_monitoring_version"`
CertManagerVersion string `yaml:"cert_manager_version"`
TesterGrafanaVersion string `yaml:"tester_grafana_version"`
Values string `yaml:"values"`
}

type TestVariables struct {
Expand Down
3 changes: 2 additions & 1 deletion internal/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/rancher/dartboard/internal/vendored"
)

func Install(kubecfg, chartLocation, releaseName, namespace string, vals map[string]any) error {
func Install(kubecfg, chartLocation, releaseName, namespace string, vals map[string]any, extraArgs ...string) error {
args := []string{
"--kubeconfig=" + kubecfg,
"upgrade",
Expand All @@ -46,6 +46,7 @@ func Install(kubecfg, chartLocation, releaseName, namespace string, vals map[str
}
args = append(args, "--set-json="+valueString)
}
args = append(args, extraArgs...)

cmd := vendored.Command("helm", args...)
var errStream strings.Builder
Expand Down

0 comments on commit a09bbc2

Please sign in to comment.