From d762a42168308d93a46be1d7bc37bc518eee496f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johnny=20Bergstr=C3=B6m?= Date: Wed, 22 Nov 2017 17:20:41 +0100 Subject: [PATCH] Fix helmignore for .* (#3114) When the first rule matching entry for top level dir will be empty string, the .* rule will match. Skip this entry as it's not needed for processing. --- pkg/chartutil/load.go | 5 +++++ pkg/chartutil/requirements_test.go | 6 ++++++ .../dependent-chart-helmignore/.helmignore | 2 ++ .../dependent-chart-helmignore/Chart.yaml | 17 +++++++++++++++++ .../charts/.ignore_me | 0 .../charts/_ignore_me | 1 + .../charts/alpine/Chart.yaml | 4 ++++ .../charts/alpine/README.md | 9 +++++++++ .../charts/alpine/charts/mast1/Chart.yaml | 4 ++++ .../charts/alpine/charts/mast1/values.yaml | 4 ++++ .../charts/alpine/charts/mast2-0.1.0.tgz | Bin 0 -> 325 bytes .../charts/alpine/templates/alpine-pod.yaml | 16 ++++++++++++++++ .../charts/alpine/values.yaml | 2 ++ .../templates/template.tpl | 1 + .../dependent-chart-helmignore/values.yaml | 6 ++++++ pkg/ignore/rules.go | 5 +++++ pkg/ignore/rules_test.go | 3 +++ pkg/ignore/testdata/.joonix | 0 18 files changed, 85 insertions(+) create mode 100644 pkg/chartutil/testdata/dependent-chart-helmignore/.helmignore create mode 100644 pkg/chartutil/testdata/dependent-chart-helmignore/Chart.yaml create mode 100644 pkg/chartutil/testdata/dependent-chart-helmignore/charts/.ignore_me create mode 100644 pkg/chartutil/testdata/dependent-chart-helmignore/charts/_ignore_me create mode 100644 pkg/chartutil/testdata/dependent-chart-helmignore/charts/alpine/Chart.yaml create mode 100644 pkg/chartutil/testdata/dependent-chart-helmignore/charts/alpine/README.md create mode 100644 pkg/chartutil/testdata/dependent-chart-helmignore/charts/alpine/charts/mast1/Chart.yaml create mode 100644 pkg/chartutil/testdata/dependent-chart-helmignore/charts/alpine/charts/mast1/values.yaml create mode 100644 pkg/chartutil/testdata/dependent-chart-helmignore/charts/alpine/charts/mast2-0.1.0.tgz create mode 100644 pkg/chartutil/testdata/dependent-chart-helmignore/charts/alpine/templates/alpine-pod.yaml create mode 100644 pkg/chartutil/testdata/dependent-chart-helmignore/charts/alpine/values.yaml create mode 100644 pkg/chartutil/testdata/dependent-chart-helmignore/templates/template.tpl create mode 100644 pkg/chartutil/testdata/dependent-chart-helmignore/values.yaml create mode 100644 pkg/ignore/testdata/.joonix diff --git a/pkg/chartutil/load.go b/pkg/chartutil/load.go index cf11ae2e4..f10c0eddd 100644 --- a/pkg/chartutil/load.go +++ b/pkg/chartutil/load.go @@ -245,6 +245,11 @@ func LoadDir(dir string) (*chart.Chart, error) { err = filepath.Walk(topdir, func(name string, fi os.FileInfo, err error) error { n := strings.TrimPrefix(name, topdir) + if n == "" { + // No need to process top level. Avoid bug with helmignore .* matching + // empty names. See issue 1779. + return nil + } // Normalize to / since it will also work on Windows n = filepath.ToSlash(n) diff --git a/pkg/chartutil/requirements_test.go b/pkg/chartutil/requirements_test.go index ef09bcd2e..1ddaa78a1 100644 --- a/pkg/chartutil/requirements_test.go +++ b/pkg/chartutil/requirements_test.go @@ -419,6 +419,12 @@ func TestDependentChartWithSubChartsAbsentInRequirements(t *testing.T) { } +func TestDependentChartWithSubChartsHelmignore(t *testing.T) { + if _, err := Load("testdata/dependent-chart-helmignore"); err != nil { + t.Fatalf("Failed to load testdata: %s", err) + } +} + func TestDependentChartsWithSubchartsAllSpecifiedInRequirements(t *testing.T) { c, err := Load("testdata/dependent-chart-with-all-in-requirements-yaml") if err != nil { diff --git a/pkg/chartutil/testdata/dependent-chart-helmignore/.helmignore b/pkg/chartutil/testdata/dependent-chart-helmignore/.helmignore new file mode 100644 index 000000000..8a71bc82e --- /dev/null +++ b/pkg/chartutil/testdata/dependent-chart-helmignore/.helmignore @@ -0,0 +1,2 @@ +ignore/ +.* diff --git a/pkg/chartutil/testdata/dependent-chart-helmignore/Chart.yaml b/pkg/chartutil/testdata/dependent-chart-helmignore/Chart.yaml new file mode 100644 index 000000000..7c071c27b --- /dev/null +++ b/pkg/chartutil/testdata/dependent-chart-helmignore/Chart.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +name: frobnitz +description: This is a frobnitz. +version: "1.2.3" +keywords: + - frobnitz + - sprocket + - dodad +maintainers: + - name: The Helm Team + email: helm@example.com + - name: Someone Else + email: nobody@example.com +sources: + - https://example.com/foo/bar +home: http://example.com +icon: https://example.com/64x64.png diff --git a/pkg/chartutil/testdata/dependent-chart-helmignore/charts/.ignore_me b/pkg/chartutil/testdata/dependent-chart-helmignore/charts/.ignore_me new file mode 100644 index 000000000..e69de29bb diff --git a/pkg/chartutil/testdata/dependent-chart-helmignore/charts/_ignore_me b/pkg/chartutil/testdata/dependent-chart-helmignore/charts/_ignore_me new file mode 100644 index 000000000..2cecca682 --- /dev/null +++ b/pkg/chartutil/testdata/dependent-chart-helmignore/charts/_ignore_me @@ -0,0 +1 @@ +This should be ignored by the loader, but may be included in a chart. diff --git a/pkg/chartutil/testdata/dependent-chart-helmignore/charts/alpine/Chart.yaml b/pkg/chartutil/testdata/dependent-chart-helmignore/charts/alpine/Chart.yaml new file mode 100644 index 000000000..38a4aaa54 --- /dev/null +++ b/pkg/chartutil/testdata/dependent-chart-helmignore/charts/alpine/Chart.yaml @@ -0,0 +1,4 @@ +name: alpine +description: Deploy a basic Alpine Linux pod +version: 0.1.0 +home: https://k8s.io/helm diff --git a/pkg/chartutil/testdata/dependent-chart-helmignore/charts/alpine/README.md b/pkg/chartutil/testdata/dependent-chart-helmignore/charts/alpine/README.md new file mode 100644 index 000000000..a7c84fc41 --- /dev/null +++ b/pkg/chartutil/testdata/dependent-chart-helmignore/charts/alpine/README.md @@ -0,0 +1,9 @@ +This example was generated using the command `helm create alpine`. + +The `templates/` directory contains a very simple pod resource with a +couple of parameters. + +The `values.toml` file contains the default values for the +`alpine-pod.yaml` template. + +You can install this example using `helm install docs/examples/alpine`. diff --git a/pkg/chartutil/testdata/dependent-chart-helmignore/charts/alpine/charts/mast1/Chart.yaml b/pkg/chartutil/testdata/dependent-chart-helmignore/charts/alpine/charts/mast1/Chart.yaml new file mode 100644 index 000000000..171e36156 --- /dev/null +++ b/pkg/chartutil/testdata/dependent-chart-helmignore/charts/alpine/charts/mast1/Chart.yaml @@ -0,0 +1,4 @@ +name: mast1 +description: A Helm chart for Kubernetes +version: 0.1.0 +home: "" diff --git a/pkg/chartutil/testdata/dependent-chart-helmignore/charts/alpine/charts/mast1/values.yaml b/pkg/chartutil/testdata/dependent-chart-helmignore/charts/alpine/charts/mast1/values.yaml new file mode 100644 index 000000000..42c39c262 --- /dev/null +++ b/pkg/chartutil/testdata/dependent-chart-helmignore/charts/alpine/charts/mast1/values.yaml @@ -0,0 +1,4 @@ +# Default values for mast1. +# This is a YAML-formatted file. +# Declare name/value pairs to be passed into your templates. +# name = "value" diff --git a/pkg/chartutil/testdata/dependent-chart-helmignore/charts/alpine/charts/mast2-0.1.0.tgz b/pkg/chartutil/testdata/dependent-chart-helmignore/charts/alpine/charts/mast2-0.1.0.tgz new file mode 100644 index 0000000000000000000000000000000000000000..ced5a4a6adf946f76033b6ee584affc12433cb78 GIT binary patch literal 325 zcmV-L0lNMliwFRxBUV=c1MSw|YJ)Ho2Jl|{6o>BKov2ah-PkS$dy3RWS}syLpID4If6g{VtOEXtaBMKbNS zqRDw>=dBp!{dV&0PTP0q&C|N>lXXt-@itxw6Y{^`DeLnWW%?A)n7>C|RUhXsgbeu$ zF~=_IIe#g+SrMn$%(;J_|DcTCP^g0JS-aNm4}L!m8@i)M-5Y9`%Ajtv^fYa?9kkaj zJ8J8~B+f<7*=}6cSg*6cei`_&c>Y7mE>#=&?)@Lnf3ci@t|adNONjYC00000 X0000000000z?FFgy`&fL04M+ebFHRB literal 0 HcmV?d00001 diff --git a/pkg/chartutil/testdata/dependent-chart-helmignore/charts/alpine/templates/alpine-pod.yaml b/pkg/chartutil/testdata/dependent-chart-helmignore/charts/alpine/templates/alpine-pod.yaml new file mode 100644 index 000000000..08cf3c2c1 --- /dev/null +++ b/pkg/chartutil/testdata/dependent-chart-helmignore/charts/alpine/templates/alpine-pod.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Pod +metadata: + name: {{.Release.Name}}-{{.Chart.Name}} + labels: + heritage: {{.Release.Service}} + chartName: {{.Chart.Name}} + chartVersion: {{.Chart.Version | quote}} + annotations: + "helm.sh/created": "{{.Release.Time.Seconds}}" +spec: + restartPolicy: {{default "Never" .restart_policy}} + containers: + - name: waiter + image: "alpine:3.3" + command: ["/bin/sleep","9000"] diff --git a/pkg/chartutil/testdata/dependent-chart-helmignore/charts/alpine/values.yaml b/pkg/chartutil/testdata/dependent-chart-helmignore/charts/alpine/values.yaml new file mode 100644 index 000000000..6c2aab7ba --- /dev/null +++ b/pkg/chartutil/testdata/dependent-chart-helmignore/charts/alpine/values.yaml @@ -0,0 +1,2 @@ +# The pod name +name: "my-alpine" diff --git a/pkg/chartutil/testdata/dependent-chart-helmignore/templates/template.tpl b/pkg/chartutil/testdata/dependent-chart-helmignore/templates/template.tpl new file mode 100644 index 000000000..c651ee6a0 --- /dev/null +++ b/pkg/chartutil/testdata/dependent-chart-helmignore/templates/template.tpl @@ -0,0 +1 @@ +Hello {{.Name | default "world"}} diff --git a/pkg/chartutil/testdata/dependent-chart-helmignore/values.yaml b/pkg/chartutil/testdata/dependent-chart-helmignore/values.yaml new file mode 100644 index 000000000..61f501258 --- /dev/null +++ b/pkg/chartutil/testdata/dependent-chart-helmignore/values.yaml @@ -0,0 +1,6 @@ +# A values file contains configuration. + +name: "Some Name" + +section: + name: "Name in a section" diff --git a/pkg/ignore/rules.go b/pkg/ignore/rules.go index aba089613..76f45fc7a 100644 --- a/pkg/ignore/rules.go +++ b/pkg/ignore/rules.go @@ -82,6 +82,11 @@ func (r *Rules) Len() int { // Ignore evaluates path against the rules in order. Evaluation stops when a match // is found. Matching a negative rule will stop evaluation. func (r *Rules) Ignore(path string, fi os.FileInfo) bool { + // Don't match on empty dirs. + if path == "" { + return false + } + // Disallow ignoring the current working directory. // See issue: // 1776 (New York City) Hamilton: "Pardon me, are you Aaron Burr, sir?" diff --git a/pkg/ignore/rules_test.go b/pkg/ignore/rules_test.go index 6afc4345b..17b8bf403 100644 --- a/pkg/ignore/rules_test.go +++ b/pkg/ignore/rules_test.go @@ -102,6 +102,9 @@ func TestIgnore(t *testing.T) { // "." should never get ignored. https://github.com/kubernetes/helm/issues/1776 {`.*`, ".", false}, {`.*`, "./", false}, + {`.*`, ".joonix", true}, + {`.*`, "helm.txt", false}, + {`.*`, "", false}, // Directory tests {`cargo/`, "cargo", true}, diff --git a/pkg/ignore/testdata/.joonix b/pkg/ignore/testdata/.joonix new file mode 100644 index 000000000..e69de29bb