Use consistent field order to generate installStrategy ID
@@ -27,6 +27,7 @@ import (
"os"
"reflect"
"regexp"
+ "sort"
"strings"
k8sv1 "k8s.io/api/core/v1"
@@ -359,15 +360,47 @@ func (c *KubeVirtDeploymentConfig) generateInstallStrategyID() {
// changeable properties from the KubeVirt CR. This will be used for identifying the correct install strategy job
// and configmap
// Calculate a sha over all those properties
-
hasher := sha1.New()
-
- version := fmt.Sprintf("%+v", c)
- hasher.Write([]byte(version))
+ values := c.getStringFromFields()
+ hasher.Write([]byte(values))
c.ID = hex.EncodeToString(hasher.Sum(nil))
}
+func (c *KubeVirtDeploymentConfig) getStringFromFields() string {
+ result := ""
+ v := reflect.ValueOf(*c)
+ for i := 0; i < v.NumField(); i++ {
+ fieldName := v.Type().Field(i).Name
+ result += fieldName
+ field := v.Field(i)
+ if field.Type().Kind() == reflect.Map {
+ keys := field.MapKeys()
+ nameKeys := make(map[string]reflect.Value, len(keys))
+ names := make([]string, 0, len(keys))
+ for _, key := range keys {
+ name := key.String()
+ if name == "" {
+ continue
+ }
+ nameKeys[name] = key
+ names = append(names, name)
+ }
+ sort.Strings(names)
+ for _, name := range names {
+ key := nameKeys[name]
+ val := field.MapIndex(key).String()
+ result += name
+ result += val
+ }
+ } else {
+ value := v.Field(i).String()
+ result += value
+ }
+ }
+ return result
+}
+
func (c *KubeVirtDeploymentConfig) GetDeploymentID() string {
return c.ID
}
