2024-09-09 14:17:02 +00:00
|
|
|
package kubectl
|
|
|
|
|
|
|
|
|
|
import (
|
2024-09-10 13:05:48 +00:00
|
|
|
"fmt"
|
|
|
|
|
"time"
|
|
|
|
|
"errors"
|
2024-09-09 14:17:02 +00:00
|
|
|
|
|
|
|
|
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 {
|
2024-09-10 13:05:48 +00:00
|
|
|
Replicas int `json:"replicas"`
|
|
|
|
|
UnavailableReplicas int `json:"unavailableReplicas"`
|
2024-09-09 14:17:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this KubectlCommand) Get(data KubectlObject) (map[string]any, error) {
|
2024-09-10 13:05:48 +00:00
|
|
|
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)
|
2024-09-09 14:17:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this KubectlCommand) Wait(data KubectlObject) (error) {
|
|
|
|
|
|
|
|
|
|
boucle := 10
|
|
|
|
|
sleep := 10000 * time.Millisecond
|
|
|
|
|
|
2024-09-10 13:05:48 +00:00
|
|
|
for _ = range boucle {
|
2024-09-09 14:17:02 +00:00
|
|
|
|
2024-09-10 13:05:48 +00:00
|
|
|
log.Log().Debug().Msg(fmt.Sprintf("Check Deployement %s", data.Name))
|
2024-09-09 14:17:02 +00:00
|
|
|
|
2024-09-10 13:05:48 +00:00
|
|
|
m, err := this.Get(data)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
ko := m["UnavailableReplicas"].(int)
|
|
|
|
|
if ko == 0 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2024-09-09 14:17:02 +00:00
|
|
|
|
2024-09-10 13:05:48 +00:00
|
|
|
log.Log().Info().Msg(fmt.Sprintf(" >> %s (Unavailable : %d)...", data.Name, ko))
|
|
|
|
|
time.Sleep(sleep)
|
2024-09-09 14:17:02 +00:00
|
|
|
|
2024-09-10 13:05:48 +00:00
|
|
|
}
|
|
|
|
|
return errors.New("Temps d'attente dépassé")
|
2024-09-02 07:09:46 +00:00
|
|
|
}
|