From 0ab836be78a9bd13986386209476e89b774a59f1 Mon Sep 17 00:00:00 2001 From: Sven Walter Date: Thu, 10 Aug 2017 16:50:19 +0200 Subject: [PATCH 1/3] add test for MakeSlice --- pkg/templates/render_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/templates/render_test.go b/pkg/templates/render_test.go index 12a45d4..1373060 100644 --- a/pkg/templates/render_test.go +++ b/pkg/templates/render_test.go @@ -7,6 +7,7 @@ func TestRender(t *testing.T) { template = ` branch: {{.branch}} commit: {{.sha}} + range: {{ $langs := MakeSlice "de" "fr" "nl" }}{{ range $langs }}{{.}}-{{end}} ` values = Variables{ "branch": "foobar", @@ -15,6 +16,7 @@ func TestRender(t *testing.T) { expected = ` branch: foobar commit: 123abc + range: de-fr-nl- ` ) From 049bed1cbf2e8fd8e410aad42cc335f33d276455 Mon Sep 17 00:00:00 2001 From: Sven Walter Date: Thu, 10 Aug 2017 16:54:02 +0200 Subject: [PATCH 2/3] add templating logs --- pkg/templates/render.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/templates/render.go b/pkg/templates/render.go index cb2e897..8c09045 100644 --- a/pkg/templates/render.go +++ b/pkg/templates/render.go @@ -6,6 +6,7 @@ import ( "text/template" "github.com/pkg/errors" + log "github.com/sirupsen/logrus" ) func RenderAll(templates map[string]string, variables Variables) (map[string]string, error) { @@ -43,5 +44,9 @@ func Render(templateString string, variables Variables) (string, error) { return "", errors.Wrapf(err, "Unable to render template") } + log.WithFields(log.Fields{ + "Result": buf.String(), + }).Debug("Rendered file") + return buf.String(), nil } From d07f301593b072e3eea8d1d870ed8b021997f7ee Mon Sep 17 00:00:00 2001 From: Sven Walter Date: Thu, 10 Aug 2017 17:31:15 +0200 Subject: [PATCH 3/3] support multiple manifests per file --- pkg/api/render.go | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/pkg/api/render.go b/pkg/api/render.go index 5f237d3..d4b9399 100644 --- a/pkg/api/render.go +++ b/pkg/api/render.go @@ -1,6 +1,7 @@ package api import ( + "regexp" "strings" "github.com/pkg/errors" @@ -39,24 +40,28 @@ func (app *App) Render(fetched *FetchResult) ([]runtime.Object, error) { continue } - if strings.TrimSpace(data) == "" { - log.WithFields(log.Fields{ - "Name": name, - }).Debug("Ignoring empty file.") - continue - } + splitted := regexp.MustCompile("[\n\r]---").Split(data, -1) - obj, _, err := decode([]byte(data), nil, nil) - if err != nil { - return nil, errors.Wrapf(err, "unable to decode file '%s'", name) - } + for _, part := range splitted { + if strings.TrimSpace(part) == "" { + log.WithFields(log.Fields{ + "Name": name, + }).Debug("Ignoring empty file.") + continue + } - obj, err = app.Interceptors.PostManifestRender(obj) - if err != nil { - return nil, errors.WithStack(err) - } + obj, _, err := decode([]byte(part), nil, nil) + if err != nil { + return nil, errors.Wrapf(err, "unable to decode file '%s'", name) + } - objects = append(objects, obj) + obj, err = app.Interceptors.PostManifestRender(obj) + if err != nil { + return nil, errors.WithStack(err) + } + + objects = append(objects, obj) + } } return objects, nil