Skip to content

Commit

Permalink
self using and fix broken yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Lazarev committed Sep 8, 2021
1 parent 24e06df commit 8d2f9a0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ myapp:

## Notes

go template [Actions](https://pkg.go.dev/text/template#hdr-Actions) could be used but yaml should we readable for yaml-parsers. So easest way to do it is using comment befor actions "#"
v0.1.3
- fixed all from previous(0.1.2) note
- could use "self" in importValuesFrom

v0.1.2
- go template [Actions](https://pkg.go.dev/text/template#hdr-Actions) could be used but yaml should we readable for yaml-parsers. So easest way to do it is using comment befor actions "#"
like this:
```
myapp:
Expand All @@ -38,4 +43,4 @@ myapp:
# {{end }}
```

Don't use helm function for trim sapces "{{-" or "-}}" - it isn't implemented
- Don't use helm function for trim sapces "{{-" or "-}}" - it isn't implemented
15 changes: 12 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,22 @@ func readFile(file string) []byte {

// Get file list from importValuesFrom
func GetValuesFiles(file string) ImportValues {
yamlFiles := readFile(file)
rawFile := readFile(file)
yamlFiles := strings.ReplaceAll(string(rawFile), "{{", "#{{")
data := ImportValues{}
err := yaml.Unmarshal(yamlFiles, &data)
err := yaml.Unmarshal([]byte(yamlFiles), &data)
if err != nil {
errLog.Fatalf("Error GetValuesFiles: Can't parse file: \"%s\"; stack:\"%v\"", file, err)
}
if len(data.ImportValues) < 1 {
println("There is no import values.")
} else {
for i, source := range data.ImportValues {
if source == "self" {
data.ImportValues[i] = filepath.Base(file)
println("There is itself using for values.")
}
}
}
return data
}
Expand All @@ -68,7 +76,8 @@ func GetValuesFiles(file string) ImportValues {
func ReadValues(valuesFiles ImportValues, dir string) (vals Values) {
vals = make(map[string]interface{})
for _, file := range valuesFiles.ImportValues {
yamlFiles := readFile(filepath.Join(dir, file))
rawFile := readFile(filepath.Join(dir, file))
yamlFiles := strings.ReplaceAll(string(rawFile), "{{", "#{{")
data := make(map[string]interface{})
err := yaml.Unmarshal([]byte(yamlFiles), &data)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions test/template-values.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
importValuesFrom:
- base-values1.yaml
- base-values2.yaml
- self

default: qwerty
myapp:
cluster: {{ .Values.clusterName }}
enabled: {{ .Values.enabled }}
controller:
autoscaling:
enabled: true
minReplicas: {{ .Values.defaults.minReplicas }}
{{- if .Values.default }}
run: {{ .Values.default }}
{{- end -}}

resources: {{ toYaml .Values.defaults.resources | nindent 6 }}

0 comments on commit 8d2f9a0

Please sign in to comment.