normalizeApplication normalizes an application.spec and additionally persists updates if it changed
(app *appv1.Application)
| 2091 | |
| 2092 | // normalizeApplication normalizes an application.spec and additionally persists updates if it changed |
| 2093 | func (ctrl *ApplicationController) normalizeApplication(app *appv1.Application) { |
| 2094 | orig := app.DeepCopy() |
| 2095 | app.Spec = *argo.NormalizeApplicationSpec(&app.Spec) |
| 2096 | logCtx := log.WithFields(applog.GetAppLogFields(app)) |
| 2097 | |
| 2098 | patch, modified, err := diff.CreateTwoWayMergePatch(orig, app, appv1.Application{}) |
| 2099 | |
| 2100 | if err != nil { |
| 2101 | logCtx.WithError(err).Error("error constructing app spec patch") |
| 2102 | } else if modified { |
| 2103 | _, err := ctrl.PatchAppWithWriteBack(context.Background(), app.Name, app.Namespace, types.MergePatchType, patch, metav1.PatchOptions{}) |
| 2104 | if err != nil { |
| 2105 | logCtx.WithError(err).Error("Error persisting normalized application spec") |
| 2106 | } else { |
| 2107 | logCtx.Infof("Normalized app spec: %s", string(patch)) |
| 2108 | } |
| 2109 | } |
| 2110 | } |
| 2111 | |
| 2112 | func createMergePatch(orig, newV any) ([]byte, bool, error) { |
| 2113 | origBytes, err := json.Marshal(orig) |
no test coverage detected