Selection des charts

This commit is contained in:
admju 2024-09-03 15:26:10 +00:00
parent 756638fe21
commit 9e267becca
3 changed files with 22 additions and 12 deletions

View File

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

View File

@ -12,7 +12,7 @@ func InstallCmd(context string, version string, modules []string) {
log.Log().Info().Msg(" << Contexte : " + context)
if len(modules) > 0 {
log.Log().Info().Msg(fmt.Sprintf(" << Modules : |%s| %d", modules, len(modules)))
log.Log().Info().Msg(fmt.Sprintf(" << Modules : %s", modules))
}
workspace := fmt.Sprintf("workspace_%s", context)
@ -40,7 +40,7 @@ func InstallCmd(context string, version string, modules []string) {
log.Log().Fatal().Msg(" >> " + err.Error())
}
err = obj.InstallCharts()
err = obj.InstallCharts(modules)
if err != nil {
log.Log().Fatal().Msg(" >> " + err.Error())
}

View File

@ -89,7 +89,7 @@ func (this *InstallClass) ChartRepo() (error) {
}
func (this *InstallClass) InstallCharts() (error) {
func (this *InstallClass) InstallCharts(modules []string) (error) {
helm_bin, _ := this.getToolBin("helm")
kubectl_bin, _ := this.getToolBin("kubectl")
@ -97,19 +97,30 @@ func (this *InstallClass) InstallCharts() (error) {
for _, v := range this.charts {
for _, v1 := range v.Charts {
wg.Add(1)
if len(modules) == 0 || stringInSlice(v1.Name, modules) {
wg.Add(1)
go func() {
defer wg.Done()
this.installChart(helm_bin, kubectl_bin, v1)
} ()
go func() {
defer wg.Done()
this.installChart(helm_bin, kubectl_bin, v1)
} ()
}
}
}
wg.Wait()
return nil
}
func stringInSlice(a string, list []string) bool {
for _, b := range list {
if b == a {
return true
}
}
return false
}
func (this *InstallClass) installChart(helm_bin string, kubectl_bin string, chart chart.ChartData) {
log.Log().Info().Msg(fmt.Sprintf(" << Chart : %s ", chart.Name))