oc-deploy/src/kubectl/deployment.go

41 lines
819 B
Go
Raw Normal View History

2024-09-09 16:17:02 +02:00
package kubectl
import (
"fmt"
"strings"
"errors"
"encoding/json"
log "oc-deploy/log_wrapper"
)
func (this KubectlCommand) getDeployment(data KubectlObject) (map[string]any, error) {
bin := this.Bin
msg := fmt.Sprintf("%s get deployment %s -o json", bin, data.Name)
log.Log().Debug().Msg(msg)
m := make(map[string]any)
cmd_args := strings.Split(msg, " ")
cmd := this.Exec(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"] = data.Name
m["kind"] = kind
m["replicas"] = status.Replicas
m["UnavailableReplicas"] = status.UnavailableReplicas
return m, nil
}