Skip to content

Commit

Permalink
fix: follow up for the relative paths improvement (roboll#262)
Browse files Browse the repository at this point in the history
Fixes for the bugs that are introduced by roboll#261, that is values.yaml files specified in `values:` have redundant base path in their prefixes, and remaining .dec files after secrets decryption(roboll#251 (comment))
  • Loading branch information
mumoshu authored Aug 30, 2018
1 parent 421299c commit bb3b44e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
11 changes: 10 additions & 1 deletion helmexec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ func (helm *execer) DecryptSecret(name string) (string, error) {
// os.Rename seems to results in "cross-device link` errors in some cases
// Instead of moving, copy it to the destination temp file as a work-around
// See https://github.com/roboll/helmfile/issues/251#issuecomment-417166296f
decFile, err := os.Open(name + ".dec")
decFilename := name + ".dec"
decFile, err := os.Open(decFilename)
if err != nil {
return "", err
}
Expand All @@ -131,6 +132,14 @@ func (helm *execer) DecryptSecret(name string) (string, error) {
return "", err
}

if err := decFile.Close(); err != nil {
return "", err
}

if err := os.Remove(decFilename); err != nil {
return "", err
}

return tmpFile.Name(), err
}

Expand Down
1 change: 1 addition & 0 deletions tmpl/context.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tmpl

type Context struct {
basePath string
readFile func(string) ([]byte, error)
}
9 changes: 2 additions & 7 deletions tmpl/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package tmpl

import (
"bytes"
"path/filepath"
)

type templateFileRenderer struct {
basePath string
ReadFile func(string) ([]byte, error)
Context *Context
}
Expand All @@ -17,19 +15,16 @@ type FileRenderer interface {

func NewFileRenderer(readFile func(filename string) ([]byte, error), basePath string) *templateFileRenderer {
return &templateFileRenderer{
basePath: basePath,
ReadFile: readFile,
Context: &Context{
basePath: basePath,
readFile: readFile,
},
}
}

func (r *templateFileRenderer) RenderTemplateFileToBuffer(file string) (*bytes.Buffer, error) {
// path to the file relative to the helmfile.yaml
path := filepath.Join(r.basePath, file)

content, err := r.ReadFile(path)
content, err := r.ReadFile(file)
if err != nil {
return nil, err
}
Expand Down
5 changes: 4 additions & 1 deletion tmpl/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"gopkg.in/yaml.v2"
"os"
"path/filepath"
"strings"
"text/template"
)
Expand All @@ -21,7 +22,9 @@ func (c *Context) createFuncMap() template.FuncMap {
}

func (c *Context) ReadFile(filename string) (string, error) {
bytes, err := c.readFile(filename)
path := filepath.Join(c.basePath, filename)

bytes, err := c.readFile(path)
if err != nil {
return "", err
}
Expand Down

0 comments on commit bb3b44e

Please sign in to comment.