oc-deploy/src/kubectl/version.go

32 lines
566 B
Go
Raw Normal View History

2024-09-02 13:44:44 +02:00
package kubectl
import (
"os/exec"
"encoding/json"
)
type toolClientVersion struct {
2024-09-04 09:11:13 +02:00
GitVersion string `json:"gitVersion"`
2024-09-02 13:44:44 +02:00
}
type toolVersion struct {
2024-09-04 09:11:13 +02:00
ClientVersion toolClientVersion `json:"clientVersion"`
2024-09-02 13:44:44 +02:00
}
func Version(path string) (string, error) {
2024-09-04 09:11:13 +02:00
cmd := exec.Command(path, "version", "-o", "json", "--client=true")
stdout, err := cmd.CombinedOutput()
2024-09-02 13:44:44 +02:00
if err != nil {
return "", err
}
2024-09-04 09:11:13 +02:00
var objmap toolVersion
2024-09-02 13:44:44 +02:00
2024-09-04 09:11:13 +02:00
json.Unmarshal(stdout, &objmap)
2024-09-02 13:44:44 +02:00
res := objmap.ClientVersion.GitVersion
return res, nil
}