oc-deploy/src/install/uninstall.go

76 lines
1.7 KiB
Go
Raw Normal View History

2024-09-02 09:09:46 +02:00
package install
import (
2024-09-02 13:43:11 +02:00
"fmt"
"os"
"sync"
log "oc-deploy/log_wrapper"
"oc-deploy/versionOc"
"oc-deploy/tool"
"oc-deploy/chart"
"oc-deploy/helm"
2024-09-02 09:09:46 +02:00
)
2024-09-02 13:43:11 +02:00
func (this *InstallClass) NewUninstall() (string, error) {
dst := fmt.Sprintf("%s/oc.yml", this.Workspace)
if _, err := os.Stat(dst); err != nil {
return dst, err
}
version, err := versionOc.GetFromFile(dst)
if err != nil {
return "", err
}
this.Version = version
// Lecture du fichier de conf
2024-09-03 15:18:20 +02:00
this.tools, err = tool.FromConfigFile(dst)
if err != nil {
return dst, err
}
this.charts, _ = chart.FromConfigFile(dst)
if err != nil {
return dst, err
}
2024-09-02 13:43:11 +02:00
return dst, nil
2024-09-02 09:09:46 +02:00
}
2024-09-02 13:43:11 +02:00
func (this *InstallClass) UninstallCharts() (error) {
helm_bin, _ := this.getToolBin("helm")
kubectl_bin, _ := this.getToolBin("kubectl")
2024-09-02 09:09:46 +02:00
2024-09-02 13:43:11 +02:00
var wg sync.WaitGroup
for _, v := range this.charts {
for _, v1 := range v.Charts {
wg.Add(1)
go func() {
defer wg.Done()
this.uninstallChart(helm_bin, kubectl_bin, v1)
} ()
}
}
wg.Wait()
return nil
2024-09-02 09:09:46 +02:00
}
2024-09-02 13:43:11 +02:00
func (this *InstallClass) uninstallChart(helm_bin string, kubectl_bin string, chart chart.ChartData) {
log.Log().Info().Msg(fmt.Sprintf(" << Chart : %s ", chart.Name))
helmchart := helm.HelmChart{Bin: helm_bin,
Name: chart.Name}
res, err := helmchart.Uninstall()
if err != nil {
log.Log().Error().Msg(fmt.Sprintf(" >> %s %s (%s)", helmchart.Name, "KO", err))
return
}
log.Log().Info().Msg(fmt.Sprintf(" >> %s (%s)", helmchart.Name, res))
2024-09-03 15:18:20 +02:00
}