This repository has been archived by the owner on Sep 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 295
Inject stack name into userdata for nodepool workers #735
Merged
mumoshu
merged 2 commits into
kubernetes-retired:master
from
HotelsDotCom:fix-nodepool-tagging
Jul 5, 2017
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package texttemplate | |
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"github.com/Masterminds/sprig" | ||
"io/ioutil" | ||
|
@@ -21,9 +22,27 @@ func Parse(filename string, funcs template.FuncMap) (*template.Template, error) | |
} | ||
return content, nil | ||
}, | ||
"toJSON": func(v interface{}) (string, error) { | ||
data, err := json.Marshal(v) | ||
return string(data), err | ||
}, | ||
"execTemplate": func(name string, ctx interface{}) (string, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that is a workaround for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, good to know! Thanks 😄 |
||
panic("[bug] Stub 'execTemplate' was not replaced") | ||
}, | ||
} | ||
|
||
t, err := template.New(filename).Funcs(sprig.HermeticTxtFuncMap()).Funcs(funcs).Funcs(funcs2).Parse(string(raw)) | ||
if err == nil { | ||
t = t.Funcs(template.FuncMap{ | ||
"execTemplate": func(name string, ctx interface{}) (string, error) { | ||
b := bytes.Buffer{} | ||
err := t.ExecuteTemplate(&b, name, ctx) | ||
return b.String(), err | ||
}, | ||
}) | ||
} | ||
return t, err | ||
|
||
return template.New(filename).Funcs(sprig.HermeticTxtFuncMap()).Funcs(funcs).Funcs(funcs2).Parse(string(raw)) | ||
} | ||
|
||
func GetBytesBuffer(filename string, data interface{}) (*bytes.Buffer, error) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toJson
is already available throughMasterminds/sprig
according to https://github.com/Masterminds/sprig/blob/dba49a8d3a46ae8522f79e2c0241842d6ab613ca/defaults.go#L66Could we use the one from sprig instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't check if it exists in a code, because it is undocumented on their godoc page: https://godoc.org/github.com/Masterminds/sprig
so I am not sure we can rely on it being available all the time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@redbaron I believe we can expect it to remain to be existing because it is used widely in many helm charts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they use their own version: https://github.com/kubernetes/helm/blob/dece57e0baa94abdba22c0e3ced0b6ea64a83afd/pkg/engine/engine.go#L82
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the good catch 👍 Let me also add that both sprig's and helm's implementations of
toJson
seems to swallow errors, which sounds problematic to me. I'm now convinced to have our own implementation!