Add ssh tools to requirements check

pull/1/head
stefanprodan 5 years ago
parent 35163fa9eb
commit bba9ac0aa1

@ -39,8 +39,11 @@ jobs:
run: sudo go build -o ./bin/tk ./cmd/tk run: sudo go build -o ./bin/tk ./cmd/tk
- name: Run integration tests - name: Run integration tests
run: | run: |
./bin/tk check
./bin/tk install --manifests ./manifests/install/ ./bin/tk install --manifests ./manifests/install/
- name: Debug failure - name: Debug failure
if: failure() if: failure()
run: | run: |
kubectl version --client --short
kustomize version --short
kubectl -n gitops-system get all kubectl -n gitops-system get all

@ -4,14 +4,15 @@ import (
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
"strings"
"github.com/blang/semver" "github.com/blang/semver"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var checkCmd = &cobra.Command{ var checkCmd = &cobra.Command{
Use: "check --pre", Use: "check",
Short: "Check for potential problems", Short: "Check requirements",
Long: ` Long: `
The check command will perform a series of checks to validate that The check command will perform a series of checks to validate that
the local environment is configured correctly.`, the local environment is configured correctly.`,
@ -31,6 +32,10 @@ func init() {
} }
func runCheckCmd(cmd *cobra.Command, args []string) error { func runCheckCmd(cmd *cobra.Command, args []string) error {
if !sshCheck() {
os.Exit(1)
}
if !kubectlCheck(">=1.14.0") { if !kubectlCheck(">=1.14.0") {
os.Exit(1) os.Exit(1)
} }
@ -52,9 +57,9 @@ func runCheckCmd(cmd *cobra.Command, args []string) error {
return nil return nil
} }
func checkLocal() bool { func sshCheck() bool {
ok := true ok := true
for _, cmd := range []string{"kubectl", "kustomize"} { for _, cmd := range []string{"ssh-keygen", "ssh-keyscan"} {
_, err := exec.LookPath(cmd) _, err := exec.LookPath(cmd)
if err != nil { if err != nil {
fmt.Println(``, cmd, "not found") fmt.Println(``, cmd, "not found")
@ -82,7 +87,7 @@ func kubectlCheck(version string) bool {
v, err := semver.ParseTolerant(output) v, err := semver.ParseTolerant(output)
if err != nil { if err != nil {
fmt.Println(``, "kubectl version can't be determined") fmt.Println(``, "kubectl version can't be parsed")
return false return false
} }
@ -109,11 +114,19 @@ func kustomizeCheck(version string) bool {
return false return false
} }
v, err := semver.ParseTolerant(output) if strings.Contains(output, "kustomize/") {
output, err = execCommand("kustomize version --short | awk '{ print $1 }' | cut -c12-")
if err != nil { if err != nil {
fmt.Println(``, "kustomize version can't be determined") fmt.Println(``, "kustomize version can't be determined")
return false return false
} }
}
v, err := semver.ParseTolerant(output)
if err != nil {
fmt.Println(``, "kustomize version can't be parsed")
return false
}
rng, _ := semver.ParseRange(version) rng, _ := semver.ParseRange(version)
if !rng(v) { if !rng(v) {

Loading…
Cancel
Save