From 2f4d86d94c591a9b6384d58acff328173f9c7a4e Mon Sep 17 00:00:00 2001 From: Martin Hickey Date: Fri, 24 Aug 2018 14:30:56 +0100 Subject: [PATCH] Add test template example for helm create As helm create ganerates an nginx chart, the example is based on https://github.com/helm/helm/blob/master/docs/examples/nginx/templates/ service-test.yaml Signed-off-by: Martin Hickey --- cmd/helm/create_test.go | 4 ++-- pkg/chartutil/create.go | 29 ++++++++++++++++++++++++++++- pkg/chartutil/create_test.go | 2 +- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/cmd/helm/create_test.go b/cmd/helm/create_test.go index 214432b83..3cdf5ebf8 100644 --- a/cmd/helm/create_test.go +++ b/cmd/helm/create_test.go @@ -143,8 +143,8 @@ func TestCreateStarterCmd(t *testing.T) { t.Errorf("Wrong API version: %q", c.Metadata.ApiVersion) } - if l := len(c.Templates); l != 6 { - t.Errorf("Expected 5 templates, got %d", l) + if l := len(c.Templates); l != 7 { + t.Errorf("Expected 6 templates, got %d", l) } found := false diff --git a/pkg/chartutil/create.go b/pkg/chartutil/create.go index 43fb5f7d3..89c9da589 100644 --- a/pkg/chartutil/create.go +++ b/pkg/chartutil/create.go @@ -44,8 +44,10 @@ const ( ServiceName = "service.yaml" // NotesName is the name of the example NOTES.txt file. NotesName = "NOTES.txt" - // HelpersName is the name of the example NOTES.txt file. + // HelpersName is the name of the example helpers file. HelpersName = "_helpers.tpl" + // ServiceTestName is the name of the example test service file. + ServiceTestName = "service-test.yaml" ) const defaultValues = `# Default values for %s. @@ -290,6 +292,26 @@ Create chart name and version as used by the chart label. {{- end -}} ` +const defaultServiceTest = `apiVersion: v1 +kind: Pod +metadata: + name: "{{ template ".fullname" . }}-service-test" + labels: + heritage: {{ .Release.Service }} + release: {{ .Release.Name }} + chart: {{ .Chart.Name }}-{{ .Chart.Version }} + app: {{ template ".name" . }} + annotations: + "helm.sh/hook": test-success +spec: + containers: + - name: curl + image: radial/busyboxplus:curl + command: ['curl'] + args: ['{{ template ".fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never +` + // CreateFrom creates a new chart, but scaffolds it from the src chart. func CreateFrom(chartfile *chart.Metadata, dest string, src string) error { schart, err := Load(src) @@ -399,6 +421,11 @@ func Create(chartfile *chart.Metadata, dir string) (string, error) { path: filepath.Join(cdir, TemplatesDir, HelpersName), content: Transform(defaultHelpers, "", chartfile.Name), }, + { + // service-test.yaml + path: filepath.Join(cdir, TemplatesDir, ServiceTestName), + content: Transform(defaultServiceTest, "", chartfile.Name), + }, } for _, file := range files { diff --git a/pkg/chartutil/create_test.go b/pkg/chartutil/create_test.go index 96c467e7e..d4b41fd4b 100644 --- a/pkg/chartutil/create_test.go +++ b/pkg/chartutil/create_test.go @@ -67,7 +67,7 @@ func TestCreate(t *testing.T) { } } - for _, f := range []string{NotesName, DeploymentName, ServiceName, HelpersName} { + for _, f := range []string{NotesName, DeploymentName, ServiceName, HelpersName, ServiceTestName} { if fi, err := os.Stat(filepath.Join(dir, TemplatesDir, f)); err != nil { t.Errorf("Expected %s file: %s", f, err) } else if fi.IsDir() {