Ressources

This commit is contained in:
admju
2024-09-06 14:08:05 +00:00
parent 052e6f1368
commit da9aab90eb
8 changed files with 907 additions and 8 deletions

View File

@@ -13,6 +13,7 @@ import (
type KubeObject struct {
Bin string // Chemin vers le binaire
Name string
Kind string
}
type getOutput struct {
@@ -26,6 +27,12 @@ type getStatusOutput struct {
}
func (this KubeObject) Get() (map[string]any, error) {
if this.Kind == "Deployment" {return this.getDeployment()}
if this.Kind == "StatefulSet" {return this.getStatefulSet()}
return make(map[string]any), fmt.Errorf("Kind %s inconnu", this.Kind)
}
func (this KubeObject) getDeployment() (map[string]any, error) {
bin := this.Bin
name := this.Name
@@ -57,6 +64,38 @@ func (this KubeObject) Get() (map[string]any, error) {
return m, nil
}
func (this KubeObject) getStatefulSet() (map[string]any, error) {
bin := this.Bin
name := this.Name
msg := fmt.Sprintf("%s get statefulset %s -o json", bin, name)
log.Log().Debug().Msg(msg)
m := make(map[string]any)
cmd_args := strings.Split(msg, " ")
cmd := exec.Command(cmd_args[0], cmd_args[1:]...)
stdout, err := cmd.CombinedOutput()
if err != nil {
return m, errors.New(string(stdout))
}
var objmap getOutput
json.Unmarshal(stdout, &objmap)
kind := objmap.Kind
status := objmap.Status
m["name"] = name
m["kind"] = kind
m["replicas"] = status.Replicas
m["UnavailableReplicas"] = status.UnavailableReplicas
return m, nil
}
func (this KubeObject) Wait() (error) {
boucle := 10
@@ -75,6 +114,7 @@ func (this KubeObject) Wait() (error) {
return nil
}
log.Log().Info().Msg(fmt.Sprintf(" >> %s (Unavailable : %d)...", this.Name, ko))
time.Sleep(sleep)
}