Commit 1f386a34 authored by adshmh's avatar adshmh Committed by Matthew Fisher

add --devel flag to inspect command (#5141)

* fix(helm): add --devel flag to allow inspect on pre-release chart versions
Signed-off-by: 's avatarArash Deshmeh <adeshmeh@ca.ibm.com>

* fix(helm): remove some duplication from inspect command preparation
Signed-off-by: 's avatarArash Deshmeh <adeshmeh@ca.ibm.com>
parent c2e8720c
......@@ -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 {
......
......@@ -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)
}
})
}
}
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
#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`.
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"]
......@@ -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
......@@ -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
......@@ -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
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment