Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #32: Not printing proper error message if no .kube/config file or KUBECONFIG env variable found with kubectl auto #34

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions internal/ikubernetes/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package ikubernetes
import (
"context"
"errors"
"log"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -37,12 +36,12 @@ func GetK8sVersion() (*string, error) {

clientset, err := kubernetes.NewForConfig(kubeconfig)
if err != nil {
log.Fatalf("Error setting up K8s client")
return nil, err
}

k8sVersion, err := clientset.ServerVersion()
if err != nil {
log.Fatalf("Error getting K8s server version: %v", err)
return nil, err
}

k8sSemversion := k8sVersion.String()
Expand Down Expand Up @@ -72,15 +71,15 @@ func GetVeleroVersion() (*string, error) {

clientset, err := kubernetes.NewForConfig(kubeconfig)
if err != nil {
log.Fatalf("Error setting up K8s client")
return nil, err
}

namespace := "velero"
deploymentName := "velero"

deployment, err := clientset.AppsV1().Deployments(namespace).Get(context.TODO(), deploymentName, metav1.GetOptions{})
if err != nil {
return nil, errors.New("Error retrieving velero deployment from velero namespace")
return nil, errors.New("error retrieving velero deployment from velero namespace")
}

veleroImageName := deployment.Spec.Template.Spec.Containers[0].Image
Expand All @@ -90,7 +89,7 @@ func GetVeleroVersion() (*string, error) {
semVersionRegex := regexp.MustCompile(`^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z-.]+))?(?:\+([0-9A-Za-z-.]+))?$`)

if !semVersionRegex.MatchString(veleroVersion) {
return nil, errors.New("Velero image used in velero deployment is not semantic version: " + veleroVersion)
return nil, errors.New("velero image used in velero deployment is not semantic version: " + veleroVersion)
}

return &veleroVersion, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func InstallKubectl(version string, overwrite bool, timeout int, proxy string) e
fmt.Println("Fetching Kubernetes server version")
k8sVersion, err := ikubernetes.GetK8sVersion()
if err != nil {
fmt.Println("Error getting Kubernetes server version")
fmt.Println("Error getting Kubernetes server version. Error:", err.Error())
return err
}
version = *k8sVersion
Expand Down
2 changes: 1 addition & 1 deletion internal/use/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func UseVersion(toolname, version string) error {
fmt.Println("Fetching Kubernetes server version")
k8sVersion, err := ikubernetes.GetK8sVersion()
if err != nil {
fmt.Println("Error getting Kubernetes server version")
fmt.Println("Error getting Kubernetes server version. Error:", err.Error())
return err
}
version = *k8sVersion
Expand Down
Loading