|
|
@ -18,13 +18,14 @@ package main
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"encoding/json"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/blang/semver/v4"
|
|
|
|
"github.com/blang/semver/v4"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
|
|
|
apimachineryversion "k8s.io/apimachinery/pkg/version"
|
|
|
|
"k8s.io/client-go/kubernetes"
|
|
|
|
"k8s.io/client-go/kubernetes"
|
|
|
|
"k8s.io/client-go/tools/clientcmd"
|
|
|
|
"k8s.io/client-go/tools/clientcmd"
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -48,6 +49,10 @@ var (
|
|
|
|
checkComponents []string
|
|
|
|
checkComponents []string
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type kubectlVersion struct {
|
|
|
|
|
|
|
|
ClientVersion *apimachineryversion.Info `json:"clientVersion"`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
func init() {
|
|
|
|
checkCmd.Flags().BoolVarP(&checkPre, "pre", "", false,
|
|
|
|
checkCmd.Flags().BoolVarP(&checkPre, "pre", "", false,
|
|
|
|
"only run pre-installation checks")
|
|
|
|
"only run pre-installation checks")
|
|
|
@ -97,14 +102,20 @@ func kubectlCheck(ctx context.Context, version string) bool {
|
|
|
|
return false
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
command := "kubectl version --client --short | awk '{ print $3 }'"
|
|
|
|
kubectlArgs := []string{"version", "--client", "--output", "json"}
|
|
|
|
output, err := utils.execCommand(ctx, ModeCapture, command)
|
|
|
|
output, err := utils.execKubectlCommand(ctx, ModeCapture, kubectlArgs...)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
logger.Failuref("kubectl version can't be determined")
|
|
|
|
logger.Failuref("kubectl version can't be determined")
|
|
|
|
return false
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
v, err := semver.ParseTolerant(output)
|
|
|
|
kv := &kubectlVersion{}
|
|
|
|
|
|
|
|
if err = json.Unmarshal([]byte(output), kv); err != nil {
|
|
|
|
|
|
|
|
logger.Failuref("kubectl version output can't be unmarshaled")
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v, err := semver.ParseTolerant(kv.ClientVersion.GitVersion)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
logger.Failuref("kubectl version can't be parsed")
|
|
|
|
logger.Failuref("kubectl version can't be parsed")
|
|
|
|
return false
|
|
|
|
return false
|
|
|
@ -161,9 +172,8 @@ func componentsCheck() bool {
|
|
|
|
|
|
|
|
|
|
|
|
ok := true
|
|
|
|
ok := true
|
|
|
|
for _, deployment := range checkComponents {
|
|
|
|
for _, deployment := range checkComponents {
|
|
|
|
command := fmt.Sprintf("kubectl -n %s rollout status deployment %s --timeout=%s",
|
|
|
|
kubectlArgs := []string{"-n", namespace, "rollout", "status", "deployment", deployment, "--timeout", timeout.String()}
|
|
|
|
namespace, deployment, timeout.String())
|
|
|
|
if output, err := utils.execKubectlCommand(ctx, ModeCapture, kubectlArgs...); err != nil {
|
|
|
|
if output, err := utils.execCommand(ctx, ModeCapture, command); err != nil {
|
|
|
|
|
|
|
|
logger.Failuref("%s: %s", deployment, strings.TrimSuffix(output, "\n"))
|
|
|
|
logger.Failuref("%s: %s", deployment, strings.TrimSuffix(output, "\n"))
|
|
|
|
ok = false
|
|
|
|
ok = false
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|