From 9bdb0cf6acadb0e07945242df815514a8ec54393 Mon Sep 17 00:00:00 2001 From: makhov Date: Sat, 17 Mar 2018 00:07:25 +0300 Subject: [PATCH 1/2] tiller grpc message size opt --- cmd/tiller/tiller.go | 22 ++++++++++++++++++++++ pkg/tiller/server.go | 8 ++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/cmd/tiller/tiller.go b/cmd/tiller/tiller.go index 5d2db3816..8e8c794d9 100644 --- a/cmd/tiller/tiller.go +++ b/cmd/tiller/tiller.go @@ -58,6 +58,8 @@ const ( tlsCertsEnvVar = "TILLER_TLS_CERTS" // historyMaxEnvVar is the name of the env var for setting max history. historyMaxEnvVar = "TILLER_HISTORY_MAX" + // maxMsgSizeEnvVar is the name of the env var for setting gRPC message size limit. + maxMsgSizeEnvVar = "TILLER_MAX_MSG_SIZE" storageMemory = "memory" storageConfigMap = "configmap" @@ -82,6 +84,7 @@ var ( caCertFile = flag.String("tls-ca-cert", tlsDefaultsFromEnv("tls-ca-cert"), "trust certificates signed by this CA") maxHistory = flag.Int("history-max", historyMaxFromEnv(), "maximum number of releases kept in release history, with 0 meaning no limit") printVersion = flag.Bool("version", false, "print the version number") + maxMsgSize = flag.Int("max-msg-size", maxMsgSizeFromEnv(), "gRPC message size limit") // rootServer is the root gRPC server. // @@ -172,6 +175,12 @@ func start() { MinTime: time.Duration(20) * time.Second, // For compatibility with the client keepalive.ClientParameters })) + // If set, configure gRPC max msg size + if *maxMsgSize > 0 { + opts = append(opts, grpc.MaxRecvMsgSize(*maxMsgSize)) + opts = append(opts, grpc.MaxSendMsgSize(*maxMsgSize)) + } + rootServer = tiller.NewServer(opts...) healthpb.RegisterHealthServer(rootServer, healthSrv) @@ -286,3 +295,16 @@ func historyMaxFromEnv() int { func tlsEnableEnvVarDefault() bool { return os.Getenv(tlsEnableEnvVar) != "" } func tlsVerifyEnvVarDefault() bool { return os.Getenv(tlsVerifyEnvVar) != "" } + +func maxMsgSizeFromEnv() int { + val := os.Getenv(maxMsgSizeEnvVar) + if val == "" { + return 0 + } + ret, err := strconv.Atoi(val) + if err != nil { + log.Printf("Invalid max msg size %q. Defaulting to %d.", val, tiller.DefaultMaxMsgSize) + return 0 + } + return ret +} diff --git a/pkg/tiller/server.go b/pkg/tiller/server.go index 818cfd47a..f6666a54f 100644 --- a/pkg/tiller/server.go +++ b/pkg/tiller/server.go @@ -29,15 +29,15 @@ import ( "k8s.io/helm/pkg/version" ) -// maxMsgSize use 20MB as the default message size limit. +// DefaultMaxMsgSize use 20MB as the default message size limit. // grpc library default is 4MB -const maxMsgSize = 1024 * 1024 * 20 +const DefaultMaxMsgSize = 1024 * 1024 * 20 // DefaultServerOpts returns the set of default grpc ServerOption's that Tiller requires. func DefaultServerOpts() []grpc.ServerOption { return []grpc.ServerOption{ - grpc.MaxRecvMsgSize(maxMsgSize), - grpc.MaxSendMsgSize(maxMsgSize), + grpc.MaxRecvMsgSize(DefaultMaxMsgSize), + grpc.MaxSendMsgSize(DefaultMaxMsgSize), grpc.UnaryInterceptor(newUnaryInterceptor()), grpc.StreamInterceptor(newStreamInterceptor()), } From f046d1c47cdbe748b01339a12ee78ac48e95598f Mon Sep 17 00:00:00 2001 From: makhov Date: Sat, 17 Mar 2018 11:08:59 +0300 Subject: [PATCH 2/2] tiller grpc message size opt. style fix --- cmd/tiller/tiller.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmd/tiller/tiller.go b/cmd/tiller/tiller.go index 8e8c794d9..88226fd44 100644 --- a/cmd/tiller/tiller.go +++ b/cmd/tiller/tiller.go @@ -177,8 +177,7 @@ func start() { // If set, configure gRPC max msg size if *maxMsgSize > 0 { - opts = append(opts, grpc.MaxRecvMsgSize(*maxMsgSize)) - opts = append(opts, grpc.MaxSendMsgSize(*maxMsgSize)) + opts = append(opts, grpc.MaxRecvMsgSize(*maxMsgSize), grpc.MaxSendMsgSize(*maxMsgSize)) } rootServer = tiller.NewServer(opts...)