From 279f93224fa3a396f58f1ed78e6a1ae3aa320110 Mon Sep 17 00:00:00 2001 From: admju Date: Wed, 11 Sep 2024 13:13:28 +0000 Subject: [PATCH] helm : fichiers multiples + variable --- src/chart/conf.go | 5 +++-- src/chart/conf_test.go | 6 ++++-- src/helm/chart.go | 12 ++++++++---- src/install/install.go | 2 -- test/chart/oc.yml | 8 ++++++-- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/chart/conf.go b/src/chart/conf.go index f23bb83..3cea699 100644 --- a/src/chart/conf.go +++ b/src/chart/conf.go @@ -12,8 +12,8 @@ type ChartData struct { Version string `yaml:"version"` Opts string `yaml:"helm_opts"` - Values string `yaml:"helm_values"` - FileValues string `yaml:"helm_filevalues"` + Values map[string]string `yaml:"helm_values"` + FileValues []string `yaml:"helm_filevalues"` } type repoData struct { @@ -33,6 +33,7 @@ type chartsRepoData struct { func FromConfigFile(filename string) ([]ChartRepoData, error) { yamlFile, _ := os.ReadFile(filename) + var data chartsRepoData err := yaml.Unmarshal(yamlFile, &data) if err != nil { diff --git a/src/chart/conf_test.go b/src/chart/conf_test.go index 3f3273a..e8a64a4 100644 --- a/src/chart/conf_test.go +++ b/src/chart/conf_test.go @@ -1,7 +1,5 @@ package chart -// https://pkg.go.dev/github.com/stretchr/testify/assert - import ( "testing" "path/filepath" @@ -22,11 +20,15 @@ func TestReadConfChart(t *testing.T){ assert.Equal(t, "wordpress", wordpress.Name, "FromConfigFile error") assert.Equal(t, "bitnami/wordpress", wordpress.Chart, "FromConfigFile error") assert.Equal(t, "23.1.0", wordpress.Version, "FromConfigFile error") + assert.Equal(t, 0, len(wordpress.FileValues), "FromConfigFile error") + assert.Equal(t, 0, len(wordpress.Values), "FromConfigFile error") phpmyadmin := data[0].Charts[1] assert.Equal(t, "phpmyadmin", phpmyadmin.Name, "FromConfigFile error") assert.Equal(t, "bitnami/phpmyadmin", phpmyadmin.Chart,"FromConfigFile error") assert.Equal(t, "17.0.4", phpmyadmin.Version, "FromConfigFile error") + assert.Equal(t, 2, len(phpmyadmin.FileValues), "FromConfigFile error") + assert.Equal(t, 1, len(phpmyadmin.Values), "FromConfigFile error") data1 := data[1] assert.Equal(t, "", data1.Repository.Name, "FromConfigFile error") diff --git a/src/helm/chart.go b/src/helm/chart.go index 1c5545a..28e25bd 100644 --- a/src/helm/chart.go +++ b/src/helm/chart.go @@ -20,8 +20,8 @@ type HelmChart struct { Workspace string Opts string - Values string - FileValues string + Values map[string]string + FileValues []string } type installInfoOutput struct { @@ -66,8 +66,12 @@ func (this HelmCommand) ChartInstall(data HelmChart) (string, error) { msg = fmt.Sprintf("%s --version %s", msg, data.Version) } - if data.FileValues != "" { - fic := filepath.Join(data.Workspace, data.FileValues) + for key, value := range data.Values { + msg = fmt.Sprintf("%s --set %s=%s", msg, key, value) + } + + for _, valuefilename := range data.FileValues { + fic := filepath.Join(data.Workspace, valuefilename) if _, err := os.Stat(fic); err != nil { log.Log().Warn().Msg(fic) } else { diff --git a/src/install/install.go b/src/install/install.go index ce957ad..01c07e9 100644 --- a/src/install/install.go +++ b/src/install/install.go @@ -92,8 +92,6 @@ func (this *InstallClass) ChartRepo() (error) { func (this *InstallClass) InstallCharts(modules []string) (error) { - // helm_bin, _ := this.getToolBin("helm") - // kubectl_bin, _ := this.getToolBin("kubectl") var wg sync.WaitGroup diff --git a/test/chart/oc.yml b/test/chart/oc.yml index 1220faa..2afbe74 100644 --- a/test/chart/oc.yml +++ b/test/chart/oc.yml @@ -8,12 +8,16 @@ opencloud: - name: wordpress chart: bitnami/wordpress version: 23.1.0 - values: {} + helm_values: [] - name: phpmyadmin chart: bitnami/phpmyadmin version: 17.0.4 - values: {} + helm_values: + VAR1: aaa + helm_filevalues: + - values-global.yml + - values-phpmyadmin.yml - charts: - name: myfirstrelease