Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
Ijaz Ahmad
ksonnet
Commits
9df426e8
Unverified
Commit
9df426e8
authored
Jul 13, 2018
by
bryanl
Browse files
render helm templates with multiple objects
Signed-off-by:
bryanl
<
bryanliles@gmail.com
>
parent
11938d61
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
37 deletions
+34
-37
pkg/actions/import.go
pkg/actions/import.go
+6
-1
pkg/helm/renderer.go
pkg/helm/renderer.go
+20
-4
pkg/util/yaml/yaml.go
pkg/util/yaml/yaml.go
+8
-32
No files found.
pkg/actions/import.go
View file @
9df426e8
...
...
@@ -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
}
...
...
pkg/helm/renderer.go
View file @
9df426e8
...
...
@@ -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
...
...
pkg/util/yaml/yaml.go
View file @
9df426e8
...
...
@@ -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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment