diff --git a/cmd/kubernetes_version.go b/cmd/kubernetes_version.go index de5cb9e..3f3f7e9 100644 --- a/cmd/kubernetes_version.go +++ b/cmd/kubernetes_version.go @@ -33,24 +33,28 @@ func (k *KubeVersion) BaseVersion() string { } func getKubeVersionFromRESTAPI() (*KubeVersion, error) { + glog.V(2).Info("Try to get version from Rest API") k8sVersionURL := getKubernetesURL() serviceaccount := "/var/run/secrets/kubernetes.io/serviceaccount" cacertfile := fmt.Sprintf("%s/ca.crt", serviceaccount) tokenfile := fmt.Sprintf("%s/token", serviceaccount) - tlsCert, err := loadCertficate(cacertfile) + tlsCert, err := loadCertificate(cacertfile) if err != nil { + glog.V(2).Infof("Failed loading certificate Error: %s", err) return nil, err } tb, err := ioutil.ReadFile(tokenfile) if err != nil { + glog.V(2).Infof("Failed reading token file Error: %s", err) return nil, err } token := strings.TrimSpace(string(tb)) data, err := getWebDataWithRetry(k8sVersionURL, token, tlsCert) if err != nil { + glog.V(2).Infof("Failed to get data Error: %s", err) return nil, err } @@ -143,7 +147,7 @@ func getWebData(srvURL, token string, cacert *tls.Certificate) ([]byte, error) { return ioutil.ReadAll(resp.Body) } -func loadCertficate(certFile string) (*tls.Certificate, error) { +func loadCertificate(certFile string) (*tls.Certificate, error) { cacert, err := ioutil.ReadFile(certFile) if err != nil { return nil, err diff --git a/cmd/kubernetes_version_test.go b/cmd/kubernetes_version_test.go index 66d9b0a..b06f79f 100644 --- a/cmd/kubernetes_version_test.go +++ b/cmd/kubernetes_version_test.go @@ -11,8 +11,8 @@ import ( "testing" ) -func TestLoadCertficate(t *testing.T) { - tmp, err := ioutil.TempDir("", "TestFakeLoadCertficate") +func TestLoadCertificate(t *testing.T) { + tmp, err := ioutil.TempDir("", "TestFakeLoadCertificate") if err != nil { t.Fatalf("unable to create temp directory: %v", err) } @@ -58,7 +58,7 @@ FAjB57z2NcIgJuVpQnGRYtr/JcH2Qdsq8bLtXaojUIWOOqoTDRLYozdMOOQ= for id, c := range cases { t.Run(strconv.Itoa(id), func(t *testing.T) { - tlsCert, err := loadCertficate(c.file) + tlsCert, err := loadCertificate(c.file) if !c.fail { if err != nil { t.Errorf("unexpected error: %v", err) diff --git a/cmd/util.go b/cmd/util.go index 91476d9..d2a1baf 100644 --- a/cmd/util.go +++ b/cmd/util.go @@ -291,12 +291,15 @@ func getKubeVersion() (*KubeVersion, error) { _, err := exec.LookPath("kubectl") if err != nil { + glog.V(3).Infof("Error locating kubectl: %s", err) _, err = exec.LookPath("kubelet") if err != nil { + glog.V(3).Infof("Error locating kubelet: %s", err) // Search for the kubelet binary all over the filesystem and run the first match to get the kubernetes version cmd := exec.Command("/bin/sh", "-c", "`find / -type f -executable -name kubelet 2>/dev/null | grep -m1 .` --version") out, err := cmd.CombinedOutput() if err == nil { + glog.V(3).Infof("Found kubelet and query kubernetes version is: %s", string(out)) return getVersionFromKubeletOutput(string(out)), nil } @@ -313,6 +316,7 @@ func getKubeVersionFromKubectl() *KubeVersion { cmd := exec.Command("kubectl", "version", "-o", "json") out, err := cmd.CombinedOutput() if err != nil { + glog.V(2).Infof("Failed to query kubectl: %s", err) glog.V(2).Info(err) } @@ -324,6 +328,7 @@ func getKubeVersionFromKubelet() *KubeVersion { out, err := cmd.CombinedOutput() if err != nil { + glog.V(2).Infof("Failed to query kubelet: %s", err) glog.V(2).Info(err) } @@ -331,7 +336,7 @@ func getKubeVersionFromKubelet() *KubeVersion { } func getVersionFromKubectlOutput(s string) *KubeVersion { - glog.V(2).Info(s) + glog.V(2).Infof("Kubectl output: %s", s) type versionResult struct { ServerVersion VersionResponse } @@ -354,7 +359,7 @@ func getVersionFromKubectlOutput(s string) *KubeVersion { } func getVersionFromKubeletOutput(s string) *KubeVersion { - glog.V(2).Info(s) + glog.V(2).Infof("Kubelet output: %s", s) serverVersionRe := regexp.MustCompile(`Kubernetes v(\d+.\d+)`) subs := serverVersionRe.FindStringSubmatch(s) if len(subs) < 2 {