From dd4afa6af0d6b4994243e8bc401f5c5b9c6cd8c1 Mon Sep 17 00:00:00 2001 From: Martin Hickey Date: Sat, 10 Aug 2019 11:55:26 +0100 Subject: [PATCH] Fail to load charts that are not v1 apiVersion (#6180) Signed-off-by: Martin Hickey --- pkg/chartutil/load.go | 4 ++++ pkg/chartutil/load_test.go | 12 +++++++++++ .../testdata/frobnitz.v2/.helmignore | 1 + pkg/chartutil/testdata/frobnitz.v2/Chart.yaml | 20 ++++++++++++++++++ .../testdata/frobnitz.v2/INSTALL.txt | 1 + pkg/chartutil/testdata/frobnitz.v2/LICENSE | 1 + pkg/chartutil/testdata/frobnitz.v2/README.md | 11 ++++++++++ .../testdata/frobnitz.v2/charts/_ignore_me | 1 + .../frobnitz.v2/charts/alpine/Chart.yaml | 4 ++++ .../frobnitz.v2/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 ++++++++++++++ .../frobnitz.v2/charts/alpine/values.yaml | 2 ++ .../frobnitz.v2/charts/mariner-4.3.2.tgz | Bin 0 -> 1012 bytes .../testdata/frobnitz.v2/docs/README.md | 1 + pkg/chartutil/testdata/frobnitz.v2/icon.svg | 8 +++++++ .../testdata/frobnitz.v2/ignore/me.txt | 0 .../testdata/frobnitz.v2/requirements.lock | 8 +++++++ .../testdata/frobnitz.v2/requirements.yaml | 7 ++++++ .../frobnitz.v2/templates/template.tpl | 1 + .../testdata/frobnitz.v2/values.yaml | 6 ++++++ 23 files changed, 121 insertions(+) create mode 100644 pkg/chartutil/testdata/frobnitz.v2/.helmignore create mode 100644 pkg/chartutil/testdata/frobnitz.v2/Chart.yaml create mode 100644 pkg/chartutil/testdata/frobnitz.v2/INSTALL.txt create mode 100644 pkg/chartutil/testdata/frobnitz.v2/LICENSE create mode 100644 pkg/chartutil/testdata/frobnitz.v2/README.md create mode 100644 pkg/chartutil/testdata/frobnitz.v2/charts/_ignore_me create mode 100644 pkg/chartutil/testdata/frobnitz.v2/charts/alpine/Chart.yaml create mode 100644 pkg/chartutil/testdata/frobnitz.v2/charts/alpine/README.md create mode 100644 pkg/chartutil/testdata/frobnitz.v2/charts/alpine/charts/mast1/Chart.yaml create mode 100644 pkg/chartutil/testdata/frobnitz.v2/charts/alpine/charts/mast1/values.yaml create mode 100644 pkg/chartutil/testdata/frobnitz.v2/charts/alpine/charts/mast2-0.1.0.tgz create mode 100644 pkg/chartutil/testdata/frobnitz.v2/charts/alpine/templates/alpine-pod.yaml create mode 100644 pkg/chartutil/testdata/frobnitz.v2/charts/alpine/values.yaml create mode 100644 pkg/chartutil/testdata/frobnitz.v2/charts/mariner-4.3.2.tgz create mode 100644 pkg/chartutil/testdata/frobnitz.v2/docs/README.md create mode 100644 pkg/chartutil/testdata/frobnitz.v2/icon.svg create mode 100644 pkg/chartutil/testdata/frobnitz.v2/ignore/me.txt create mode 100644 pkg/chartutil/testdata/frobnitz.v2/requirements.lock create mode 100644 pkg/chartutil/testdata/frobnitz.v2/requirements.yaml create mode 100644 pkg/chartutil/testdata/frobnitz.v2/templates/template.tpl create mode 100644 pkg/chartutil/testdata/frobnitz.v2/values.yaml diff --git a/pkg/chartutil/load.go b/pkg/chartutil/load.go index b0927a5cf..95b835d5b 100644 --- a/pkg/chartutil/load.go +++ b/pkg/chartutil/load.go @@ -171,6 +171,10 @@ func LoadFiles(files []*BufferedFile) (*chart.Chart, error) { return c, err } c.Metadata = m + var apiVersion = c.Metadata.ApiVersion + if apiVersion != "" && apiVersion != ApiVersionV1 { + return c, fmt.Errorf("apiVersion '%s' is not valid. The value must be \"v1\"", apiVersion) + } } else if f.Name == "values.toml" { return c, errors.New("values.toml is illegal as of 2.0.0-alpha.2") } else if f.Name == "values.yaml" { diff --git a/pkg/chartutil/load_test.go b/pkg/chartutil/load_test.go index c031a6a96..f139abf5c 100644 --- a/pkg/chartutil/load_test.go +++ b/pkg/chartutil/load_test.go @@ -23,6 +23,7 @@ import ( "os" "path" "path/filepath" + "strings" "testing" "time" @@ -39,6 +40,17 @@ func TestLoadDir(t *testing.T) { verifyRequirements(t, c) } +func TestLoadNonV1Chart(t *testing.T) { + _, err := Load("testdata/frobnitz.v2") + if err != nil { + if strings.Compare(err.Error(), "apiVersion 'v2' is not valid. The value must be \"v1\"") != 0 { + t.Errorf("Unexpected message: %s", err) + } + return + } + t.Fatalf("chart with v2 apiVersion should not load") +} + func TestLoadFile(t *testing.T) { c, err := Load("testdata/frobnitz-1.2.3.tgz") if err != nil { diff --git a/pkg/chartutil/testdata/frobnitz.v2/.helmignore b/pkg/chartutil/testdata/frobnitz.v2/.helmignore new file mode 100644 index 000000000..9973a57b8 --- /dev/null +++ b/pkg/chartutil/testdata/frobnitz.v2/.helmignore @@ -0,0 +1 @@ +ignore/ diff --git a/pkg/chartutil/testdata/frobnitz.v2/Chart.yaml b/pkg/chartutil/testdata/frobnitz.v2/Chart.yaml new file mode 100644 index 000000000..157af54c1 --- /dev/null +++ b/pkg/chartutil/testdata/frobnitz.v2/Chart.yaml @@ -0,0 +1,20 @@ +apiVersion: v2 +name: frobnitz +description: This is a frobnitz as a v2 chart +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 +annotations: + extrakey: extravalue + anotherkey: anothervalue diff --git a/pkg/chartutil/testdata/frobnitz.v2/INSTALL.txt b/pkg/chartutil/testdata/frobnitz.v2/INSTALL.txt new file mode 100644 index 000000000..2010438c2 --- /dev/null +++ b/pkg/chartutil/testdata/frobnitz.v2/INSTALL.txt @@ -0,0 +1 @@ +This is an install document. The client may display this. diff --git a/pkg/chartutil/testdata/frobnitz.v2/LICENSE b/pkg/chartutil/testdata/frobnitz.v2/LICENSE new file mode 100644 index 000000000..6121943b1 --- /dev/null +++ b/pkg/chartutil/testdata/frobnitz.v2/LICENSE @@ -0,0 +1 @@ +LICENSE placeholder. diff --git a/pkg/chartutil/testdata/frobnitz.v2/README.md b/pkg/chartutil/testdata/frobnitz.v2/README.md new file mode 100644 index 000000000..8cf4cc3d7 --- /dev/null +++ b/pkg/chartutil/testdata/frobnitz.v2/README.md @@ -0,0 +1,11 @@ +# Frobnitz + +This is an example chart. + +## Usage + +This is an example. It has no usage. + +## Development + +For developer info, see the top-level repository. diff --git a/pkg/chartutil/testdata/frobnitz.v2/charts/_ignore_me b/pkg/chartutil/testdata/frobnitz.v2/charts/_ignore_me new file mode 100644 index 000000000..2cecca682 --- /dev/null +++ b/pkg/chartutil/testdata/frobnitz.v2/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/frobnitz.v2/charts/alpine/Chart.yaml b/pkg/chartutil/testdata/frobnitz.v2/charts/alpine/Chart.yaml new file mode 100644 index 000000000..38a4aaa54 --- /dev/null +++ b/pkg/chartutil/testdata/frobnitz.v2/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/frobnitz.v2/charts/alpine/README.md b/pkg/chartutil/testdata/frobnitz.v2/charts/alpine/README.md new file mode 100644 index 000000000..a7c84fc41 --- /dev/null +++ b/pkg/chartutil/testdata/frobnitz.v2/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/frobnitz.v2/charts/alpine/charts/mast1/Chart.yaml b/pkg/chartutil/testdata/frobnitz.v2/charts/alpine/charts/mast1/Chart.yaml new file mode 100644 index 000000000..171e36156 --- /dev/null +++ b/pkg/chartutil/testdata/frobnitz.v2/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/frobnitz.v2/charts/alpine/charts/mast1/values.yaml b/pkg/chartutil/testdata/frobnitz.v2/charts/alpine/charts/mast1/values.yaml new file mode 100644 index 000000000..42c39c262 --- /dev/null +++ b/pkg/chartutil/testdata/frobnitz.v2/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/frobnitz.v2/charts/alpine/charts/mast2-0.1.0.tgz b/pkg/chartutil/testdata/frobnitz.v2/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/frobnitz.v2/charts/alpine/templates/alpine-pod.yaml b/pkg/chartutil/testdata/frobnitz.v2/charts/alpine/templates/alpine-pod.yaml new file mode 100644 index 000000000..c34fa8c47 --- /dev/null +++ b/pkg/chartutil/testdata/frobnitz.v2/charts/alpine/templates/alpine-pod.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Pod +metadata: + name: {{.Release.Name}}-{{.Chart.Name}} + labels: + app.kubernetes.io/managed-by: {{.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/frobnitz.v2/charts/alpine/values.yaml b/pkg/chartutil/testdata/frobnitz.v2/charts/alpine/values.yaml new file mode 100644 index 000000000..6c2aab7ba --- /dev/null +++ b/pkg/chartutil/testdata/frobnitz.v2/charts/alpine/values.yaml @@ -0,0 +1,2 @@ +# The pod name +name: "my-alpine" diff --git a/pkg/chartutil/testdata/frobnitz.v2/charts/mariner-4.3.2.tgz b/pkg/chartutil/testdata/frobnitz.v2/charts/mariner-4.3.2.tgz new file mode 100644 index 0000000000000000000000000000000000000000..78fabe241b042dcd5ec2ce08dacaaf26fc110640 GIT binary patch literal 1012 zcmVXdFct$FCMzS*7)(8lmGQQS%|2-P@PLQ%XW@8+wgs zC{cqN=XU3ETlOupvu)3qh#>i3n-2{XEL0(gmeQ(NX#^|8)Y=AHVz8k>LqKV1T8daG zEj<%$=k{JmQfgYfTrJLzgPFUVotfQdp8x+@3u41YxGuDa2!aq*6cDs(t`#D3uFV5P zDWXcUtctP>1W^(NH3XE!+*ASIBM{TAXenrG=+@)tuw?Qd=E>hjvAsvI^6_7jf|&4W zXqly7gFX*cmTw(@QH;{~3yLaB(TF0^_$z`Wg@91{t=!E2JpMMcPz>Zx0jDER!-h)? z$Buyp(1=V6XxWnik`4xOKY_4~2=cfs2z$XGnV0womvXYRgu~q3z8%ILQpo=x%HHDG z!0qY(?EI%4iRphiD8wJ54&T7YLN@VAZ37GHzY>`je^n7>rvK$YM=r8;WNQZUVjKXq zAm<3sOhAGi&!fKqfRXEX261pY22zB$UaYPTZG)C;B3^T>y16P6TvBw1u)vGFz^viF zNg;9s(O^Pq?TcUmw_X3!tQSQ&sQ;o0)Bkc%i2oL7`l#f}pJO5YmqcaW`=1ht3QYgY zK_z$&C82K;kUIfEq5tff#)jri&o?x!UCncqU{lKQ0R2GlN<-7eS~|jlgdiOx4XXb| zLufZh%1;D-Kpe}gHKE-e^tkLInh7xq%q4f$fC~-m0pfr}w(og#KEtM8(~gfpQI4|f z=Nu^Y)DCL+s!aQ+Hp#}@qe}Xbs|08rDtN+Tv z?ChQ$d5&A}IC>(DKxZf4k~4>F9)h=ko)?VpRtKAUxT}lh-M!1a_y1zqUmH~IJZXRP z->${wV*aZl_5Y|Mi!A@k!K&@|hdSOLX$>v?eJsBDJK>>aZ+z~*H?-WXjvpL4 z+}G5<_l3u*R}8o8JX`OyO}(?U->9kT8ofSoa@}xcZ+FF4a?Q1eR~7Y2d{^PMLneEN5o@_g@A$io99Pa!(Gqe2EM9;aGzHLzl;B?va8(XMXA#dZOazk)CZYAAR6O_jKm3)#;J$KkF}5PtE+Xqr&>;_{v|u zobg_3J2%*OU*`IX%QJf~eIop_=ZoIU@iULE(~pg1Mn{i4Q!%i=ckS0p=02G2kD@hK icf1~Y>h8pa!C){L3 + + Example icon + + + diff --git a/pkg/chartutil/testdata/frobnitz.v2/ignore/me.txt b/pkg/chartutil/testdata/frobnitz.v2/ignore/me.txt new file mode 100644 index 000000000..e69de29bb diff --git a/pkg/chartutil/testdata/frobnitz.v2/requirements.lock b/pkg/chartutil/testdata/frobnitz.v2/requirements.lock new file mode 100644 index 000000000..6fcc2ed9f --- /dev/null +++ b/pkg/chartutil/testdata/frobnitz.v2/requirements.lock @@ -0,0 +1,8 @@ +dependencies: + - name: alpine + version: "0.1.0" + repository: https://example.com/charts + - name: mariner + version: "4.3.2" + repository: https://example.com/charts +digest: invalid diff --git a/pkg/chartutil/testdata/frobnitz.v2/requirements.yaml b/pkg/chartutil/testdata/frobnitz.v2/requirements.yaml new file mode 100644 index 000000000..5eb0bc98b --- /dev/null +++ b/pkg/chartutil/testdata/frobnitz.v2/requirements.yaml @@ -0,0 +1,7 @@ +dependencies: + - name: alpine + version: "0.1.0" + repository: https://example.com/charts + - name: mariner + version: "4.3.2" + repository: https://example.com/charts diff --git a/pkg/chartutil/testdata/frobnitz.v2/templates/template.tpl b/pkg/chartutil/testdata/frobnitz.v2/templates/template.tpl new file mode 100644 index 000000000..c651ee6a0 --- /dev/null +++ b/pkg/chartutil/testdata/frobnitz.v2/templates/template.tpl @@ -0,0 +1 @@ +Hello {{.Name | default "world"}} diff --git a/pkg/chartutil/testdata/frobnitz.v2/values.yaml b/pkg/chartutil/testdata/frobnitz.v2/values.yaml new file mode 100644 index 000000000..61f501258 --- /dev/null +++ b/pkg/chartutil/testdata/frobnitz.v2/values.yaml @@ -0,0 +1,6 @@ +# A values file contains configuration. + +name: "Some Name" + +section: + name: "Name in a section"