test
This commit is contained in:
@@ -1,159 +1,162 @@
|
||||
package helm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"errors"
|
||||
"path/filepath"
|
||||
"encoding/json"
|
||||
log "oc-deploy/log_wrapper"
|
||||
)
|
||||
|
||||
type HelmChart struct {
|
||||
Bin string
|
||||
Name string
|
||||
Chart string
|
||||
Version string
|
||||
Url string
|
||||
|
||||
Workspace string
|
||||
Opts string
|
||||
Values string
|
||||
FileValues string
|
||||
}
|
||||
|
||||
type installInfoOutput struct {
|
||||
Description string `json:"description"`
|
||||
Notes string `json:"notes"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
type installOutput struct {
|
||||
Info installInfoOutput `json:"info"`
|
||||
}
|
||||
|
||||
func (this HelmChart) Install() (string, error) {
|
||||
bin := this.Bin
|
||||
|
||||
existe, err := this.exists()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if existe {
|
||||
return "Existe déjà", nil
|
||||
}
|
||||
|
||||
ficChart := this.Chart
|
||||
// Recherche locale
|
||||
if _, err := os.Stat(ficChart); err != nil {
|
||||
} else {
|
||||
// Recherche voa le Workspace
|
||||
ficChart := filepath.Join(this.Workspace, this.Chart)
|
||||
if _, err := os.Stat(ficChart); err == nil {
|
||||
} else {
|
||||
if this.Url != "" {
|
||||
fmt.Println("============ 52 Télechargement", this.Url)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf("%s install %s %s %s --output json", bin, this.Name, ficChart, this.Opts)
|
||||
|
||||
if this.Version != "" {
|
||||
msg = fmt.Sprintf("%s --version %s", msg, this.Version)
|
||||
}
|
||||
|
||||
if this.FileValues != "" {
|
||||
fic := filepath.Join(this.Workspace, this.FileValues)
|
||||
if _, err := os.Stat(fic); err != nil {
|
||||
log.Log().Warn().Msg(fic)
|
||||
} else {
|
||||
msg = fmt.Sprintf("%s --values %s", msg, fic)
|
||||
}
|
||||
}
|
||||
|
||||
msg = strings.Replace(msg, " ", " ", -1)
|
||||
|
||||
log.Log().Debug().Msg(msg)
|
||||
|
||||
cmd_args := strings.Split(msg, " ")
|
||||
|
||||
cmd := exec.Command(cmd_args[0], cmd_args[1:]...)
|
||||
stdout, err := cmd.CombinedOutput()
|
||||
|
||||
if err != nil {
|
||||
res := string(stdout)
|
||||
res = strings.TrimSuffix(res, "\n")
|
||||
return "", errors.New(res)
|
||||
}
|
||||
|
||||
var objmap installOutput
|
||||
|
||||
err = json.Unmarshal(stdout, &objmap)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
res := objmap.Info.Status
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (this HelmChart) Uninstall() (string, error) {
|
||||
bin := this.Bin
|
||||
|
||||
log.Log().Info().Msg(" >> Chart : " + this.Name)
|
||||
|
||||
existe, err := this.exists()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if ! existe {
|
||||
return "Non présent", nil
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf("%s uninstall %s", bin, this.Name)
|
||||
log.Log().Debug().Msg(msg)
|
||||
|
||||
cmd := exec.Command(bin, "uninstall", this.Name)
|
||||
stdout, err := cmd.CombinedOutput()
|
||||
|
||||
return string(stdout), err
|
||||
}
|
||||
|
||||
// ../bin/helm list --filter phpmyadminm --short
|
||||
func (this HelmChart) exists() (bool, error) {
|
||||
bin := this.Bin
|
||||
|
||||
msg := fmt.Sprintf("%s list --filter %s --no-headers", bin, this.Name)
|
||||
log.Log().Debug().Msg(msg)
|
||||
|
||||
cmd_args := strings.Split(msg, " ")
|
||||
|
||||
cmd := exec.Command(cmd_args[0], cmd_args[1:]...)
|
||||
stdout, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
log.Log().Debug().Msg(string(stdout))
|
||||
return false, errors.New(string(stdout))
|
||||
}
|
||||
|
||||
res := string(stdout)
|
||||
res = strings.TrimSuffix(res, "\n")
|
||||
|
||||
log.Log().Debug().Msg(string(stdout))
|
||||
log.Log().Debug().Msg(strconv.FormatBool(res != ""))
|
||||
|
||||
return res != "", nil
|
||||
}
|
||||
|
||||
func (this HelmChart) GetRessources() (map[string]string, error) {
|
||||
hs := HelmStatus{Name: this.Name}
|
||||
hs.New(this.Bin)
|
||||
data, _ := hs.getRessources()
|
||||
|
||||
return data, nil
|
||||
}
|
||||
package helm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"os"
|
||||
"strings"
|
||||
"errors"
|
||||
"path/filepath"
|
||||
"encoding/json"
|
||||
log "oc-deploy/log_wrapper"
|
||||
)
|
||||
|
||||
type HelmChart struct {
|
||||
Bin string
|
||||
Name string
|
||||
Chart string
|
||||
Version string
|
||||
Url string
|
||||
|
||||
Workspace string
|
||||
Opts string
|
||||
Values string
|
||||
FileValues string
|
||||
}
|
||||
|
||||
type installInfoOutput struct {
|
||||
Description string `json:"description"`
|
||||
Notes string `json:"notes"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
type installOutput struct {
|
||||
Info installInfoOutput `json:"info"`
|
||||
}
|
||||
|
||||
func (this HelmCommand) ChartInstall(data HelmChart) (string, error) {
|
||||
bin := this.Bin
|
||||
|
||||
existe, err := this.chartExists(data)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if existe {
|
||||
return "Existe déjà", nil
|
||||
}
|
||||
|
||||
ficChart := data.Chart
|
||||
// Recherche locale
|
||||
if _, err := os.Stat(ficChart); err != nil {
|
||||
} else {
|
||||
// Recherche voa le Workspace
|
||||
ficChart := filepath.Join(data.Workspace, data.Chart)
|
||||
if _, err := os.Stat(ficChart); err == nil {
|
||||
} else {
|
||||
if data.Url != "" {
|
||||
fmt.Println("============ 52 Télechargement", data.Url)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf("%s install %s %s %s --output json", bin, data.Name, ficChart, data.Opts)
|
||||
|
||||
if data.Version != "" {
|
||||
msg = fmt.Sprintf("%s --version %s", msg, data.Version)
|
||||
}
|
||||
|
||||
if data.FileValues != "" {
|
||||
fic := filepath.Join(data.Workspace, data.FileValues)
|
||||
if _, err := os.Stat(fic); err != nil {
|
||||
log.Log().Warn().Msg(fic)
|
||||
} else {
|
||||
msg = fmt.Sprintf("%s --values %s", msg, fic)
|
||||
}
|
||||
}
|
||||
|
||||
msg = strings.Replace(msg, " ", " ", -1)
|
||||
|
||||
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 {
|
||||
res := string(stdout)
|
||||
res = strings.TrimSuffix(res, "\n")
|
||||
return "", errors.New(res)
|
||||
}
|
||||
|
||||
var objmap installOutput
|
||||
|
||||
err = json.Unmarshal(stdout, &objmap)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
res := objmap.Info.Status
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (this HelmCommand) ChartUninstall(data HelmChart) (string, error) {
|
||||
bin := this.Bin
|
||||
|
||||
log.Log().Info().Msg(" >> Chart : " + data.Name)
|
||||
|
||||
existe, err := this.chartExists(data)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if ! existe {
|
||||
return "Non présent", nil
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf("%s uninstall %s", bin, data.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")
|
||||
|
||||
log.Log().Debug().Msg(res)
|
||||
|
||||
return res, err
|
||||
}
|
||||
|
||||
// ../bin/helm list --filter phpmyadminm --short
|
||||
func (this HelmCommand) chartExists(data HelmChart) (bool, error) {
|
||||
bin := this.Bin
|
||||
|
||||
msg := fmt.Sprintf("%s list --filter %s --no-headers", bin, data.Name)
|
||||
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 {
|
||||
log.Log().Debug().Msg(string(stdout))
|
||||
return false, errors.New(string(stdout))
|
||||
}
|
||||
|
||||
res := string(stdout)
|
||||
res = strings.TrimSuffix(res, "\n")
|
||||
|
||||
log.Log().Debug().Msg(string(stdout))
|
||||
log.Log().Debug().Msg(strconv.FormatBool(res != ""))
|
||||
|
||||
return res != "", nil
|
||||
}
|
||||
|
||||
// func (this HelmChart) GetRessources() (map[string]string, error) {
|
||||
// hs := HelmStatus{Name: this.Name}
|
||||
// hs.New(this.Bin)
|
||||
// data, _ := hs.getRessources()
|
||||
|
||||
// return data, nil
|
||||
// }
|
||||
Reference in New Issue
Block a user