Charts locaux

This commit is contained in:
admju 2024-09-03 15:18:11 +00:00
parent 11a4d5cc90
commit 756638fe21
7 changed files with 72 additions and 27 deletions

View File

@ -8,17 +8,22 @@ import (
type ChartData struct {
Name string `yaml:"name"`
Chart string `yaml:"chart"`
Url string `yaml:"url"`
Version string `yaml:"version"`
Opts string `yaml:"helm_opts"`
Values string `yaml:"helm_values"`
FileValues string `yaml:"helm_filevalues"`
}
type repoData struct {
Name string `yaml:"name"`
Url string `yaml:"url"`
ForceUpdate bool `yaml:"forceupdate"`
}
type ChartRepoData struct {
Name string `yaml:"name"`
Repository string `yaml:"repository"`
Repository repoData `yaml:"repository"`
Charts []ChartData `yaml:"charts"`
}

View File

@ -15,16 +15,25 @@ func TestReadConfChart(t *testing.T){
assert.FileExists(t, src, "FromConfigFile error")
data, _ := FromConfigFile(src)
assert.Equal(t, data[0].Name, "bitnami", "FromConfigFile error")
assert.Equal(t, data[0].Repository, "https://charts.bitnami.com/bitnami", "FromConfigFile error")
assert.Equal(t, "bitnami", data[0].Repository.Name, "FromConfigFile error")
assert.Equal(t, "https://charts.bitnami.com/bitnami", data[0].Repository.Url, "FromConfigFile error")
wordpress := data[0].Charts[0]
assert.Equal(t, wordpress.Name, "wordpress", "FromConfigFile error")
assert.Equal(t, wordpress.Chart, "bitnami/wordpress", "FromConfigFile error")
assert.Equal(t, wordpress.Version, "23.1.0", "FromConfigFile error")
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")
phpmyadmin := data[0].Charts[1]
assert.Equal(t, phpmyadmin.Name, "phpmyadmin", "FromConfigFile error")
assert.Equal(t, phpmyadmin.Chart, "bitnami/phpmyadmin", "FromConfigFile error")
assert.Equal(t, phpmyadmin.Version, "17.0.4", "FromConfigFile error")
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")
data1 := data[1]
assert.Equal(t, "", data1.Repository.Name, "FromConfigFile error")
assert.Equal(t, "", data1.Repository.Url, "FromConfigFile error")
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")
}

View File

@ -5,6 +5,7 @@
package cmd
import (
"strings"
"github.com/spf13/cobra"
log "oc-deploy/log_wrapper"
@ -13,6 +14,7 @@ import (
var (
context string
version string
modules []string
)
func Execute() {
@ -27,7 +29,7 @@ func Execute() {
Long: `deploy Charts`,
Args: cobra.MaximumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
InstallCmd(context, version)
InstallCmd(context, version, strings.Split(modules, ","))
},
Example: "oc-deploy install --version 1.0 --context ex1",
}
@ -56,6 +58,7 @@ func Execute() {
cmdInstall.Flags().StringVarP(&context, "context", "p", "opencloud", "Nom du projet")
cmdInstall.Flags().StringVarP(&version, "version", "v", "latest", "Version")
cmdInstall.Flags().StringArrayVarP(&modules, "modules", "m", "", "modules, ...")
cmdUninstall.Flags().StringVarP(&context, "context", "p", "opencloud", "Nom du projet")

View File

@ -7,10 +7,13 @@ import (
"oc-deploy/install"
)
func InstallCmd(context string, version string) {
func InstallCmd(context string, version string, modules []string) {
log.Log().Info().Msg("Install >> ")
log.Log().Info().Msg(" << Contexte : " + context)
if len(modules) > 0 {
log.Log().Info().Msg(fmt.Sprintf(" << Modules : |%s| %d", modules, len(modules)))
}
workspace := fmt.Sprintf("workspace_%s", context)
obj := install.InstallClass{Workspace: workspace, Version: version}

View File

@ -16,6 +16,8 @@ type HelmChart struct {
Name string
Chart string
Version string
Url string
Workspace string
Opts string
Values string
@ -39,12 +41,27 @@ func (this HelmChart) Install() (string, error) {
if err != nil {
return "", err
}
// existe := false
if existe {
return "Existe déjà", nil
}
msg := fmt.Sprintf("%s install %s %s %s --output json", bin, this.Name, this.Chart, this.Opts)
ficChart := this.Chart
// Recherche locale
if _, err := os.Stat(ficChart); err != nil {
} else {
// Recherche voa le Workspace
ficChart := filepath.Join(this.Workspace, this.Chart)
if _, err := os.Stat(ficChart); err == nil {
} else {
if this.Url != "" {
fmt.Println("============ 52 Télechargement", this.Url)
}
}
}
msg := fmt.Sprintf("%s install %s %s %s --output json", bin, this.Name, ficChart, this.Opts)
if this.Version != "" {
msg = fmt.Sprintf("%s --version %s", msg, this.Version)

View File

@ -71,18 +71,19 @@ func (this *InstallClass) ChartRepo() (error) {
bin_path, _ := this.getToolBin("helm")
for _, v := range this.charts {
log.Log().Info().Msg(fmt.Sprintf(" >> Helm Repo : %s", v.Name))
if v.Repository.Name != "" {
log.Log().Info().Msg(fmt.Sprintf(" >> Helm Repo : %s", v.Repository.Name))
repo := helm.HelmRepo{Bin: bin_path,
Name: v.Name,
Repository: v.Repository,
ForceUpdate: true}
Name: v.Repository.Name,
Repository: v.Repository.Url,
ForceUpdate: v.Repository.ForceUpdate}
res, err := repo.AddRepository()
if err != nil {
log.Log().Info().Msg(fmt.Sprintf(" << %s ", err))
return err
}
log.Log().Info().Msg(fmt.Sprintf(" << %s ", res))
}
}
return nil
}
@ -116,6 +117,7 @@ func (this *InstallClass) installChart(helm_bin string, kubectl_bin string, char
helmchart := helm.HelmChart{Bin: helm_bin,
Name: chart.Name,
Chart: chart.Chart,
Url: chart.Url,
Version: chart.Version,
Workspace: this.Workspace,
Opts: chart.Opts,

View File

@ -1,8 +1,9 @@
---
opencloud:
- name: bitnami
repository: https://charts.bitnami.com/bitnami # Repository des Charts
- repository:
name: bitnami
url: https://charts.bitnami.com/bitnami # Repository des Charts
charts:
- name: wordpress
chart: bitnami/wordpress
@ -13,3 +14,8 @@ opencloud:
chart: bitnami/phpmyadmin
version: 17.0.4
values: {}
- charts:
- name: myfirstrelease
chart: myfirstchart-0.1.0.tgz
url: https://zzzz/myfirstchart-0.1.0.tgz