From 1f386a34ea170850f1239a850ce381356fd59ddd Mon Sep 17 00:00:00 2001 From: adshmh <23505281+adshmh@users.noreply.github.com> Date: Fri, 1 Feb 2019 18:44:46 -0500 Subject: [PATCH] add --devel flag to inspect command (#5141) * fix(helm): add --devel flag to allow inspect on pre-release chart versions Signed-off-by: Arash Deshmeh * fix(helm): remove some duplication from inspect command preparation Signed-off-by: Arash Deshmeh --- cmd/helm/inspect.go | 43 +++++++----- cmd/helm/inspect_test.go | 66 ++++++++++++++++++ .../prerelease-0.2.0-pre-release.tgz | Bin 0 -> 1064 bytes .../testdata/testcharts/prerelease/Chart.yaml | 6 ++ .../testdata/testcharts/prerelease/README.md | 13 ++++ .../prerelease/templates/alpine-pod.yaml | 26 +++++++ docs/helm/helm_inspect.md | 3 +- docs/helm/helm_inspect_chart.md | 3 +- docs/helm/helm_inspect_readme.md | 3 +- docs/helm/helm_inspect_values.md | 3 +- 10 files changed, 146 insertions(+), 20 deletions(-) create mode 100644 cmd/helm/testdata/testcharts/prerelease-0.2.0-pre-release.tgz create mode 100644 cmd/helm/testdata/testcharts/prerelease/Chart.yaml create mode 100644 cmd/helm/testdata/testcharts/prerelease/README.md create mode 100644 cmd/helm/testdata/testcharts/prerelease/templates/alpine-pod.yaml diff --git a/cmd/helm/inspect.go b/cmd/helm/inspect.go index 844116bc5..52e681e48 100644 --- a/cmd/helm/inspect.go +++ b/cmd/helm/inspect.go @@ -59,6 +59,7 @@ type inspectCmd struct { repoURL string username string password string + devel bool certFile string keyFile string @@ -88,12 +89,9 @@ func newInspectCmd(out io.Writer) *cobra.Command { if err := checkArgsLength(len(args), "chart name"); err != nil { return err } - cp, err := locateChartPath(insp.repoURL, insp.username, insp.password, args[0], insp.version, insp.verify, insp.keyring, - insp.certFile, insp.keyFile, insp.caFile) - if err != nil { + if err := insp.prepare(args[0]); err != nil { return err } - insp.chartpath = cp return insp.run() }, } @@ -107,12 +105,9 @@ func newInspectCmd(out io.Writer) *cobra.Command { if err := checkArgsLength(len(args), "chart name"); err != nil { return err } - cp, err := locateChartPath(insp.repoURL, insp.username, insp.password, args[0], insp.version, insp.verify, insp.keyring, - insp.certFile, insp.keyFile, insp.caFile) - if err != nil { + if err := insp.prepare(args[0]); err != nil { return err } - insp.chartpath = cp return insp.run() }, } @@ -126,12 +121,9 @@ func newInspectCmd(out io.Writer) *cobra.Command { if err := checkArgsLength(len(args), "chart name"); err != nil { return err } - cp, err := locateChartPath(insp.repoURL, insp.username, insp.password, args[0], insp.version, insp.verify, insp.keyring, - insp.certFile, insp.keyFile, insp.caFile) - if err != nil { + if err := insp.prepare(args[0]); err != nil { return err } - insp.chartpath = cp return insp.run() }, } @@ -145,12 +137,9 @@ func newInspectCmd(out io.Writer) *cobra.Command { if err := checkArgsLength(len(args), "chart name"); err != nil { return err } - cp, err := locateChartPath(insp.repoURL, insp.username, insp.password, args[0], insp.version, insp.verify, insp.keyring, - insp.certFile, insp.keyFile, insp.caFile) - if err != nil { + if err := insp.prepare(args[0]); err != nil { return err } - insp.chartpath = cp return insp.run() }, } @@ -193,6 +182,12 @@ func newInspectCmd(out io.Writer) *cobra.Command { valuesSubCmd.Flags().StringVar(&insp.password, password, "", passworddesc) chartSubCmd.Flags().StringVar(&insp.password, password, "", passworddesc) + develFlag := "devel" + develDesc := "use development versions, too. Equivalent to version '>0.0.0-0'. If --version is set, this is ignored." + for _, subCmd := range cmds { + subCmd.Flags().BoolVar(&insp.devel, develFlag, false, develDesc) + } + certFile := "cert-file" certFiledesc := "verify certificates of HTTPS-enabled servers using this CA bundle" for _, subCmd := range cmds { @@ -218,6 +213,22 @@ func newInspectCmd(out io.Writer) *cobra.Command { return inspectCommand } +func (i *inspectCmd) prepare(chart string) error { + debug("Original chart version: %q", i.version) + if i.version == "" && i.devel { + debug("setting version to >0.0.0-0") + i.version = ">0.0.0-0" + } + + cp, err := locateChartPath(i.repoURL, i.username, i.password, chart, i.version, i.verify, i.keyring, + i.certFile, i.keyFile, i.caFile) + if err != nil { + return err + } + i.chartpath = cp + return nil +} + func (i *inspectCmd) run() error { chrt, err := chartutil.Load(i.chartpath) if err != nil { diff --git a/cmd/helm/inspect_test.go b/cmd/helm/inspect_test.go index b9dbf2ab6..c4ce005b0 100644 --- a/cmd/helm/inspect_test.go +++ b/cmd/helm/inspect_test.go @@ -19,8 +19,11 @@ package main import ( "bytes" "io/ioutil" + "os" "strings" "testing" + + "k8s.io/helm/pkg/repo/repotest" ) func TestInspect(t *testing.T) { @@ -78,3 +81,66 @@ func TestInspect(t *testing.T) { t.Errorf("expected empty values buffer, got %q", b.String()) } } + +func TestInspectPreReleaseChart(t *testing.T) { + hh, err := tempHelmHome(t) + if err != nil { + t.Fatal(err) + } + cleanup := resetEnv() + defer func() { + os.RemoveAll(hh.String()) + cleanup() + }() + + settings.Home = hh + + srv := repotest.NewServer(hh.String()) + defer srv.Stop() + + if _, err := srv.CopyCharts("testdata/testcharts/*.tgz*"); err != nil { + t.Fatal(err) + } + if err := srv.LinkIndices(); err != nil { + t.Fatal(err) + } + + tests := []struct { + name string + args []string + flags []string + fail bool + expectedErr string + }{ + { + name: "inspect pre-release chart", + args: []string{"prerelease"}, + fail: true, + expectedErr: "chart \"prerelease\" not found", + }, + { + name: "inspect pre-release chart with 'devel' flag", + args: []string{"prerelease"}, + flags: []string{"--devel"}, + fail: false, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + tt.flags = append(tt.flags, "--repo", srv.URL()) + cmd := newInspectCmd(ioutil.Discard) + cmd.SetArgs(tt.args) + cmd.ParseFlags(tt.flags) + if err := cmd.RunE(cmd, tt.args); err != nil { + if tt.fail { + if !strings.Contains(err.Error(), tt.expectedErr) { + t.Errorf("%q expected error: %s, got: %s", tt.name, tt.expectedErr, err.Error()) + } + return + } + t.Errorf("%q reported error: %s", tt.name, err) + } + }) + } +} diff --git a/cmd/helm/testdata/testcharts/prerelease-0.2.0-pre-release.tgz b/cmd/helm/testdata/testcharts/prerelease-0.2.0-pre-release.tgz new file mode 100644 index 0000000000000000000000000000000000000000..36c8f02da06c1b6b36342b1757e719074282c712 GIT binary patch literal 1064 zcmV+@1lRi?iwG0|00000|0w_~VMtOiV@ORlOnEsqVl!4SWK%V1T2nbTPgYhoO;>Dc zVQyr3R8em|NM&qo0PI&ykJ~mA-m`wiK)J@UY`yD!>)WCU(4cJ)Y=ZzrQNUwyY!RkN zl|xzUI{xnkNonnMw#cE24T^d$hDpvdADnrHYAjh&giPb_E3_`#VXdy7SMog1Z?3Py zZ=UDpzxlK%t|rC*CfAeMO)kmL1xw{2$vo5AI(gg1EG@ank5H zyrD*!9Uv@`WeK;ck(%HqsoQ&Kj7Ta|(;O=28lI2GoBwkr&A1{}CmQ|Ev6vDztu2Y? z$>`zyTDq!TW~HfvPE_2I)M5@Fj7Vy7DA3_N0f^n5?)TYUtd;CN)^s?G z_WSG;s+PE4ND}~sOH%CB0A9hziXg4XN{4Go<0eRkmPvp!;4GFK=qg!O;EYiq0tb-* zgtgp~hBAz$9`2p%l~=8Tm9c=LmYSif40NcShh!q?Ds<2nHUmO~*2%I}XoHm=O)^;G z#%PvHMIJBO!KTSJ?UJk}M}g#O)VL-wTJGj>l7?T%Ze>aE8UAREBRCvR!|v^;P#V1@ z?Ku`|+z^9wK*+n007-y@t9}8M0i{PQcPyz3>!~2l1 zN4W4A&J2euespI3ly`lPpE;R;H|tPpvf>g{{`TA=k%)}OOimLbdN!|LxweJvSA{%UNMkh z-|n!e0(hWwh@7wp7zB&s^K$`0S}L8fyMbXm9d60)1}D8Q!!U$Sx(YBUP3yPJ%FjWp z$&uv&d>a|ezh)P(l8TPNUywA1IpFDaarO{iz~E$-B)^&#O4JYrsZ!uh6A?p?;SL9c iDS6x<7~a^6?80>yxyVJnk^B_^0RR8mc}r0M6aWC+uN4~r literal 0 HcmV?d00001 diff --git a/cmd/helm/testdata/testcharts/prerelease/Chart.yaml b/cmd/helm/testdata/testcharts/prerelease/Chart.yaml new file mode 100644 index 000000000..d8d901473 --- /dev/null +++ b/cmd/helm/testdata/testcharts/prerelease/Chart.yaml @@ -0,0 +1,6 @@ +description: Deploy a basic Alpine Linux pod +home: https://k8s.io/helm +name: prerelease +sources: +- https://github.com/helm/helm +version: 0.2.0-pre-release diff --git a/cmd/helm/testdata/testcharts/prerelease/README.md b/cmd/helm/testdata/testcharts/prerelease/README.md new file mode 100644 index 000000000..3c32de5db --- /dev/null +++ b/cmd/helm/testdata/testcharts/prerelease/README.md @@ -0,0 +1,13 @@ +#Alpine: A simple Helm chart + +Run a single pod of Alpine Linux. + +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.yaml` 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/cmd/helm/testdata/testcharts/prerelease/templates/alpine-pod.yaml b/cmd/helm/testdata/testcharts/prerelease/templates/alpine-pod.yaml new file mode 100644 index 000000000..f569d556c --- /dev/null +++ b/cmd/helm/testdata/testcharts/prerelease/templates/alpine-pod.yaml @@ -0,0 +1,26 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{.Release.Name}}-{{.Values.Name}}" + labels: + # The "heritage" label is used to track which tool deployed a given chart. + # It is useful for admins who want to see what releases a particular tool + # is responsible for. + app.kubernetes.io/managed-by: {{.Release.Service | quote }} + # The "release" convention makes it easy to tie a release to all of the + # Kubernetes resources that were created as part of that release. + app.kubernetes.io/instance: {{.Release.Name | quote }} + # This makes it easy to audit chart usage. + helm.sh/chart: "{{.Chart.Name}}-{{.Chart.Version}}" + annotations: + "helm.sh/created": {{.Release.Time.Seconds | quote }} +spec: + # This shows how to use a simple value. This will look for a passed-in value + # called restartPolicy. If it is not found, it will use the default value. + # {{default "Never" .restartPolicy}} is a slightly optimized version of the + # more conventional syntax: {{.restartPolicy | default "Never"}} + restartPolicy: {{default "Never" .Values.restartPolicy}} + containers: + - name: waiter + image: "alpine:3.3" + command: ["/bin/sleep","9000"] diff --git a/docs/helm/helm_inspect.md b/docs/helm/helm_inspect.md index 86689eeaa..8bdf1092d 100644 --- a/docs/helm/helm_inspect.md +++ b/docs/helm/helm_inspect.md @@ -20,6 +20,7 @@ helm inspect [CHART] [flags] ``` --ca-file string chart repository url where to locate the requested chart --cert-file string verify certificates of HTTPS-enabled servers using this CA bundle + --devel use development versions, too. Equivalent to version '>0.0.0-0'. If --version is set, this is ignored. -h, --help help for inspect --key-file string identify HTTPS client using this SSL key file --keyring string path to the keyring containing public verification keys (default "~/.gnupg/pubring.gpg") @@ -49,4 +50,4 @@ helm inspect [CHART] [flags] * [helm inspect readme](helm_inspect_readme.md) - shows inspect readme * [helm inspect values](helm_inspect_values.md) - shows inspect values -###### Auto generated by spf13/cobra on 1-Aug-2018 +###### Auto generated by spf13/cobra on 8-Jan-2019 diff --git a/docs/helm/helm_inspect_chart.md b/docs/helm/helm_inspect_chart.md index 2b9adbb7e..1cd13fc72 100644 --- a/docs/helm/helm_inspect_chart.md +++ b/docs/helm/helm_inspect_chart.md @@ -18,6 +18,7 @@ helm inspect chart [CHART] [flags] ``` --ca-file string chart repository url where to locate the requested chart --cert-file string verify certificates of HTTPS-enabled servers using this CA bundle + --devel use development versions, too. Equivalent to version '>0.0.0-0'. If --version is set, this is ignored. -h, --help help for chart --key-file string identify HTTPS client using this SSL key file --keyring string path to the keyring containing public verification keys (default "~/.gnupg/pubring.gpg") @@ -44,4 +45,4 @@ helm inspect chart [CHART] [flags] * [helm inspect](helm_inspect.md) - inspect a chart -###### Auto generated by spf13/cobra on 1-Aug-2018 +###### Auto generated by spf13/cobra on 8-Jan-2019 diff --git a/docs/helm/helm_inspect_readme.md b/docs/helm/helm_inspect_readme.md index d222cd53a..9570d19d6 100644 --- a/docs/helm/helm_inspect_readme.md +++ b/docs/helm/helm_inspect_readme.md @@ -18,6 +18,7 @@ helm inspect readme [CHART] [flags] ``` --ca-file string chart repository url where to locate the requested chart --cert-file string verify certificates of HTTPS-enabled servers using this CA bundle + --devel use development versions, too. Equivalent to version '>0.0.0-0'. If --version is set, this is ignored. -h, --help help for readme --key-file string identify HTTPS client using this SSL key file --keyring string path to the keyring containing public verification keys (default "~/.gnupg/pubring.gpg") @@ -42,4 +43,4 @@ helm inspect readme [CHART] [flags] * [helm inspect](helm_inspect.md) - inspect a chart -###### Auto generated by spf13/cobra on 1-Aug-2018 +###### Auto generated by spf13/cobra on 8-Jan-2019 diff --git a/docs/helm/helm_inspect_values.md b/docs/helm/helm_inspect_values.md index 9cca2fc32..a634134dd 100644 --- a/docs/helm/helm_inspect_values.md +++ b/docs/helm/helm_inspect_values.md @@ -18,6 +18,7 @@ helm inspect values [CHART] [flags] ``` --ca-file string chart repository url where to locate the requested chart --cert-file string verify certificates of HTTPS-enabled servers using this CA bundle + --devel use development versions, too. Equivalent to version '>0.0.0-0'. If --version is set, this is ignored. -h, --help help for values --key-file string identify HTTPS client using this SSL key file --keyring string path to the keyring containing public verification keys (default "~/.gnupg/pubring.gpg") @@ -44,4 +45,4 @@ helm inspect values [CHART] [flags] * [helm inspect](helm_inspect.md) - inspect a chart -###### Auto generated by spf13/cobra on 1-Aug-2018 +###### Auto generated by spf13/cobra on 8-Jan-2019