Skip to content

Commit

Permalink
Convert messageRetentionDuration to time.Duration in comparisons
Browse files Browse the repository at this point in the history
Signed-off-by: Feggah <[email protected]>
  • Loading branch information
Feggah committed Oct 10, 2022
1 parent bac1e2a commit 76b2966
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion pkg/clients/topic/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 76b2966

Please sign in to comment.