Compare commits
3 Commits
c7f8503fb6
...
c1134f7403
Author | SHA1 | Date | |
---|---|---|---|
|
c1134f7403 | ||
|
9561dc5493 | ||
|
279f93224f |
@ -12,8 +12,10 @@ 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"`
|
||||
|
||||
Overwrite string `yaml:"helm_overwrite"`
|
||||
}
|
||||
|
||||
type repoData struct {
|
||||
@ -33,6 +35,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 {
|
||||
|
@ -1,7 +1,5 @@
|
||||
package chart
|
||||
|
||||
// https://pkg.go.dev/github.com/stretchr/testify/assert
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"path/filepath"
|
||||
@ -9,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
|
||||
func TestReadConfChart(t *testing.T){
|
||||
func _TestReadConfChart(t *testing.T) {
|
||||
src := filepath.Join(TEST_SRC_DIR, "oc.yml")
|
||||
|
||||
assert.FileExists(t, src, "FromConfigFile error")
|
||||
@ -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")
|
||||
@ -35,5 +37,14 @@ func TestReadConfChart(t *testing.T){
|
||||
myfirstrelease := data1.Charts[0]
|
||||
assert.Equal(t, "myfirstrelease", myfirstrelease.Name, "FromConfigFile error")
|
||||
assert.Equal(t, "https://zzzz/myfirstchart-0.1.0.tgz", myfirstrelease.Url, "FromConfigFile error")
|
||||
|
||||
}
|
||||
|
||||
func TestReadConfChartOverwrite(t *testing.T){
|
||||
src := filepath.Join(TEST_SRC_DIR, "oc_overwrite.yml")
|
||||
|
||||
assert.FileExists(t, src, "FromConfigFile error")
|
||||
|
||||
data, _ := FromConfigFile(src)
|
||||
// Nombre de lettres
|
||||
assert.Equal(t, 70, len(data[0].Charts[0].Overwrite), "TestReadConfChartOverwrite error")
|
||||
}
|
@ -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
|
||||
}
|
@ -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
|
||||
}
|
@ -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,19 @@ 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)
|
||||
}
|
||||
|
||||
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 {
|
||||
log.Log().Warn().Msg(fic)
|
||||
} else {
|
||||
|
@ -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
36
src/install/generate.go
Normal 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
|
||||
}
|
@ -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
|
||||
}
|
||||
|
||||
@ -92,8 +55,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
|
||||
|
||||
@ -126,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))
|
||||
|
@ -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)
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
13
test/chart/oc_overwrite.yml
Normal file
13
test/chart/oc_overwrite.yml
Normal file
@ -0,0 +1,13 @@
|
||||
---
|
||||
|
||||
opencloud:
|
||||
- charts:
|
||||
- name: mongo
|
||||
chart: bitnami/wordpress
|
||||
version: 23.1.0
|
||||
helm_overwrite: |
|
||||
---
|
||||
# Texte Mot de passe
|
||||
# mongo:
|
||||
# name: <user>
|
||||
# password: <_mdp>
|
Loading…
Reference in New Issue
Block a user