This commit is contained in:
admju 2024-09-03 13:18:20 +00:00
parent 26404e5892
commit 11a4d5cc90
12 changed files with 121 additions and 96 deletions

View File

@ -26,9 +26,12 @@ type chartsRepoData struct {
Charts []ChartRepoData `yaml:"opencloud"`
}
func FromConfigFile(filename string) ([]ChartRepoData) {
func FromConfigFile(filename string) ([]ChartRepoData, error) {
yamlFile, _ := os.ReadFile(filename)
var data chartsRepoData
yaml.Unmarshal(yamlFile, &data)
return data.Charts
err := yaml.Unmarshal(yamlFile, &data)
if err != nil {
return data.Charts, err
}
return data.Charts, nil
}

View File

@ -14,7 +14,7 @@ func TestReadConfChart(t *testing.T){
assert.FileExists(t, src, "FromConfigFile error")
data := FromConfigFile(src)
data, _ := FromConfigFile(src)
assert.Equal(t, data[0].Name, "bitnami", "FromConfigFile error")
assert.Equal(t, data[0].Repository, "https://charts.bitnami.com/bitnami", "FromConfigFile error")

View File

@ -8,7 +8,6 @@ import (
type GenerateClass struct {
Version string
Workspace string
url string
}
func (this GenerateClass) New() (string, error) {

View File

@ -76,7 +76,10 @@ func (this HelmChart) Install() (string, error) {
var objmap installOutput
json.Unmarshal(stdout, &objmap)
err = json.Unmarshal(stdout, &objmap)
if err != nil {
return "", err
}
res := objmap.Info.Status

View File

@ -52,8 +52,15 @@ func (this *InstallClass) NewInstall() (string, error) {
// Lecture du fichier de conf
// this.versionFile = dst
this.tools = tool.FromConfigFile(dst)
this.charts = chart.FromConfigFile(dst)
var err error
this.tools, err = tool.FromConfigFile(dst)
if err != nil {
return dst, err
}
this.charts, _ = chart.FromConfigFile(dst)
if err != nil {
return dst, err
}
return dst, nil
}

View File

@ -27,8 +27,14 @@ func (this *InstallClass) NewUninstall() (string, error) {
this.Version = version
// Lecture du fichier de conf
this.tools = tool.FromConfigFile(dst)
this.charts = chart.FromConfigFile(dst)
this.tools, err = tool.FromConfigFile(dst)
if err != nil {
return dst, err
}
this.charts, _ = chart.FromConfigFile(dst)
if err != nil {
return dst, err
}
return dst, nil
}

View File

@ -60,7 +60,10 @@ func (this KubeContext) GetContext() (string, string, string, error) {
var objmap kubeConfig
json.Unmarshal(stdout, &objmap)
err := json.Unmarshal(stdout, &objmap)
if err != nil {
return "", "", "", err
}
currentContext := objmap.CurrentContext
currentCluster := ""

View File

@ -9,9 +9,12 @@ type toolsData struct {
Tools []ToolData `yaml:"tools"`
}
func FromConfigFile(filename string) ([]ToolData) {
func FromConfigFile(filename string) ([]ToolData, error) {
yamlFile, _ := os.ReadFile(filename)
var data toolsData
yaml.Unmarshal(yamlFile, &data)
return data.Tools
err := yaml.Unmarshal(yamlFile, &data)
if err != nil {
return data.Tools, nil
}
return data.Tools, nil
}

View File

@ -36,14 +36,16 @@ func (this HelmInstallData) Download() (error) {
r, _ := os.Open(tmp_file)
err1 := utils.ExtractTarGz(bin_dir, r)
if err1 != nil {return err1}
os.Remove(tmp_file)
bin_file := fmt.Sprintf("%s/%s", bin_dir, this.obj.Name)
os.Chmod(bin_file, 0755)
errChmod := os.Chmod(bin_file, 0755)
if errChmod != nil {return errChmod}
return err1
return nil
}
///////////////

View File

@ -4,7 +4,6 @@ import (
"fmt"
"os"
"os/exec"
"errors"
"path/filepath"
)
@ -73,7 +72,7 @@ func factory(data ToolData) (Forme, error) {
case "helm":
f = HelmInstallData{obj: data, tmp: "/tmp"}
default:
return f, errors.New(fmt.Sprintf("Outil Inconnu : %s", data.Name))
return f, fmt.Errorf("Outil Inconnu : %s", data.Name)
}
return f, nil

View File

@ -43,7 +43,7 @@ func ExtractTarGz(dest string, gzipStream io.Reader) error {
tarReader := tar.NewReader(uncompressedStream)
for true {
for {
header, err := tarReader.Next()
if err == io.EOF {

View File

@ -5,7 +5,7 @@ import (
"fmt"
"os"
"errors"
"io/ioutil"
"io"
"gopkg.in/yaml.v2"
log "oc-deploy/log_wrapper"
)
@ -21,7 +21,7 @@ func GetFromFile(fileversion string) (string, error) {
}
defer fin.Close()
byteValue, err := ioutil.ReadAll(fin)
byteValue, err := io.ReadAll(fin)
if err != nil {
return "", err
}
@ -64,7 +64,7 @@ func readLatestFile() (string, error) {
}
defer fin.Close()
byteValue, err := ioutil.ReadAll(fin)
byteValue, err := io.ReadAll(fin)
if err != nil {
return "", err
}