Unverified Commit 9df426e8 authored by bryanl's avatar bryanl
Browse files

render helm templates with multiple objects


Signed-off-by: default avatarbryanl <bryanliles@gmail.com>
parent 11938d61
......@@ -206,7 +206,12 @@ func (i *Import) importFile(fileName string) error {
}
func (i *Import) createYAML(fileName, base, ext string) error {
readers, err := utilyaml.Decode(i.app.Fs(), fileName)
f, err := i.app.Fs().Open(fileName)
if err != nil {
return errors.Wrapf(err, "opening %q", fileName)
}
readers, err := utilyaml.Decode(f)
if err != nil {
return err
}
......
......@@ -17,6 +17,7 @@ package helm
import (
"fmt"
"io/ioutil"
"path/filepath"
"strings"
......@@ -25,6 +26,7 @@ import (
"github.com/google/go-jsonnet/ast"
"github.com/ksonnet/ksonnet/pkg/app"
ksstrings "github.com/ksonnet/ksonnet/pkg/util/strings"
utilyaml "github.com/ksonnet/ksonnet/pkg/util/yaml"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/version"
......@@ -148,12 +150,26 @@ func (r *Renderer) Render(repoName, chartName, chartVersion, componentName strin
if !ksstrings.InSlice(filepath.Ext(name), []string{".yaml", ".yml"}) {
continue
}
var m map[string]interface{}
if err := goyaml.Unmarshal([]byte(s), &m); err != nil {
return nil, errors.Wrapf(err, "unmarshalling %s", name)
r := strings.NewReader(s)
readers, err := utilyaml.Decode(r)
if err != nil {
return nil, err
}
out = append(out, m)
for _, r := range readers {
data, err := ioutil.ReadAll(r)
if err != nil {
return nil, err
}
var m map[string]interface{}
if err := goyaml.Unmarshal(data, &m); err != nil {
return nil, errors.Wrapf(err, "unmarshalling %s", name)
}
out = append(out, m)
}
}
return out, nil
......
......@@ -19,10 +19,6 @@ import (
"bufio"
"bytes"
"io"
"os"
"github.com/pkg/errors"
"github.com/spf13/afero"
)
const (
......@@ -30,16 +26,7 @@ const (
)
// Decode decodes YAML into one or more readers.
func Decode(fs afero.Fs, source string) ([]io.Reader, error) {
if err := checkSource(fs, source); err != nil {
return nil, errors.Wrap(err, "check source")
}
f, err := fs.Open(source)
if err != nil {
return nil, errors.Wrap(err, "open source")
}
defer f.Close()
func Decode(f io.Reader) ([]io.Reader, error) {
buffer := make([]bytes.Buffer, 1)
......@@ -51,8 +38,13 @@ func Decode(fs afero.Fs, source string) ([]io.Reader, error) {
continue
}
buffer[len(buffer)-1].WriteString(t)
buffer[len(buffer)-1].WriteByte('\n')
if _, err := buffer[len(buffer)-1].WriteString(t); err != nil {
return nil, err
}
if err := buffer[len(buffer)-1].WriteByte('\n'); err != nil {
return nil, err
}
}
var readers []io.Reader
......@@ -62,19 +54,3 @@ func Decode(fs afero.Fs, source string) ([]io.Reader, error) {
return readers, nil
}
func checkSource(fs afero.Fs, source string) error {
if source == "" {
return errors.New("source is empty")
}
if _, err := fs.Stat(source); err != nil {
if os.IsNotExist(err) {
return errors.Errorf("%q does not exist", source)
}
return errors.Wrap(err, "could not stat source")
}
return nil
}
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