Opts pour helm repo
This commit is contained in:
200
src/helm/repo.go
200
src/helm/repo.go
@@ -1,98 +1,102 @@
|
||||
package helm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"encoding/json"
|
||||
|
||||
log "oc-deploy/log_wrapper"
|
||||
"oc-deploy/utils"
|
||||
)
|
||||
|
||||
type HelmRepo struct {
|
||||
Name string
|
||||
Repository string // Url du dépôt
|
||||
ForceUpdate bool
|
||||
Opts string
|
||||
}
|
||||
|
||||
func (this HelmCommand) AddRepository(repo HelmRepo) (string, error) {
|
||||
|
||||
helm_bin := this.Bin
|
||||
|
||||
force_update := "--force-update=false"
|
||||
if repo.ForceUpdate {
|
||||
force_update = "--force-update=true"
|
||||
} else {
|
||||
list, _ := this.ListRepository()
|
||||
if utils.StringInSlice(repo.Name, list) {
|
||||
return "Existe déjà", nil
|
||||
}
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf("%s repo add %s %s %s %s", helm_bin, repo.Name, repo.Repository, force_update, repo.Opts)
|
||||
log.Log().Debug().Msg(msg)
|
||||
|
||||
msg = strings.TrimSuffix(msg, " ")
|
||||
|
||||
cmd_args := strings.Split(msg, " ")
|
||||
cmd := this.Exec(cmd_args[0], cmd_args[1:]...)
|
||||
stdout, err := cmd.CombinedOutput()
|
||||
|
||||
res := string(stdout)
|
||||
res = strings.TrimSuffix(res, "\n")
|
||||
|
||||
return res, err
|
||||
}
|
||||
|
||||
type parseList struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func (this HelmCommand) ListRepository() ([]string, error) {
|
||||
|
||||
helm_bin := this.Bin
|
||||
res := make([]string, 0, 0)
|
||||
|
||||
msg := fmt.Sprintf("%s repo list -o json", helm_bin)
|
||||
log.Log().Debug().Msg(msg)
|
||||
|
||||
cmd_args := strings.Split(msg, " ")
|
||||
|
||||
cmd := this.Exec(cmd_args[0], cmd_args[1:]...)
|
||||
stdout, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
var objmap []parseList
|
||||
|
||||
err = json.Unmarshal(stdout, &objmap)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
for _, ele := range objmap {
|
||||
res = append(res, ele.Name)
|
||||
}
|
||||
|
||||
return res, err
|
||||
}
|
||||
|
||||
// helm repo remove [NAME]
|
||||
func (this HelmCommand) RemoveRepository(repo HelmRepo) (string, error) {
|
||||
helm_bin := this.Bin
|
||||
|
||||
msg := fmt.Sprintf("%s repo remove %s", helm_bin, repo.Name)
|
||||
log.Log().Debug().Msg(msg)
|
||||
|
||||
cmd_args := strings.Split(msg, " ")
|
||||
|
||||
cmd := this.Exec(cmd_args[0], cmd_args[1:]...)
|
||||
stdout, err := cmd.CombinedOutput()
|
||||
|
||||
res := string(stdout)
|
||||
res = strings.TrimSuffix(res, "\n")
|
||||
|
||||
return res, err
|
||||
}
|
||||
package helm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"encoding/json"
|
||||
|
||||
log "oc-deploy/log_wrapper"
|
||||
"oc-deploy/utils"
|
||||
)
|
||||
|
||||
type HelmRepo struct {
|
||||
Name string
|
||||
Repository string // Url du dépôt
|
||||
ForceUpdate bool
|
||||
Opts string
|
||||
}
|
||||
|
||||
func (this HelmCommand) AddRepository(repo HelmRepo) (string, error) {
|
||||
|
||||
helm_bin := this.Bin
|
||||
|
||||
force_update := "--force-update=false"
|
||||
if repo.ForceUpdate {
|
||||
force_update = "--force-update=true"
|
||||
} else {
|
||||
list, _ := this.ListRepository()
|
||||
if utils.StringInSlice(repo.Name, list) {
|
||||
return "Existe déjà", nil
|
||||
}
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf("%s repo add %s %s %s %s", helm_bin, repo.Name, repo.Repository, force_update, repo.Opts)
|
||||
|
||||
msg = strings.TrimSuffix(msg, " ")
|
||||
log.Log().Debug().Msg(msg)
|
||||
|
||||
cmd_args := strings.Split(msg, " ")
|
||||
cmd := this.Exec(cmd_args[0], cmd_args[1:]...)
|
||||
stdout, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf(string(stdout))
|
||||
}
|
||||
|
||||
res := string(stdout)
|
||||
res = strings.TrimSuffix(res, "\n")
|
||||
log.Log().Debug().Msg(res)
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
type parseList struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func (this HelmCommand) ListRepository() ([]string, error) {
|
||||
|
||||
helm_bin := this.Bin
|
||||
res := make([]string, 0, 0)
|
||||
|
||||
msg := fmt.Sprintf("%s repo list -o json", helm_bin)
|
||||
log.Log().Debug().Msg(msg)
|
||||
|
||||
cmd_args := strings.Split(msg, " ")
|
||||
|
||||
cmd := this.Exec(cmd_args[0], cmd_args[1:]...)
|
||||
stdout, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
var objmap []parseList
|
||||
|
||||
err = json.Unmarshal(stdout, &objmap)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
for _, ele := range objmap {
|
||||
res = append(res, ele.Name)
|
||||
}
|
||||
|
||||
return res, err
|
||||
}
|
||||
|
||||
// helm repo remove [NAME]
|
||||
func (this HelmCommand) RemoveRepository(repo HelmRepo) (string, error) {
|
||||
helm_bin := this.Bin
|
||||
|
||||
msg := fmt.Sprintf("%s repo remove %s", helm_bin, repo.Name)
|
||||
log.Log().Debug().Msg(msg)
|
||||
|
||||
cmd_args := strings.Split(msg, " ")
|
||||
|
||||
cmd := this.Exec(cmd_args[0], cmd_args[1:]...)
|
||||
stdout, err := cmd.CombinedOutput()
|
||||
|
||||
res := string(stdout)
|
||||
res = strings.TrimSuffix(res, "\n")
|
||||
|
||||
return res, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user