1
0
mirror of https://github.com/rancher/types.git synced 2025-09-12 13:03:45 +00:00

sort env key

Problems:
When we created workloads in rancher api, the environment variable
field is converted without a specific order.(we simplely loop in the
map). This will cause K8s workload spec to change constantly if we do a
update, and cause the pod getting recreated.
Solutions:
Sort the map and make sure they always follow the same order in k8s
workload spec.
This commit is contained in:
Daishan Peng
2018-07-26 11:41:44 -07:00
committed by Craig Jellick
parent 0968d09296
commit 728ef5c4b9

View File

@@ -1,6 +1,8 @@
package mapper
import (
"sort"
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
"k8s.io/api/core/v1"
@@ -98,10 +100,16 @@ func (e EnvironmentMapper) ToInternal(data map[string]interface{}) error {
var envVar []map[string]interface{}
var envVarFrom []map[string]interface{}
for key, value := range convert.ToMapInterface(data["environment"]) {
var orderedKeys []string
environment := convert.ToMapInterface(data["environment"])
for k := range environment {
orderedKeys = append(orderedKeys, k)
}
sort.Strings(orderedKeys)
for _, key := range orderedKeys {
envVar = append(envVar, map[string]interface{}{
"name": key,
"value": value,
"value": environment[key],
})
}