mirror of
https://github.com/rancher/os.git
synced 2025-09-05 16:52:20 +00:00
Updated hash based on comments
This commit is contained in:
@@ -57,9 +57,6 @@ func getHash(containerCfg *config.ContainerConfig) (string, error) {
|
|||||||
//Create a data structure of map of values keyed by a string
|
//Create a data structure of map of values keyed by a string
|
||||||
unsortedKeyValue := make(map[string]interface{})
|
unsortedKeyValue := make(map[string]interface{})
|
||||||
|
|
||||||
//Create a data structure of map of type keyed by a string
|
|
||||||
unsortedKeyType := make(map[string]reflect.Type)
|
|
||||||
|
|
||||||
//Get all keys and values in Service Configuration
|
//Get all keys and values in Service Configuration
|
||||||
for i := 0; i < val.NumField(); i++ {
|
for i := 0; i < val.NumField(); i++ {
|
||||||
valueField := val.Field(i)
|
valueField := val.Field(i)
|
||||||
@@ -67,47 +64,44 @@ func getHash(containerCfg *config.ContainerConfig) (string, error) {
|
|||||||
|
|
||||||
serviceKeys = append(serviceKeys, keyField.Name)
|
serviceKeys = append(serviceKeys, keyField.Name)
|
||||||
unsortedKeyValue[keyField.Name] = valueField.Interface()
|
unsortedKeyValue[keyField.Name] = valueField.Interface()
|
||||||
unsortedKeyType[keyField.Name] = valueField.Type()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Sort serviceKeys alphabetically
|
//Sort serviceKeys alphabetically
|
||||||
sort.Strings(serviceKeys)
|
sort.Strings(serviceKeys)
|
||||||
|
|
||||||
//New slice to sort through Keys
|
|
||||||
//var sliceKeys []string
|
|
||||||
|
|
||||||
//Go through keys and write hash
|
//Go through keys and write hash
|
||||||
for i := 0; i < len(serviceKeys); i++ {
|
for i := 0; i < len(serviceKeys); i++ {
|
||||||
serviceValue := unsortedKeyValue[serviceKeys[i]]
|
serviceValue := unsortedKeyValue[serviceKeys[i]]
|
||||||
serviceType := unsortedKeyType[serviceKeys[i]]
|
|
||||||
sliceKeys := []string{}
|
sliceKeys := []string{}
|
||||||
|
|
||||||
//Only need to check for Labels key as it's a Map and write hash after sorting the label names
|
switch s := serviceValue.(type) {
|
||||||
if serviceType == reflect.TypeOf(project.NewSliceorMap(make(map[string]string))) {
|
default:
|
||||||
for lkey := range serviceValue.(*project.SliceorMap).MapParts() {
|
w.Write([]byte(fmt.Sprintf("%v", serviceValue)))
|
||||||
|
case *project.SliceorMap:
|
||||||
|
for lkey := range s.MapParts() {
|
||||||
|
if lkey != "io.rancher.os.hash" {
|
||||||
sliceKeys = append(sliceKeys, lkey)
|
sliceKeys = append(sliceKeys, lkey)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
sort.Strings(sliceKeys)
|
sort.Strings(sliceKeys)
|
||||||
|
|
||||||
for j := 0; j < len(sliceKeys); j++ {
|
for j := 0; j < len(sliceKeys); j++ {
|
||||||
w.Write([]byte(fmt.Sprintf("%s%v", sliceKeys[j], serviceValue.(*project.SliceorMap).MapParts()[sliceKeys[j]])))
|
w.Write([]byte(fmt.Sprintf("%s=%v", sliceKeys[j], s.MapParts()[sliceKeys[j]])))
|
||||||
}
|
}
|
||||||
} else if serviceType == reflect.TypeOf(project.NewStringorslice("TestString")) {
|
case *project.Stringorslice:
|
||||||
sliceKeys = serviceValue.(*project.Stringorslice).Slice()
|
sliceKeys = s.Slice()
|
||||||
sort.Strings(sliceKeys)
|
sort.Strings(sliceKeys)
|
||||||
|
|
||||||
for j := 0; j < len(sliceKeys); j++ {
|
for j := 0; j < len(sliceKeys); j++ {
|
||||||
w.Write([]byte(fmt.Sprintf("%s", sliceKeys[j])))
|
w.Write([]byte(fmt.Sprintf("%s", sliceKeys[j])))
|
||||||
}
|
}
|
||||||
} else if v, ok := serviceValue.([]string); ok {
|
case []string:
|
||||||
sliceKeys = v
|
sliceKeys = s
|
||||||
sort.Strings(sliceKeys)
|
sort.Strings(sliceKeys)
|
||||||
|
|
||||||
for j := 0; j < len(sliceKeys); j++ {
|
for j := 0; j < len(sliceKeys); j++ {
|
||||||
w.Write([]byte(fmt.Sprintf("%s", sliceKeys[j])))
|
w.Write([]byte(fmt.Sprintf("%s", sliceKeys[j])))
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
w.Write([]byte(fmt.Sprintf("%v", serviceValue)))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user