Skip to content

Commit

Permalink
issue-544, refactor externalChanges message
Browse files Browse the repository at this point in the history
  • Loading branch information
OleksiienkoMykyta committed Dec 1, 2023
1 parent 64d2342 commit fe82e0b
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion controllers/clusters/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit fe82e0b

Please sign in to comment.