oc-deploy/src/helm/repo.go

54 lines
1.2 KiB
Go
Raw Normal View History

2024-09-02 13:44:44 +02:00
package helm
import (
2024-09-05 09:26:32 +02:00
"fmt"
"strings"
"os/exec"
2024-09-02 13:44:44 +02:00
log "oc-deploy/log_wrapper"
)
type HelmRepo struct {
2024-09-05 09:26:32 +02:00
Bin string // Chemin vers le binaire
2024-09-02 13:44:44 +02:00
Name string
2024-09-05 09:26:32 +02:00
Repository string // Url du dépôt
ForceUpdate bool
Opts string
2024-09-02 13:44:44 +02:00
}
func (this HelmRepo) AddRepository() (string, error) {
2024-09-05 09:26:32 +02:00
helm_bin := this.Bin
2024-09-02 13:44:44 +02:00
2024-09-05 09:26:32 +02:00
force_update := "--force-update=false"
if this.ForceUpdate {
force_update = "--force-update=true"
}
2024-09-02 13:44:44 +02:00
2024-09-05 09:26:32 +02:00
msg := fmt.Sprintf("%s repo add %s %s %s %s", helm_bin, this.Name, this.Repository, force_update, this.Opts)
log.Log().Debug().Msg(msg)
2024-09-02 13:44:44 +02:00
2024-09-05 09:26:32 +02:00
cmd := exec.Command(helm_bin, "repo", "add", this.Name, this.Repository, force_update)
stdout, err := cmd.CombinedOutput()
2024-09-02 13:44:44 +02:00
2024-09-05 09:26:32 +02:00
res := string(stdout)
res = strings.TrimSuffix(res, "\n")
2024-09-02 13:44:44 +02:00
2024-09-05 09:26:32 +02:00
return res, err
2024-09-02 13:44:44 +02:00
}
// helm repo remove [NAME]
func (this HelmRepo) RemoveRepository() (string, error) {
2024-09-05 09:26:32 +02:00
helm_bin := this.Bin
2024-09-02 13:44:44 +02:00
2024-09-05 09:26:32 +02:00
msg := fmt.Sprintf("%s repo remove %s", helm_bin, this.Name)
log.Log().Debug().Msg(msg)
2024-09-02 13:44:44 +02:00
2024-09-05 09:26:32 +02:00
cmd := exec.Command(helm_bin, "repo", "remove", this.Name)
stdout, err := cmd.CombinedOutput()
2024-09-02 13:44:44 +02:00
2024-09-05 09:26:32 +02:00
res := string(stdout)
res = strings.TrimSuffix(res, "\n")
2024-09-02 13:44:44 +02:00
2024-09-05 09:26:32 +02:00
return res, err
2024-09-02 13:44:44 +02:00
}