Charts locaux
This commit is contained in:
parent
11a4d5cc90
commit
756638fe21
@ -8,17 +8,22 @@ import (
|
|||||||
type ChartData struct {
|
type ChartData struct {
|
||||||
Name string `yaml:"name"`
|
Name string `yaml:"name"`
|
||||||
Chart string `yaml:"chart"`
|
Chart string `yaml:"chart"`
|
||||||
|
Url string `yaml:"url"`
|
||||||
Version string `yaml:"version"`
|
Version string `yaml:"version"`
|
||||||
|
|
||||||
Opts string `yaml:"helm_opts"`
|
Opts string `yaml:"helm_opts"`
|
||||||
Values string `yaml:"helm_values"`
|
Values string `yaml:"helm_values"`
|
||||||
FileValues string `yaml:"helm_filevalues"`
|
FileValues string `yaml:"helm_filevalues"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type repoData struct {
|
||||||
|
Name string `yaml:"name"`
|
||||||
|
Url string `yaml:"url"`
|
||||||
|
ForceUpdate bool `yaml:"forceupdate"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChartRepoData struct {
|
type ChartRepoData struct {
|
||||||
Name string `yaml:"name"`
|
Repository repoData `yaml:"repository"`
|
||||||
Repository string `yaml:"repository"`
|
|
||||||
Charts []ChartData `yaml:"charts"`
|
Charts []ChartData `yaml:"charts"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,16 +15,25 @@ func TestReadConfChart(t *testing.T){
|
|||||||
assert.FileExists(t, src, "FromConfigFile error")
|
assert.FileExists(t, src, "FromConfigFile error")
|
||||||
|
|
||||||
data, _ := FromConfigFile(src)
|
data, _ := FromConfigFile(src)
|
||||||
assert.Equal(t, data[0].Name, "bitnami", "FromConfigFile error")
|
assert.Equal(t, "bitnami", data[0].Repository.Name, "FromConfigFile error")
|
||||||
assert.Equal(t, data[0].Repository, "https://charts.bitnami.com/bitnami", "FromConfigFile error")
|
assert.Equal(t, "https://charts.bitnami.com/bitnami", data[0].Repository.Url, "FromConfigFile error")
|
||||||
|
|
||||||
wordpress := data[0].Charts[0]
|
wordpress := data[0].Charts[0]
|
||||||
assert.Equal(t, wordpress.Name, "wordpress", "FromConfigFile error")
|
assert.Equal(t, "wordpress", wordpress.Name, "FromConfigFile error")
|
||||||
assert.Equal(t, wordpress.Chart, "bitnami/wordpress", "FromConfigFile error")
|
assert.Equal(t, "bitnami/wordpress", wordpress.Chart, "FromConfigFile error")
|
||||||
assert.Equal(t, wordpress.Version, "23.1.0", "FromConfigFile error")
|
assert.Equal(t, "23.1.0", wordpress.Version, "FromConfigFile error")
|
||||||
|
|
||||||
phpmyadmin := data[0].Charts[1]
|
phpmyadmin := data[0].Charts[1]
|
||||||
assert.Equal(t, phpmyadmin.Name, "phpmyadmin", "FromConfigFile error")
|
assert.Equal(t, "phpmyadmin", phpmyadmin.Name, "FromConfigFile error")
|
||||||
assert.Equal(t, phpmyadmin.Chart, "bitnami/phpmyadmin", "FromConfigFile error")
|
assert.Equal(t, "bitnami/phpmyadmin", phpmyadmin.Chart,"FromConfigFile error")
|
||||||
assert.Equal(t, phpmyadmin.Version, "17.0.4", "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")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
log "oc-deploy/log_wrapper"
|
log "oc-deploy/log_wrapper"
|
||||||
@ -13,6 +14,7 @@ import (
|
|||||||
var (
|
var (
|
||||||
context string
|
context string
|
||||||
version string
|
version string
|
||||||
|
modules []string
|
||||||
)
|
)
|
||||||
|
|
||||||
func Execute() {
|
func Execute() {
|
||||||
@ -27,7 +29,7 @@ func Execute() {
|
|||||||
Long: `deploy Charts`,
|
Long: `deploy Charts`,
|
||||||
Args: cobra.MaximumNArgs(0),
|
Args: cobra.MaximumNArgs(0),
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
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",
|
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(&context, "context", "p", "opencloud", "Nom du projet")
|
||||||
cmdInstall.Flags().StringVarP(&version, "version", "v", "latest", "Version")
|
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")
|
cmdUninstall.Flags().StringVarP(&context, "context", "p", "opencloud", "Nom du projet")
|
||||||
|
|
||||||
|
@ -7,10 +7,13 @@ import (
|
|||||||
"oc-deploy/install"
|
"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("Install >> ")
|
||||||
|
|
||||||
log.Log().Info().Msg(" << Contexte : " + context)
|
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)
|
workspace := fmt.Sprintf("workspace_%s", context)
|
||||||
obj := install.InstallClass{Workspace: workspace, Version: version}
|
obj := install.InstallClass{Workspace: workspace, Version: version}
|
||||||
|
@ -16,6 +16,8 @@ type HelmChart struct {
|
|||||||
Name string
|
Name string
|
||||||
Chart string
|
Chart string
|
||||||
Version string
|
Version string
|
||||||
|
Url string
|
||||||
|
|
||||||
Workspace string
|
Workspace string
|
||||||
Opts string
|
Opts string
|
||||||
Values string
|
Values string
|
||||||
@ -39,12 +41,27 @@ func (this HelmChart) Install() (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
// existe := false
|
||||||
|
|
||||||
if existe {
|
if existe {
|
||||||
return "Existe déjà", nil
|
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 != "" {
|
if this.Version != "" {
|
||||||
msg = fmt.Sprintf("%s --version %s", msg, this.Version)
|
msg = fmt.Sprintf("%s --version %s", msg, this.Version)
|
||||||
|
@ -71,18 +71,19 @@ func (this *InstallClass) ChartRepo() (error) {
|
|||||||
bin_path, _ := this.getToolBin("helm")
|
bin_path, _ := this.getToolBin("helm")
|
||||||
|
|
||||||
for _, v := range this.charts {
|
for _, v := range this.charts {
|
||||||
log.Log().Info().Msg(fmt.Sprintf(" >> Helm Repo : %s", v.Name))
|
if v.Repository.Name != "" {
|
||||||
repo := helm.HelmRepo{Bin: bin_path,
|
log.Log().Info().Msg(fmt.Sprintf(" >> Helm Repo : %s", v.Repository.Name))
|
||||||
Name: v.Name,
|
repo := helm.HelmRepo{Bin: bin_path,
|
||||||
Repository: v.Repository,
|
Name: v.Repository.Name,
|
||||||
ForceUpdate: true}
|
Repository: v.Repository.Url,
|
||||||
res, err := repo.AddRepository()
|
ForceUpdate: v.Repository.ForceUpdate}
|
||||||
if err != nil {
|
res, err := repo.AddRepository()
|
||||||
log.Log().Info().Msg(fmt.Sprintf(" << %s ", err))
|
if err != nil {
|
||||||
return err
|
log.Log().Info().Msg(fmt.Sprintf(" << %s ", err))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Log().Info().Msg(fmt.Sprintf(" << %s ", res))
|
||||||
}
|
}
|
||||||
log.Log().Info().Msg(fmt.Sprintf(" << %s ", res))
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -116,6 +117,7 @@ func (this *InstallClass) installChart(helm_bin string, kubectl_bin string, char
|
|||||||
helmchart := helm.HelmChart{Bin: helm_bin,
|
helmchart := helm.HelmChart{Bin: helm_bin,
|
||||||
Name: chart.Name,
|
Name: chart.Name,
|
||||||
Chart: chart.Chart,
|
Chart: chart.Chart,
|
||||||
|
Url: chart.Url,
|
||||||
Version: chart.Version,
|
Version: chart.Version,
|
||||||
Workspace: this.Workspace,
|
Workspace: this.Workspace,
|
||||||
Opts: chart.Opts,
|
Opts: chart.Opts,
|
||||||
@ -127,7 +129,7 @@ func (this *InstallClass) installChart(helm_bin string, kubectl_bin string, char
|
|||||||
|
|
||||||
res, err := helmchart.Install()
|
res, err := helmchart.Install()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Log().Error().Msg(fmt.Sprintf(" >> %s %s (%s)", helmchart.Name, "KO", err))
|
log.Log().Error().Msg(fmt.Sprintf(" >> %s %s (%s)", helmchart.Name, "KO", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Log().Info().Msg(fmt.Sprintf(" >> %s (%s)", helmchart.Name, res))
|
log.Log().Info().Msg(fmt.Sprintf(" >> %s (%s)", helmchart.Name, res))
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
opencloud:
|
opencloud:
|
||||||
- name: bitnami
|
- repository:
|
||||||
repository: https://charts.bitnami.com/bitnami # Repository des Charts
|
name: bitnami
|
||||||
|
url: https://charts.bitnami.com/bitnami # Repository des Charts
|
||||||
charts:
|
charts:
|
||||||
- name: wordpress
|
- name: wordpress
|
||||||
chart: bitnami/wordpress
|
chart: bitnami/wordpress
|
||||||
@ -13,3 +14,8 @@ opencloud:
|
|||||||
chart: bitnami/phpmyadmin
|
chart: bitnami/phpmyadmin
|
||||||
version: 17.0.4
|
version: 17.0.4
|
||||||
values: {}
|
values: {}
|
||||||
|
|
||||||
|
- charts:
|
||||||
|
- name: myfirstrelease
|
||||||
|
chart: myfirstchart-0.1.0.tgz
|
||||||
|
url: https://zzzz/myfirstchart-0.1.0.tgz
|
||||||
|
Loading…
Reference in New Issue
Block a user