Update after review

- https://github.com/helm/helm/pull/4524#pullrequestreview-155183390
- https://github.com/helm/helm/pull/4524#pullrequestreview-155379922
- Fix where app.kubernetes.io/instance was incorrect in service selector

Signed-off-by: Martin Hickey <martin.hickey@ie.ibm.com>
pull/4524/head
Martin Hickey 7 years ago
parent 2f4d86d94c
commit c93c724102

@ -47,6 +47,8 @@ something like this:
|- charts/ # Charts that this chart depends on |- charts/ # Charts that this chart depends on
| |
|- templates/ # The template files |- templates/ # The template files
|
|- templates/tests/ # The test files
'helm create' takes a path for an argument. If directories in the given path 'helm create' takes a path for an argument. If directories in the given path
do not exist, Helm will attempt to create them as it goes. If the given do not exist, Helm will attempt to create them as it goes. If the given
@ -84,7 +86,6 @@ func newCreateCmd(out io.Writer) *cobra.Command {
func (c *createCmd) run() error { func (c *createCmd) run() error {
fmt.Fprintf(c.out, "Creating %s\n", c.name) fmt.Fprintf(c.out, "Creating %s\n", c.name)
chartname := filepath.Base(c.name) chartname := filepath.Base(c.name)
cfile := &chart.Metadata{ cfile := &chart.Metadata{
Name: chartname, Name: chartname,

@ -46,8 +46,10 @@ const (
NotesName = "NOTES.txt" NotesName = "NOTES.txt"
// HelpersName is the name of the example helpers file. // HelpersName is the name of the example helpers file.
HelpersName = "_helpers.tpl" HelpersName = "_helpers.tpl"
// ServiceTestName is the name of the example test service file. // TemplatesTestsDir is the relative directory name for templates tests.
ServiceTestName = "service-test.yaml" TemplatesTestsDir = "templates/tests"
// TestConnectionName is the name of the example connection test file.
TestConnectionName = "test-connection.yaml"
) )
const defaultValues = `# Default values for %s. const defaultValues = `# Default values for %s.
@ -292,23 +294,23 @@ Create chart name and version as used by the chart label.
{{- end -}} {{- end -}}
` `
const defaultServiceTest = `apiVersion: v1 const defaultTestConnection = `apiVersion: v1
kind: Pod kind: Pod
metadata: metadata:
name: "{{ template "<CHARTNAME>.fullname" . }}-service-test" name: "{{ include "<CHARTNAME>.fullname" . }}-test-connection"
labels: labels:
heritage: {{ .Release.Service }} app.kubernetes.io/name: {{ include "<CHARTNAME>.name" . }}
release: {{ .Release.Name }} helm.sh/chart: {{ include "<CHARTNAME>.chart" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }} app.kubernetes.io/instance: {{ .Release.Name }}
app: {{ template "<CHARTNAME>.name" . }} app.kubernetes.io/managed-by: {{ .Release.Service }}
annotations: annotations:
"helm.sh/hook": test-success "helm.sh/hook": test-success
spec: spec:
containers: containers:
- name: curl - name: wget
image: radial/busyboxplus:curl image: busybox
command: ['curl'] command: ['wget']
args: ['{{ template "<CHARTNAME>.fullname" . }}:{{ .Values.service.port }}'] args: ['{{ include "<CHARTNAME>.fullname" . }}:{{ .Values.service.port }}']
restartPolicy: Never restartPolicy: Never
` `
@ -376,7 +378,7 @@ func Create(chartfile *chart.Metadata, dir string) (string, error) {
} }
} }
for _, d := range []string{TemplatesDir, ChartsDir} { for _, d := range []string{TemplatesDir, TemplatesTestsDir, ChartsDir} {
if err := os.MkdirAll(filepath.Join(cdir, d), 0755); err != nil { if err := os.MkdirAll(filepath.Join(cdir, d), 0755); err != nil {
return cdir, err return cdir, err
} }
@ -422,9 +424,9 @@ func Create(chartfile *chart.Metadata, dir string) (string, error) {
content: Transform(defaultHelpers, "<CHARTNAME>", chartfile.Name), content: Transform(defaultHelpers, "<CHARTNAME>", chartfile.Name),
}, },
{ {
// service-test.yaml // test-connection.yaml
path: filepath.Join(cdir, TemplatesDir, ServiceTestName), path: filepath.Join(cdir, TemplatesTestsDir, TestConnectionName),
content: Transform(defaultServiceTest, "<CHARTNAME>", chartfile.Name), content: Transform(defaultTestConnection, "<CHARTNAME>", chartfile.Name),
}, },
} }

@ -67,7 +67,7 @@ func TestCreate(t *testing.T) {
} }
} }
for _, f := range []string{NotesName, DeploymentName, ServiceName, HelpersName, ServiceTestName} { for _, f := range []string{NotesName, DeploymentName, ServiceName, HelpersName} {
if fi, err := os.Stat(filepath.Join(dir, TemplatesDir, f)); err != nil { if fi, err := os.Stat(filepath.Join(dir, TemplatesDir, f)); err != nil {
t.Errorf("Expected %s file: %s", f, err) t.Errorf("Expected %s file: %s", f, err)
} else if fi.IsDir() { } else if fi.IsDir() {
@ -75,6 +75,14 @@ func TestCreate(t *testing.T) {
} }
} }
for _, f := range []string{TestConnectionName} {
if fi, err := os.Stat(filepath.Join(dir, TemplatesTestsDir, f)); err != nil {
t.Errorf("Expected %s file: %s", f, err)
} else if fi.IsDir() {
t.Errorf("Expected %s to be a file.", f)
}
}
} }
func TestCreateFrom(t *testing.T) { func TestCreateFrom(t *testing.T) {

@ -54,7 +54,7 @@ func SaveDir(c *chart.Chart, dest string) error {
} }
} }
for _, d := range []string{TemplatesDir, ChartsDir} { for _, d := range []string{TemplatesDir, ChartsDir, TemplatesTestsDir} {
if err := os.MkdirAll(filepath.Join(outdir, d), 0755); err != nil { if err := os.MkdirAll(filepath.Join(outdir, d), 0755); err != nil {
return err return err
} }

Loading…
Cancel
Save