-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from kubeslice/rc-0.4.3
feat(): support for chart values with custom topology configuration
- Loading branch information
Showing
12 changed files
with
98 additions
and
24 deletions.
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
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
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package internal | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"strings" | ||
|
||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
func mergeMaps(dest, src map[interface{}]interface{}) map[interface{}]interface{} { | ||
for k, v := range src { | ||
if d, ok := dest[k]; ok { | ||
switch d.(type) { | ||
case map[interface{}]interface{}: | ||
dest[k] = mergeMaps(d.(map[interface{}]interface{}), v.(map[interface{}]interface{})) | ||
default: | ||
dest[k] = v | ||
} | ||
} else { | ||
dest[k] = v | ||
} | ||
} | ||
return dest | ||
} | ||
|
||
func generateValuesFile(filePath string, hc *HelmChart, defaults string) error { | ||
valuesMap := make(map[interface{}]interface{}) | ||
for k, v := range hc.Values { | ||
keys := strings.Split(k, ".") | ||
currentMap := valuesMap | ||
for i, key := range keys { | ||
if i == len(keys)-1 { | ||
currentMap[key] = v | ||
} else { | ||
if currentMap[key] == nil { | ||
currentMap[key] = make(map[interface{}]interface{}) | ||
} | ||
currentMap = currentMap[key].(map[interface{}]interface{}) | ||
} | ||
} | ||
} | ||
|
||
defaultsMap := make(map[interface{}]interface{}) | ||
if err := yaml.Unmarshal([]byte(defaults), &defaultsMap); err != nil { | ||
return fmt.Errorf("error parsing defaults: %v", err) | ||
} | ||
|
||
mergedMap := mergeMaps(valuesMap, defaultsMap) | ||
|
||
finalData, err := yaml.Marshal(mergedMap) | ||
if err != nil { | ||
return fmt.Errorf("error encoding final data as YAML: %v", err) | ||
} | ||
|
||
if err := ioutil.WriteFile(filePath, finalData, 0644); err != nil { | ||
return fmt.Errorf("error writing values file: %v", err) | ||
} | ||
|
||
return nil | ||
} |
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
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