Skip to content

Commit

Permalink
cli: encode error along with message for additional context (openserv…
Browse files Browse the repository at this point in the history
…icemesh#1905)

Encodes the actual error when a command fails due to kubeconfig
issues or the cluster not being accessible. Without this, it is
difficult to understand the actual cause of the error.
  • Loading branch information
shashankram authored and draychev committed Oct 28, 2020
1 parent c7dd56d commit 464f4f3
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions cmd/cli/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ func newInstallCmd(config *helm.Configuration, out io.Writer) *cobra.Command {
RunE: func(_ *cobra.Command, args []string) error {
kubeconfig, err := settings.RESTClientGetter().ToRESTConfig()
if err != nil {
return errors.Errorf("Error fetching kubeconfig")
return errors.Errorf("Error fetching kubeconfig: %s", err)
}

clientset, err := kubernetes.NewForConfig(kubeconfig)
if err != nil {
return errors.Errorf("Could not access Kubernetes cluster. Check kubeconfig, %s", err)
return errors.Errorf("Could not access Kubernetes cluster, check kubeconfig: %s", err)
}
inst.clientSet = clientset
return inst.run(config)
Expand Down
4 changes: 2 additions & 2 deletions cmd/cli/mesh_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ func newMeshList(out io.Writer) *cobra.Command {
RunE: func(_ *cobra.Command, args []string) error {
config, err := settings.RESTClientGetter().ToRESTConfig()
if err != nil {
return errors.Errorf("Error fetching kubeconfig")
return errors.Errorf("Error fetching kubeconfig: %s", err)
}
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
return errors.Errorf("Could not access Kubernetes cluster. Check kubeconfig")
return errors.Errorf("Could not access Kubernetes cluster, check kubeconfig: %s", err)
}
meshList.clientSet = clientset
return meshList.run()
Expand Down
4 changes: 2 additions & 2 deletions cmd/cli/metrics_disable.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ func newMetricsDisable(out io.Writer) *cobra.Command {
RunE: func(_ *cobra.Command, args []string) error {
config, err := settings.RESTClientGetter().ToRESTConfig()
if err != nil {
return errors.Errorf("Error fetching kubeconfig")
return errors.Errorf("Error fetching kubeconfig: %s", err)
}

clientset, err := kubernetes.NewForConfig(config)
if err != nil {
return errors.Errorf("Could not access Kubernetes cluster. Check kubeconfig")
return errors.Errorf("Could not access Kubernetes cluster, check kubeconfig: %s", err)
}
disableCmd.clientSet = clientset
return disableCmd.run()
Expand Down
4 changes: 2 additions & 2 deletions cmd/cli/metrics_enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ func newMetricsEnable(out io.Writer) *cobra.Command {
RunE: func(_ *cobra.Command, args []string) error {
config, err := settings.RESTClientGetter().ToRESTConfig()
if err != nil {
return errors.Errorf("Error fetching kubeconfig")
return errors.Errorf("Error fetching kubeconfig: %s", err)
}

clientset, err := kubernetes.NewForConfig(config)
if err != nil {
return errors.Errorf("Could not access Kubernetes cluster. Check kubeconfig")
return errors.Errorf("Could not access Kubernetes cluster, check kubeconfig: %s", err)
}
enableCmd.clientSet = clientset
return enableCmd.run()
Expand Down
4 changes: 2 additions & 2 deletions cmd/cli/namespace_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ func newNamespaceAdd(out io.Writer) *cobra.Command {
namespaceAdd.namespaces = args
config, err := settings.RESTClientGetter().ToRESTConfig()
if err != nil {
return errors.Errorf("Error fetching kubeconfig")
return errors.Errorf("Error fetching kubeconfig: %s", err)
}

clientset, err := kubernetes.NewForConfig(config)
if err != nil {
return errors.Errorf("Could not access Kubernetes cluster. Check kubeconfig")
return errors.Errorf("Could not access Kubernetes cluster, check kubeconfig: %s", err)
}
namespaceAdd.clientSet = clientset
return namespaceAdd.run()
Expand Down
4 changes: 2 additions & 2 deletions cmd/cli/namespace_ignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ func newNamespaceIgnore(out io.Writer) *cobra.Command {
ignoreCmd.namespaces = args
config, err := settings.RESTClientGetter().ToRESTConfig()
if err != nil {
return errors.Errorf("Error fetching kubeconfig")
return errors.Errorf("Error fetching kubeconfig: %s", err)
}

clientset, err := kubernetes.NewForConfig(config)
if err != nil {
return errors.Errorf("Could not access Kubernetes cluster. Check kubeconfig")
return errors.Errorf("Could not access Kubernetes cluster, check kubeconfig: %s", err)
}
ignoreCmd.clientSet = clientset
return ignoreCmd.run()
Expand Down
4 changes: 2 additions & 2 deletions cmd/cli/namespace_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ func newNamespaceList(out io.Writer) *cobra.Command {

config, err := settings.RESTClientGetter().ToRESTConfig()
if err != nil {
return errors.Errorf("Error fetching kubeconfig")
return errors.Errorf("Error fetching kubeconfig: %s", err)
}

clientset, err := kubernetes.NewForConfig(config)
if err != nil {
return errors.Errorf("Could not access Kubernetes cluster. Check kubeconfig")
return errors.Errorf("Could not access Kubernetes cluster, check kubeconfig: %s", err)
}
namespaceList.clientSet = clientset
return namespaceList.run()
Expand Down
4 changes: 2 additions & 2 deletions cmd/cli/namespace_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ func newNamespaceRemove(out io.Writer) *cobra.Command {
namespaceRemove.namespace = args[0]
config, err := settings.RESTClientGetter().ToRESTConfig()
if err != nil {
return errors.Errorf("Error fetching kubeconfig")
return errors.Errorf("Error fetching kubeconfig: %s", err)
}

clientset, err := kubernetes.NewForConfig(config)
if err != nil {
return errors.Errorf("Could not access Kubernetes cluster. Check kubeconfig")
return errors.Errorf("Could not access Kubernetes cluster, check kubeconfig: %s", err)
}
namespaceRemove.clientSet = clientset
return namespaceRemove.run()
Expand Down
4 changes: 2 additions & 2 deletions cmd/cli/proxy_configdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ func newProxyDumpConfig(config *action.Configuration, out io.Writer) *cobra.Comm
dumpConfigCmd.pod = args[0]
conf, err := config.RESTClientGetter.ToRESTConfig()
if err != nil {
return errors.Errorf("Error fetching kubeconfig")
return errors.Errorf("Error fetching kubeconfig: %s", err)
}
dumpConfigCmd.config = conf

clientset, err := kubernetes.NewForConfig(conf)
if err != nil {
return errors.Errorf("Could not access Kubernetes cluster. Check kubeconfig")
return errors.Errorf("Could not access Kubernetes cluster, check kubeconfig: %s", err)
}
dumpConfigCmd.clientSet = clientset
return dumpConfigCmd.run()
Expand Down

0 comments on commit 464f4f3

Please sign in to comment.