Unverified Commit 3c629baf authored by Alexander Matyushentsev's avatar Alexander Matyushentsev Committed by GitHub
Browse files

refactor: support disabling legacy diffing logic (#3720)

* refactor: support disabling legacy diffing logic

* apply reviewer suggestion
No related merge requests found
Showing with 21 additions and 2 deletions
+21 -2
......@@ -27,6 +27,7 @@ import (
cacheutil "github.com/argoproj/argo-cd/util/cache"
appstatecache "github.com/argoproj/argo-cd/util/cache/appstate"
"github.com/argoproj/argo-cd/util/cli"
"github.com/argoproj/argo-cd/util/diff"
"github.com/argoproj/argo-cd/util/kube"
"github.com/argoproj/argo-cd/util/settings"
)
......@@ -81,6 +82,8 @@ func newCommand() *cobra.Command {
settingsMgr := settings.NewSettingsManager(ctx, kubeClient, namespace)
kubectl := &kube.KubectlCmd{}
legacyDiffDisabled := os.Getenv("ARGOCD_ENABLE_LEGACY_DIFF") == "false"
diff.SetPopulateLegacyDiff(!legacyDiffDisabled)
appController, err := controller.NewApplicationController(
namespace,
settingsMgr,
......
......@@ -27,6 +27,22 @@ import (
jsonutil "github.com/argoproj/argo-cd/util/json"
)
var (
emptyGoJSONDiff = gojsondiff.New().CompareObjects(map[string]interface{}{}, map[string]interface{}{})
populateLegacyDiff = true
)
func SetPopulateLegacyDiff(val bool) {
populateLegacyDiff = val
}
func calcGoJsonDiff(left map[string]interface{}, right map[string]interface{}) gojsondiff.Diff {
if !populateLegacyDiff {
return emptyGoJSONDiff
}
return gojsondiff.New().CompareObjects(left, right)
}
type DiffResult struct {
// Deprecated: Use PredictedLive and NormalizedLive instead
Diff gojsondiff.Diff
......@@ -76,7 +92,7 @@ func getLegacyTwoWayDiff(config, live *unstructured.Unstructured) gojsondiff.Dif
if live != nil {
liveObj = jsonutil.RemoveMapFields(configObj, live.Object)
}
return gojsondiff.New().CompareObjects(liveObj, configObj)
return calcGoJsonDiff(liveObj, configObj)
}
// TwoWayDiff performs a three-way diff and uses specified config as a recently applied config
......@@ -150,7 +166,7 @@ func ThreeWayDiff(orig, config, live *unstructured.Unstructured) (*DiffResult, e
NormalizedLive: liveBytes,
Modified: string(predictedLiveBytes) != string(liveBytes),
// legacy diff for backward compatibility
Diff: gojsondiff.New().CompareObjects(live.Object, predictedLive.Object),
Diff: calcGoJsonDiff(live.Object, predictedLive.Object),
}
return &dr, nil
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment