From ab750f48aa002504a18602e29f18af561b52cfe0 Mon Sep 17 00:00:00 2001 From: Matt Moyer Date: Thu, 27 May 2021 17:09:12 -0500 Subject: [PATCH] When merging CredentialIssuer updates, don't overwrite LastUpdated. If the only thing that has changed about a strategy is the LastUpdated timestamp, then we should not update the object. Signed-off-by: Margo Crawford --- .../controller/issuerconfig/issuerconfig.go | 12 ++++++- .../issuerconfig/issuerconfig_test.go | 32 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/internal/controller/issuerconfig/issuerconfig.go b/internal/controller/issuerconfig/issuerconfig.go index b2440203..faa14695 100644 --- a/internal/controller/issuerconfig/issuerconfig.go +++ b/internal/controller/issuerconfig/issuerconfig.go @@ -42,7 +42,9 @@ func mergeStrategy(configToUpdate *v1alpha1.CredentialIssuerStatus, strategy v1a } } if existing != nil { - strategy.DeepCopyInto(existing) + if !equalExceptLastUpdated(existing, &strategy) { + strategy.DeepCopyInto(existing) + } } else { configToUpdate.Strategies = append(configToUpdate.Strategies, strategy) } @@ -75,3 +77,11 @@ func (s sortableStrategies) Less(i, j int) bool { return s[i].Type < s[j].Type } func (s sortableStrategies) Swap(i, j int) { s[i], s[j] = s[j], s[i] } + +func equalExceptLastUpdated(s1, s2 *v1alpha1.CredentialIssuerStrategy) bool { + s1 = s1.DeepCopy() + s2 = s2.DeepCopy() + s1.LastUpdateTime = metav1.Time{} + s2.LastUpdateTime = metav1.Time{} + return apiequality.Semantic.DeepEqual(s1, s2) +} diff --git a/internal/controller/issuerconfig/issuerconfig_test.go b/internal/controller/issuerconfig/issuerconfig_test.go index 16302499..1ef1600d 100644 --- a/internal/controller/issuerconfig/issuerconfig_test.go +++ b/internal/controller/issuerconfig/issuerconfig_test.go @@ -125,6 +125,38 @@ func TestMergeStrategy(t *testing.T) { }, }, }, + { + name: "existing entry matches except for LastUpdated time", + configToUpdate: v1alpha1.CredentialIssuerStatus{ + Strategies: []v1alpha1.CredentialIssuerStrategy{ + { + Type: "Type1", + Status: v1alpha1.ErrorStrategyStatus, + Reason: "some starting reason", + Message: "some starting message", + LastUpdateTime: t1, + }, + }, + }, + strategy: v1alpha1.CredentialIssuerStrategy{ + Type: "Type1", + Status: v1alpha1.ErrorStrategyStatus, + Reason: "some starting reason", + Message: "some starting message", + LastUpdateTime: t2, + }, + expected: v1alpha1.CredentialIssuerStatus{ + Strategies: []v1alpha1.CredentialIssuerStrategy{ + { + Type: "Type1", + Status: v1alpha1.ErrorStrategyStatus, + Reason: "some starting reason", + Message: "some starting message", + LastUpdateTime: t1, + }, + }, + }, + }, { name: "new entry among others", configToUpdate: v1alpha1.CredentialIssuerStatus{