-
Notifications
You must be signed in to change notification settings - Fork 372
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 #474 from jnummelin/fix-helm-values-parsing
Fix Helm values parsing
- Loading branch information
Showing
4 changed files
with
116 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ bindata | |
*.tfstate* | ||
aws_private.pem | ||
out.json | ||
.vscode |
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,66 @@ | ||
/* | ||
Copyright 2020 Mirantis, Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package v1beta1 | ||
|
||
import "fmt" | ||
|
||
// Cleans up a slice of interfaces into slice of actual values | ||
func cleanUpInterfaceArray(in []interface{}) []interface{} { | ||
result := make([]interface{}, len(in)) | ||
for i, v := range in { | ||
result[i] = cleanUpMapValue(v) | ||
} | ||
return result | ||
} | ||
|
||
// Cleans up the map keys to be strings | ||
func cleanUpInterfaceMap(in map[interface{}]interface{}) map[string]interface{} { | ||
result := make(map[string]interface{}) | ||
for k, v := range in { | ||
result[fmt.Sprintf("%v", k)] = cleanUpMapValue(v) | ||
} | ||
return result | ||
} | ||
|
||
// Cleans up the value in the map, recurses in case of arrays and maps | ||
func cleanUpMapValue(v interface{}) interface{} { | ||
switch v := v.(type) { | ||
case []interface{}: | ||
return cleanUpInterfaceArray(v) | ||
case map[interface{}]interface{}: | ||
return cleanUpInterfaceMap(v) | ||
case string: | ||
return v | ||
case int: | ||
return v | ||
case bool: | ||
return v | ||
case float64: | ||
return v | ||
default: | ||
return fmt.Sprintf("%v", v) | ||
} | ||
} | ||
|
||
// CleanUpGenericMap is a helper to "cleanup" generic yaml parsing where nested maps | ||
// are unmarshalled with type map[interface{}]interface{} | ||
func CleanUpGenericMap(in map[string]interface{}) map[string]interface{} { | ||
result := make(map[string]interface{}) | ||
for k, v := range in { | ||
result[fmt.Sprintf("%v", k)] = cleanUpMapValue(v) | ||
} | ||
return result | ||
} |