diff --git a/controllers/clusters/helpers.go b/controllers/clusters/helpers.go index 6ee2bb09f..6c7f78b92 100644 --- a/controllers/clusters/helpers.go +++ b/controllers/clusters/helpers.go @@ -158,8 +158,36 @@ func getSortedAppVersions(versions []*models.AppVersions, appType string) []*ver return nil } +func removeRedundantFieldsFromSpec(k8sSpec interface{}, ignoreFields ...string) (string, error) { + k8sSpecJson, err := json.Marshal(k8sSpec) + if err != nil { + return "", err + } + + if len(ignoreFields) == 0 { + return string(k8sSpecJson), nil + } + + k8sSpecMap := map[string]interface{}{} + err = json.Unmarshal([]byte(string(k8sSpecJson)), &k8sSpecMap) + + if err != nil { + return "", err + } + + for _, field := range ignoreFields { + delete(k8sSpecMap, field) + } + + k8sSpecJson, err = json.Marshal(k8sSpecMap) + if err != nil { + return "", err + } + return string(k8sSpecJson), nil +} + func createSpecDifferenceMessage(k8sSpec, iSpec any) (string, error) { - k8sData, err := json.Marshal(k8sSpec) + k8sData, err := removeRedundantFieldsFromSpec(k8sSpec, "userRefs") if err != nil { return "", err }