From 4d45bcb35c1e22f0f0d861807dd7341aed4d268a Mon Sep 17 00:00:00 2001 From: Weiping Cai Date: Sat, 20 Jun 2020 21:59:54 +0800 Subject: [PATCH] add template file size to 3m and throw error Signed-off-by: Weiping Cai --- cmd/helm/install.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cmd/helm/install.go b/cmd/helm/install.go index 21a41b9f9..f953c1230 100644 --- a/cmd/helm/install.go +++ b/cmd/helm/install.go @@ -17,6 +17,7 @@ limitations under the License. package main import ( + "bytes" "fmt" "io" "time" @@ -192,6 +193,10 @@ func runInstall(args []string, client *action.Install, valueOpts *values.Options return nil, err } + if _, err := isLimitSize(chartRequested.Raw); err != nil { + return nil, err + } + if chartRequested.Metadata.Deprecated { fmt.Fprintln(out, "WARNING: This chart is deprecated") } @@ -240,6 +245,20 @@ func isChartInstallable(ch *chart.Chart) (bool, error) { return false, errors.Errorf("%s charts are not installable", ch.Metadata.Type) } +// It is to limit the total size of the template file to 3m, and the content of files over 3m should not be allowed to be installed. +// +// This is because the server requires the requestbody to be less than 3m when creating secrets.For details, please refer to: https://github.com/kubernetes/kubernetes/blob/release-1.18/staging/src/k8s.io/apiserver/pkg/server/config.go#L323 +func isLimitSize(raw []*chart.File) (bool, error) { + totalSize := int64(0) + for _, r := range raw { + totalSize += int64(bytes.Count(r.Data, []byte(""))) + } + if totalSize < int64(3 * 1024 * 1024) { + return true, nil + } + return false,errors.Errorf("Chart package too large, limit is 3MB.") +} + // Provide dynamic auto-completion for the install and template commands func compInstall(args []string, toComplete string, client *action.Install) ([]string, completion.BashCompDirective) { requiredArgs := 1