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
pull/1490/head
Matt Butcher 8 years ago
parent 846011b02a
commit 32354be03b
No known key found for this signature in database
GPG Key ID: DCD5F5E5EF32C345

@ -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 {
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 (
"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 {
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

Loading…
Cancel
Save