/
validation.go
37 lines (29 loc) · 908 Bytes
/
validation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package pkg
import (
"errors"
"fmt"
"os/exec"
"strings"
)
const (
docLink = "https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/" +
"#append-home-kube-config-to-your-kubeconfig-environment-variable"
)
func (drift *Drift) ValidatePrerequisite() bool {
success := true
if len(strings.Split(drift.kubeConfig, ":")) > 1 {
drift.log.Info("since drift uses kubectl underneath with arg '--kubeconfig' " +
"drift cannot run with multiple kubeconfig files set under environment var 'KUBECONFIG', " +
"like mentioned in below document")
fmt.Printf("%s\n", docLink)
success = false
}
if goPath := exec.Command("kubectl"); goPath.Err != nil {
if !errors.Is(goPath.Err, exec.ErrDot) {
drift.log.Infof("%v", goPath.Err.Error())
drift.log.Info("helm-drift requires 'kubectl' to identify drifts")
success = false
}
}
return success
}