Files
oc-deploy/src/kubectl/object.go

56 lines
1.2 KiB
Go
Raw Normal View History

2024-09-09 14:17:02 +00:00
package kubectl
import (
"fmt"
"time"
"errors"
log "oc-deploy/log_wrapper"
)
type KubectlObject struct {
Name string
Kind string
}
type getOutput struct {
Kind string `json:"kind"`
Status getStatusOutput `json:"status"`
}
type getStatusOutput struct {
Replicas int `json:"replicas"`
UnavailableReplicas int `json:"unavailableReplicas"`
}
func (this KubectlCommand) Get(data KubectlObject) (map[string]any, error) {
if data.Kind == "Deployment" {return this.getDeployment(data)}
if data.Kind == "StatefulSet" {return this.getStatefulSet(data)}
return make(map[string]any), fmt.Errorf("Kind %s inconnu", data.Kind)
}
func (this KubectlCommand) Wait(data KubectlObject) (error) {
boucle := 10
sleep := 10000 * time.Millisecond
for _ = range boucle {
log.Log().Debug().Msg(fmt.Sprintf("Check Deployement %s", data.Name))
m, err := this.Get(data)
if err != nil {
return err
}
ko := m["UnavailableReplicas"].(int)
if ko == 0 {
return nil
}
log.Log().Info().Msg(fmt.Sprintf(" >> %s (Unavailable : %d)...", data.Name, ko))
time.Sleep(sleep)
}
return errors.New("Temps d'attente dépassé")
2024-09-02 07:09:46 +00:00
}