Add override option to Dart files for rancher charts repo (#81)

This commit is contained in:
Iramis Valentin 2025-07-23 17:39:27 -04:00 committed by GitHub
parent a257320e86
commit fd824db806
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 68 additions and 6 deletions

View File

@ -118,7 +118,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
@ -130,7 +130,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
@ -218,13 +218,35 @@ func chartInstallRancher(r *dart.Dart, rancherImageTag string, cluster *tofu.Clu
chartVals := getRancherValsJSON(r.ChartVariables.RancherImageOverride, rancherImageTag, r.ChartVariables.AdminPassword, rancherClusterName, extraEnv, r.ChartVariables.RancherReplicas)
var extraArgs []string
if r.ChartVariables.RancherValues != "" {
p, err := writeValuesFile(r.ChartVariables.RancherValues)
if err != nil {
return fmt.Errorf("writing extra values file: %w", err)
}
defer os.Remove(p)
extraArgs = append(extraArgs, "-f", p)
}
fmt.Printf("\n\nRANCHER CHART VALS:\n")
for key, value := range chartVals {
fmt.Printf("\t%s = %v\n", key, value)
}
return chartInstall(cluster.Kubeconfig, chartRancher, chartVals)
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 {
@ -257,11 +279,18 @@ func chartInstallRancherIngress(cluster *tofu.Cluster) error {
func chartInstallRancherMonitoring(r *dart.Dart, cluster *tofu.Cluster) error {
rancherMinorVersion := strings.Join(strings.Split(r.ChartVariables.RancherVersion, ".")[0:2], ".")
const chartPrefix = "https://github.com/rancher/charts/raw/release-v"
chartPath := fmt.Sprintf("%s%s", chartPrefix, rancherMinorVersion)
if len(r.ChartVariables.RancherAppsRepoOverride) > 0 {
chartPath = r.ChartVariables.RancherAppsRepoOverride
}
chartRancherMonitoringCRDRoute := "assets/rancher-monitoring-crd/rancher-monitoring-crd"
chartRancherMonitoringCRD := chart{
name: "rancher-monitoring-crd",
namespace: "cattle-monitoring-system",
path: fmt.Sprintf("https://github.com/rancher/charts/raw/release-v%s/assets/rancher-monitoring-crd/rancher-monitoring-crd-%s.tgz", rancherMinorVersion, r.ChartVariables.RancherMonitoringVersion),
path: fmt.Sprintf("%s/%s-%s.tgz", chartPath, chartRancherMonitoringCRDRoute, r.ChartVariables.RancherMonitoringVersion),
}
chartVals := map[string]any{
@ -279,10 +308,11 @@ func chartInstallRancherMonitoring(r *dart.Dart, cluster *tofu.Cluster) error {
return err
}
chartRancherMonitoringRoute := "assets/rancher-monitoring/rancher-monitoring"
chartRancherMonitoring := chart{
name: "rancher-monitoring",
namespace: "cattle-monitoring-system",
path: fmt.Sprintf("https://github.com/rancher/charts/raw/release-v%s/assets/rancher-monitoring/rancher-monitoring-%s.tgz", rancherMinorVersion, r.ChartVariables.RancherMonitoringVersion),
path: fmt.Sprintf("%s/%s-%s.tgz", chartPath, chartRancherMonitoringRoute, r.ChartVariables.RancherMonitoringVersion),
}
clusterAdd, err := getAppAddressFor(*cluster)

View File

@ -63,11 +63,18 @@ chart_variables:
rancher_replicas: 1
downstream_rancher_monitoring: true
admin_password: adminadminadmin
# rancher_apps_repo_override: # must be the "raw" link not the "blob" link ex: https://github.com/rancher/charts/raw/dev-v2.11 vs https://github.com/rancher/charts/blob/dev-v2.12
rancher_monitoring_version: 104.1.0+up57.0.3 # see https://github.com/rancher/charts/tree/release-v2.9/assets/rancher-monitoring-crd
cert_manager_version: 1.8.0
tester_grafana_version: 6.56.5
rancher_version: 2.9.1
# rancher_chart_repo_override: # URL override defining where to pull Rancher's helm chart from
force_prime_registry: false
# extra_environment_variables:
# - name: CATTLE_FEATURES
# value: aggregated-roletemplates=true
# - name: CATTLE_AGENT_IMAGE
# value: ""
# Use the following for 2.8.6:
# rancher_version: 2.8.6

View File

@ -89,11 +89,18 @@ chart_variables:
rancher_replicas: 1
downstream_rancher_monitoring: true
admin_password: adminadminadmin
# rancher_apps_repo_override: # must be the "raw" link not the "blob" link ex: https://github.com/rancher/charts/raw/dev-v2.11 vs https://github.com/rancher/charts/blob/dev-v2.12
rancher_monitoring_version: 104.1.0+up57.0.3 # see https://github.com/rancher/charts/tree/release-v2.9/assets/rancher-monitoring-crd
cert_manager_version: 1.8.0
tester_grafana_version: 6.56.5
rancher_version: 2.9.1
# rancher_chart_repo_override: # URL override defining where to pull Rancher's helm chart from
force_prime_registry: false
# extra_environment_variables:
# - name: CATTLE_FEATURES
# value: aggregated-roletemplates=true
# - name: CATTLE_AGENT_IMAGE
# value: ""
# Use the following for 2.8.6:
# rancher_version: 2.8.6

View File

@ -136,11 +136,18 @@ chart_variables:
rancher_replicas: 1
downstream_rancher_monitoring: true
admin_password: adminadminadmin
# rancher_apps_repo_override: # must be the "raw" link not the "blob" link ex: https://github.com/rancher/charts/raw/dev-v2.11 vs https://github.com/rancher/charts/blob/dev-v2.12
rancher_monitoring_version: 104.1.0+up57.0.3 # see https://github.com/rancher/charts/tree/release-v2.9/assets/rancher-monitoring-crd
cert_manager_version: 1.8.0
tester_grafana_version: 6.56.5
rancher_version: 2.9.1
# rancher_chart_repo_override: # URL override defining where to pull Rancher's helm chart from
force_prime_registry: false
# extra_environment_variables:
# - name: CATTLE_FEATURES
# value: aggregated-roletemplates=true
# - name: CATTLE_AGENT_IMAGE
# value: ""
# Use the following for 2.8.6:
# rancher_version: 2.8.6
@ -150,6 +157,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
# rancher_values: |
# features: "my-feature-flag=true"
test_variables:
test_config_maps: 2000
test_secrets: 2000

View File

@ -45,11 +45,18 @@ chart_variables:
rancher_replicas: 1
downstream_rancher_monitoring: true
admin_password: adminadminadmin
# rancher_apps_repo_override: # must be the "raw" link not the "blob" link ex: https://github.com/rancher/charts/raw/dev-v2.11 vs https://github.com/rancher/charts/blob/dev-v2.12
rancher_monitoring_version: 104.1.0+up57.0.3 # see https://github.com/rancher/charts/tree/release-v2.9/assets/rancher-monitoring-crd
cert_manager_version: 1.8.0
tester_grafana_version: 6.56.5
rancher_version: 2.9.1
# rancher_chart_repo_override: # URL override defining where to pull Rancher's helm chart from
force_prime_registry: false
# extra_environment_variables:
# - name: CATTLE_FEATURES
# value: aggregated-roletemplates=true
# - name: CATTLE_AGENT_IMAGE
# value: ""
# Use the following for 2.8.6:
# rancher_version: 2.8.6
@ -63,7 +70,6 @@ chart_variables:
# rancher_values: |
# features: "my-feature-flag=true"
test_variables:
test_config_maps: 2000
test_secrets: 2000

View File

@ -27,6 +27,7 @@ type ChartVariables struct {
AdminPassword string `yaml:"admin_password"`
RancherVersion string `yaml:"rancher_version"`
ForcePrimeRegistry bool `yaml:"force_prime_registry"`
RancherAppsRepoOverride string `yaml:"rancher_apps_repo_override"`
RancherChartRepoOverride string `yaml:"rancher_chart_repo_override"`
RancherImageOverride string `yaml:"rancher_image_override"`
RancherImageTagOverride string `yaml:"rancher_image_tag_override"`