Skip to content

Commit

Permalink
Manually load the dependencies for the linkerd2 and patch charts to
Browse files Browse the repository at this point in the history
avoid requiring the build environments to have `helm` installed.

Signed-off-by: Alejandro Pedraza <alejandro@buoyant.io>
  • Loading branch information
alpeb committed Aug 5, 2019
1 parent 8cf5b42 commit 41c64f1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
49 changes: 31 additions & 18 deletions pkg/charts/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,24 @@ type Chart struct {

// Render returns a bytes buffer with the result of rendering a Helm chart
func (chart *Chart) Render() (bytes.Buffer, error) {
// Read templates into bytes
for _, f := range chart.Files {
data, err := readIntoBytes(chart.Dir + "/" + f.Name)
if err != nil {
return bytes.Buffer{}, err
}
f.Data = data
chart.filesReader(chart.Dir+"/", chart.Files)

// Keep this slice synced with the contents of /charts/partials
partialsFiles := []*chartutil.BufferedFile{
{Name: "charts/partials/" + chartutil.ChartfileName},
{Name: "charts/partials/templates/_proxy.tpl"},
{Name: "charts/partials/templates/_proxy-init.tpl"},
{Name: "charts/partials/templates/_volumes.tpl"},
{Name: "charts/partials/templates/_resources.tpl"},
{Name: "charts/partials/templates/_metadata.tpl"},
{Name: "charts/partials/templates/_helpers.tpl"},
{Name: "charts/partials/templates/_debug.tpl"},
{Name: "charts/partials/templates/_capabilities.tpl"},
}
chart.filesReader("", partialsFiles)

// Create chart and render templates
chrt, err := chartutil.LoadFiles(chart.Files)
chrt, err := chartutil.LoadFiles(append(chart.Files, partialsFiles...))
if err != nil {
return bytes.Buffer{}, err
}
Expand Down Expand Up @@ -66,16 +73,22 @@ func (chart *Chart) Render() (bytes.Buffer, error) {
return buf, nil
}

func readIntoBytes(filename string) ([]byte, error) {
// TODO: remove `chart/` after `linkerd install` starts using `/charts`
file, err := static.Templates.Open(filename)
if err != nil {
return nil, err
}
defer file.Close()
func (chart *Chart) filesReader(dir string, files []*chartutil.BufferedFile) error {
for _, f := range files {
filename := dir + f.Name
if dir == "" {
filename = filename[7:]
}
file, err := static.Templates.Open(filename)
if err != nil {
return err
}
defer file.Close()

buf := new(bytes.Buffer)
buf.ReadFrom(file)
buf := new(bytes.Buffer)
buf.ReadFrom(file)

return buf.Bytes(), nil
f.Data = buf.Bytes()
}
return nil
}
1 change: 0 additions & 1 deletion pkg/inject/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ func (conf *ResourceConfig) GetPatch(injectProxy bool) ([]byte, error) {
{Name: chartutil.ChartfileName},
{Name: "requirements.yaml"},
{Name: "templates/patch.json"},
{Name: "charts/partials-0.1.0.tgz"},
}

chart := &charts.Chart{
Expand Down

0 comments on commit 41c64f1

Please sign in to comment.