diff --git a/pkg/cmd/template.go b/pkg/cmd/template.go index cf68c6c46..e66d8cf04 100644 --- a/pkg/cmd/template.go +++ b/pkg/cmd/template.go @@ -35,6 +35,7 @@ import ( "helm.sh/helm/v4/pkg/action" "helm.sh/helm/v4/pkg/chart/common" + "helm.sh/helm/v4/pkg/cli" "helm.sh/helm/v4/pkg/cli/values" "helm.sh/helm/v4/pkg/cmd/require" releaseutil "helm.sh/helm/v4/pkg/release/v1/util" @@ -194,6 +195,8 @@ func newTemplateCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { f := cmd.Flags() addInstallFlags(cmd, f, client, valueOpts) + f.Var(cli.NewQuantityBytesValue(&client.MaxChartSize), "max-chart-size", "maximum size for a decompressed chart (e.g., 500Ki, 5Mi)") + f.Var(cli.NewQuantityBytesValue(&client.MaxChartFileSize), "max-file-size", "maximum size for a single file in a chart (e.g., 5Mi, 10Mi)") f.StringArrayVarP(&showFiles, "show-only", "s", []string{}, "only show manifests rendered from the given templates") f.StringVar(&client.OutputDir, "output-dir", "", "writes the executed templates to files in output-dir instead of stdout") f.BoolVar(&validate, "validate", false, "deprecated") diff --git a/pkg/cmd/template_test.go b/pkg/cmd/template_test.go index 5bcccf5d0..1c00b74ac 100644 --- a/pkg/cmd/template_test.go +++ b/pkg/cmd/template_test.go @@ -166,6 +166,18 @@ func TestTemplateCmd(t *testing.T) { cmd: fmt.Sprintf("template '%s' -f %s/extra_values.yaml", chartPath, chartPath), golden: "output/template-subchart-cm-set-file.txt", }, + { + name: "template with restricted max size (with IEC size)", + cmd: "template too-big testdata/testcharts/oci-dependent-chart-0.1.0.tgz --max-chart-size=1Ki", + wantError: true, + golden: "output/template-with-restricted-chart-size.txt", + }, + { + name: "template with restricted max file size", + cmd: "template too-big testdata/testcharts/compressedchart-0.1.0.tgz --max-file-size=10", + wantError: true, + golden: "output/template-with-restricted-file-size.txt", + }, } runTestCmd(t, tests) } diff --git a/pkg/cmd/testdata/output/template-with-restricted-chart-size.txt b/pkg/cmd/testdata/output/template-with-restricted-chart-size.txt new file mode 100644 index 000000000..94acd948d --- /dev/null +++ b/pkg/cmd/testdata/output/template-with-restricted-chart-size.txt @@ -0,0 +1 @@ +Error: unable to load chart archive: decompressed chart is larger than the maximum size 1Ki diff --git a/pkg/cmd/testdata/output/template-with-restricted-file-size.txt b/pkg/cmd/testdata/output/template-with-restricted-file-size.txt new file mode 100644 index 000000000..d08344f7f --- /dev/null +++ b/pkg/cmd/testdata/output/template-with-restricted-file-size.txt @@ -0,0 +1 @@ +Error: unable to load chart archive: decompressed chart file "compressedchart/Chart.yaml" is larger than the maximum file size 10