fix(1488): suppress gRPC logs and errors

If gRPC fails to make a connection, the result is a log message and a
verbose error. This suppresses log output and replaces the error with a
much more succinct one.

Closes #1488
parent 846011b0
...@@ -20,11 +20,14 @@ import ( ...@@ -20,11 +20,14 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"log"
"os" "os"
"strings" "strings"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/grpclog"
"k8s.io/kubernetes/pkg/client/restclient" "k8s.io/kubernetes/pkg/client/restclient"
"k8s.io/kubernetes/pkg/client/unversioned" "k8s.io/kubernetes/pkg/client/unversioned"
...@@ -90,6 +93,9 @@ func newRootCmd(out io.Writer) *cobra.Command { ...@@ -90,6 +93,9 @@ func newRootCmd(out io.Writer) *cobra.Command {
p.StringVar(&kubeContext, "kube-context", "", "name of the kubeconfig context to use") p.StringVar(&kubeContext, "kube-context", "", "name of the kubeconfig context to use")
p.BoolVarP(&flagDebug, "debug", "", false, "enable verbose output") p.BoolVarP(&flagDebug, "debug", "", false, "enable verbose output")
// Tell gRPC not to log to console.
grpclog.SetLogger(log.New(ioutil.Discard, "", log.LstdFlags))
rup := newRepoUpdateCmd(out) rup := newRepoUpdateCmd(out)
rup.Deprecated = "use 'helm repo update'\n" rup.Deprecated = "use 'helm repo update'\n"
......
...@@ -20,6 +20,7 @@ import ( ...@@ -20,6 +20,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"os"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"google.golang.org/grpc" "google.golang.org/grpc"
...@@ -101,7 +102,10 @@ func (v *versionCmd) run() error { ...@@ -101,7 +102,10 @@ func (v *versionCmd) run() error {
if grpc.Code(err) == codes.Unimplemented { if grpc.Code(err) == codes.Unimplemented {
return errors.New("server is too old to know its version") return errors.New("server is too old to know its version")
} }
return err if flagDebug {
fmt.Fprintln(os.Stderr, err)
}
return errors.New("cannot connect to Tiller")
} }
fmt.Fprintf(v.out, "Server: %#v\n", resp.Version) fmt.Fprintf(v.out, "Server: %#v\n", resp.Version)
return nil return nil
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment