values overwrite

This commit is contained in:
admju 2024-09-11 13:40:40 +00:00
parent 9561dc5493
commit c1134f7403
7 changed files with 100 additions and 79 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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 {

View File

@ -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
}

36
src/install/generate.go Normal file
View File

@ -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
}

View File

@ -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))

View File

@ -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)
}