From c1134f7403bd8258f754a7d9bfec0597dbf69eee Mon Sep 17 00:00:00 2001 From: admju Date: Wed, 11 Sep 2024 13:40:40 +0000 Subject: [PATCH] values overwrite --- src/cmd/generateCmd.go | 19 ++++++--------- src/generate/generate.go | 22 ----------------- src/helm/chart.go | 7 ++++++ src/install/common.go | 45 +++++++++++++++++++++++++++++++++++ src/install/generate.go | 36 ++++++++++++++++++++++++++++ src/install/install.go | 46 ++++-------------------------------- src/versionOc/online_test.go | 4 +--- 7 files changed, 100 insertions(+), 79 deletions(-) delete mode 100644 src/generate/generate.go create mode 100644 src/install/generate.go diff --git a/src/cmd/generateCmd.go b/src/cmd/generateCmd.go index 5607b76..e2adee1 100644 --- a/src/cmd/generateCmd.go +++ b/src/cmd/generateCmd.go @@ -1,28 +1,23 @@ package cmd import ( - + "fmt" log "oc-deploy/log_wrapper" - "oc-deploy/versionOc" - "oc-deploy/generate" + // "oc-deploy/versionOc" + "oc-deploy/install" ) -func GenerateCmd(project string, version string) error { +func GenerateCmd(prcontextoject string, version string) error { log.Log().Info().Msg("Generate >> ") - version, err := versionOc.GetFromFile(version) - if err != nil { - log.Log().Fatal().Msg("OpenCloud >> " + err.Error()) - } - log.Log().Info().Msg(" >> Version : " + version) + workspace := fmt.Sprintf("workspace_%s", context) - obj := generate.GenerateClass{Workspace: "workspace_" + project, Version: version} - fic, err := obj.New() + obj := install.InstallClass{Workspace: workspace, Version: version} + _, err := obj.NewGenerate() if err != nil { log.Log().Fatal().Msg(" >> " + err.Error()) } - log.Log().Info().Msg(" >> Value : " + fic) return err } \ No newline at end of file diff --git a/src/generate/generate.go b/src/generate/generate.go deleted file mode 100644 index a1f6226..0000000 --- a/src/generate/generate.go +++ /dev/null @@ -1,22 +0,0 @@ -package generate - -import ( - "fmt" - "oc-deploy/utils" -) - -type GenerateClass struct { - Version string - Workspace string -} - -func (this GenerateClass) New() (string, error) { - src := fmt.Sprintf("../offline/default_value_%s.yml", this.Version) - dst := fmt.Sprintf("%s/default_value.yml", this.Workspace) - - err := utils.CopyFile(src, dst) - if err != nil { - return "", err - } - return src, nil -} diff --git a/src/helm/chart.go b/src/helm/chart.go index 28e25bd..e5c8021 100644 --- a/src/helm/chart.go +++ b/src/helm/chart.go @@ -70,6 +70,13 @@ func (this HelmCommand) ChartInstall(data HelmChart) (string, error) { msg = fmt.Sprintf("%s --set %s=%s", msg, key, value) } + ficoverwrite := filepath.Join(data.Workspace, fmt.Sprintf("value-%s.yml", data.Name)) + if _, err := os.Stat(ficoverwrite); err != nil { + log.Log().Warn().Msg(ficoverwrite) + } else { + msg = fmt.Sprintf("%s --values %s", msg, ficoverwrite) + } + for _, valuefilename := range data.FileValues { fic := filepath.Join(data.Workspace, valuefilename) if _, err := os.Stat(fic); err != nil { diff --git a/src/install/common.go b/src/install/common.go index 3d12684..0a63a6c 100644 --- a/src/install/common.go +++ b/src/install/common.go @@ -2,14 +2,30 @@ package install import ( "fmt" + "os" "errors" log "oc-deploy/log_wrapper" "oc-deploy/tool" + "oc-deploy/chart" "oc-deploy/kubectl" "oc-deploy/helm" + "oc-deploy/versionOc" + "oc-deploy/utils" ) +type InstallClass struct { + Version string + Workspace string + + tools []tool.ToolData + toolsBin map[string]string + charts []chart.ChartRepoData + + commandHelm helm.HelmCommand + commandKubectl kubectl.KubectlCommand +} + func (this *InstallClass) Tools() (error) { var mem []tool.ToolClass @@ -102,3 +118,32 @@ func (this *InstallClass) K8s(context string) (error) { return nil } + +func (this *InstallClass) extractVersion() (string, error) { + + // Extraction du fichier de version + dst := fmt.Sprintf("%s/oc.yml", this.Workspace) + log.Log().Debug().Msg(fmt.Sprintf("Check du fichier de version : %s", dst)) + if _, err := os.Stat(dst); err == nil { + log.Log().Debug().Msg("Existe déjà") + version, err := versionOc.GetFromFile(dst) + if err != nil { + return "", err + } + this.Version = version + } else { + log.Log().Debug().Msg("Téléchargement du fichier de version") + version, fileversion, err := versionOc.GetFromOnline(this.Version) + if err != nil { + return "", err + } + this.Version = version + + err = utils.CopyContentFile(fileversion, dst) + if err != nil { + return "", err + } + } + + return dst, nil +} \ No newline at end of file diff --git a/src/install/generate.go b/src/install/generate.go new file mode 100644 index 0000000..f206237 --- /dev/null +++ b/src/install/generate.go @@ -0,0 +1,36 @@ +package install + +import ( + "fmt" + "path/filepath" + + log "oc-deploy/log_wrapper" + "oc-deploy/utils" + "oc-deploy/chart" +) + +func (this *InstallClass) NewGenerate() (string, error) { + + // Extraction du fichier de la version + dst, err := this.extractVersion() + if err != nil { + return "", err + } + + this.charts, _ = chart.FromConfigFile(dst) + if err != nil { + return dst, err + } + + for _, ele1 := range this.charts { + for _, ele2 := range ele1.Charts { + + filename := filepath.Join(this.Workspace, fmt.Sprintf("values-%s.yml", ele2.Name) ) + utils.CopyContentFile(ele2.Overwrite, filename) + log.Log().Info().Msg(fmt.Sprintf(">> %s : %s", ele2.Name, filename)) + + } + } + + return dst, nil +} \ No newline at end of file diff --git a/src/install/install.go b/src/install/install.go index 01c07e9..c258575 100644 --- a/src/install/install.go +++ b/src/install/install.go @@ -3,7 +3,6 @@ package install import ( "fmt" "sync" - "os" log "oc-deploy/log_wrapper" "oc-deploy/utils" @@ -11,50 +10,17 @@ import ( "oc-deploy/chart" "oc-deploy/helm" "oc-deploy/kubectl" - "oc-deploy/versionOc" ) -type InstallClass struct { - Version string - Workspace string - - tools []tool.ToolData - toolsBin map[string]string - charts []chart.ChartRepoData - - commandHelm helm.HelmCommand - commandKubectl kubectl.KubectlCommand -} - func (this *InstallClass) NewInstall() (string, error) { - // Extraction du fichier de version - dst := fmt.Sprintf("%s/oc.yml", this.Workspace) - log.Log().Debug().Msg(fmt.Sprintf("Check du fichier de version : %s", dst)) - if _, err := os.Stat(dst); err == nil { - log.Log().Debug().Msg("Existe déjà") - version, err := versionOc.GetFromFile(dst) - if err != nil { - return "", err - } - this.Version = version - } else { - log.Log().Debug().Msg("Téléchargement du fichier de version") - // version, fileversion, err := versionOc.Get(this.Version) - version, fileversion, err := versionOc.GetFromOnline(this.Version) - if err != nil { - return "", err - } - this.Version = version - - err = utils.CopyContentFile(fileversion, dst) - if err != nil { - return "", err - } + // Extraction du fichier de la version + dst, err := this.extractVersion() + if err != nil { + return "", err } // Lecture du fichier de conf - var err error this.tools, err = tool.FromConfigFile(dst) if err != nil { return dst, err @@ -64,9 +30,6 @@ func (this *InstallClass) NewInstall() (string, error) { return dst, err } - bin_path, _ := this.getToolBin("helm") - fmt.Println("Install 67 bin_path", bin_path) - return dst, nil } @@ -124,7 +87,6 @@ func (this *InstallClass) installChart(chart chart.ChartData) { Values: chart.Values, FileValues: chart.FileValues} - res, err := this.commandHelm.ChartInstall(data) if err != nil { log.Log().Error().Msg(fmt.Sprintf(" >> %s %s (%s)", data.Name, "KO", err)) diff --git a/src/versionOc/online_test.go b/src/versionOc/online_test.go index f919fca..b7458a8 100644 --- a/src/versionOc/online_test.go +++ b/src/versionOc/online_test.go @@ -3,7 +3,6 @@ package versionOc import ( "fmt" "testing" - // "encoding/base64" "oc-deploy/occonst" @@ -57,6 +56,5 @@ func TestGetOnlineLatest(t *testing.T) { version, _, err := GetFromOnline("latest") assert.Nilf(t, err, "error message %s", err) assert.Equal(t, "99.0", version, "TestGetFromFile error") - fmt.Println("TestGetOnlineLatest ", version, err) -} \ No newline at end of file +}