From 9e267becca358da69f6f11dea3cba3b64e001f79 Mon Sep 17 00:00:00 2001 From: admju Date: Tue, 3 Sep 2024 15:26:10 +0000 Subject: [PATCH] Selection des charts --- src/cmd/args.go | 5 ++--- src/cmd/installCmd.go | 4 ++-- src/install/install.go | 25 ++++++++++++++++++------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/cmd/args.go b/src/cmd/args.go index 0c00bc3..bacbd48 100644 --- a/src/cmd/args.go +++ b/src/cmd/args.go @@ -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") diff --git a/src/cmd/installCmd.go b/src/cmd/installCmd.go index 9910fab..72e0e87 100644 --- a/src/cmd/installCmd.go +++ b/src/cmd/installCmd.go @@ -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()) } diff --git a/src/install/install.go b/src/install/install.go index 90904b2..36a4310 100644 --- a/src/install/install.go +++ b/src/install/install.go @@ -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))