From 76b29664c6b9af4cba9772d3e36f644d26d52f35 Mon Sep 17 00:00:00 2001 From: Feggah Date: Sat, 1 Oct 2022 16:26:54 -0300 Subject: [PATCH] Convert messageRetentionDuration to time.Duration in comparisons Signed-off-by: Feggah --- pkg/clients/topic/topic.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/pkg/clients/topic/topic.go b/pkg/clients/topic/topic.go index 092c0de74..1e39368e4 100644 --- a/pkg/clients/topic/topic.go +++ b/pkg/clients/topic/topic.go @@ -19,8 +19,10 @@ package topic import ( "fmt" "strings" + "time" "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" pubsub "google.golang.org/api/pubsub/v1" "github.com/crossplane-contrib/provider-gcp/apis/pubsub/v1alpha1" @@ -78,7 +80,26 @@ func LateInitialize(s *v1alpha1.TopicParameters, t pubsub.Topic) { func IsUpToDate(s v1alpha1.TopicParameters, t pubsub.Topic) bool { observed := &v1alpha1.TopicParameters{} LateInitialize(observed, t) - return cmp.Equal(observed, &s) + + observedDuration := convertDuration(observed.MessageRetentionDuration) + sDuration := convertDuration(s.MessageRetentionDuration) + if observedDuration != sDuration { + return false + } + + return cmp.Equal(observed, &s, cmpopts.IgnoreFields(v1alpha1.TopicParameters{}, "MessageRetentionDuration")) +} + +func convertDuration(duration *string) time.Duration { + if duration == nil { + return 0 + } + + // From here we know that "duration" has a valid duration string + // format because of the kubebuilder Pattern validator, so we can + // ignore time.ParseDuration errors + d, _ := time.ParseDuration(*duration) + return d } // GenerateUpdateRequest produces an UpdateTopicRequest with the difference