Ressources
This commit is contained in:
29
src/kubectl/command.go
Normal file
29
src/kubectl/command.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package kubectl
|
||||
|
||||
// import (
|
||||
// "fmt"
|
||||
// )
|
||||
|
||||
// type KubectlCommandInterface interface {
|
||||
// // GetDeployment() (string, error)
|
||||
// GetDeployment() (string, error)
|
||||
// }
|
||||
|
||||
// type KubectlCommandData struct {
|
||||
// bin string
|
||||
// command string
|
||||
// }
|
||||
|
||||
// type Real KubectlCommandStatus KubectlCommandData
|
||||
|
||||
// // func (this KubectlCommandStatus) Status() (string, error) {
|
||||
// // fmt.Println("BIN ", this.bin)
|
||||
// // fmt.Println("COMMAND status")
|
||||
// // return "Res de KubectlCommandStatus", nil
|
||||
// // }
|
||||
|
||||
// func (this KubectlCommandStatus) GetDeployment() (string, error) {
|
||||
// fmt.Println("BIN ", this.bin)
|
||||
// fmt.Println("COMMAND status")
|
||||
// return "Res de GetDeployment", nil
|
||||
// }
|
@@ -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)
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user