Skip to content

Commit

Permalink
migrate resource field comparisons away from go-cmp
Browse files Browse the repository at this point in the history
  • Loading branch information
rosstimothy committed Oct 7, 2024
1 parent 55c53e1 commit a6a0006
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions lib/services/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ package services
import (
"encoding/json"
"fmt"
"maps"
"slices"
"time"

"github.com/google/go-cmp/cmp"
"github.com/gravitational/trace"

apidefaults "github.com/gravitational/teleport/api/defaults"
"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/api/types/wrappers"
apiutils "github.com/gravitational/teleport/api/utils"
"github.com/gravitational/teleport/lib/defaults"
"github.com/gravitational/teleport/lib/utils"
Expand Down Expand Up @@ -111,14 +114,16 @@ func compareServers(a, b types.Server) int {
if !utils.StringMapsEqual(a.GetStaticLabels(), b.GetStaticLabels()) {
return Different
}
if !cmp.Equal(a.GetCmdLabels(), b.GetCmdLabels()) {
if !maps.EqualFunc(a.GetCmdLabels(), b.GetCmdLabels(), func(label types.CommandLabel, label2 types.CommandLabel) bool {
return label.GetResult() == label2.GetResult()
}) {
return Different
}
if a.GetTeleportVersion() != b.GetTeleportVersion() {
return Different
}

if !cmp.Equal(a.GetProxyIDs(), b.GetProxyIDs()) {
if !slices.Equal(a.GetProxyIDs(), b.GetProxyIDs()) {
return Different
}
// OnlyTimestampsDifferent check must be after all Different checks.
Expand Down Expand Up @@ -148,7 +153,7 @@ func compareApplicationServers(a, b types.AppServer) int {
if !cmp.Equal(a.GetApp(), b.GetApp()) {
return Different
}
if !cmp.Equal(a.GetProxyIDs(), b.GetProxyIDs()) {
if !slices.Equal(a.GetProxyIDs(), b.GetProxyIDs()) {
return Different
}
// OnlyTimestampsDifferent check must be after all Different checks.
Expand All @@ -168,7 +173,14 @@ func compareDatabaseServices(a, b types.DatabaseService) int {
if a.GetNamespace() != b.GetNamespace() {
return Different
}
if !cmp.Equal(a.GetResourceMatchers(), b.GetResourceMatchers()) {
if !slices.EqualFunc(a.GetResourceMatchers(), b.GetResourceMatchers(),
func(matcher *types.DatabaseResourceMatcher, matcher2 *types.DatabaseResourceMatcher) bool {
return matcher.AWS.AssumeRoleARN == matcher2.AWS.AssumeRoleARN &&
maps.EqualFunc(matcher.Labels.ToProto().Values, matcher2.Labels.ToProto().Values,
func(values wrappers.StringValues, values2 wrappers.StringValues) bool {
return slices.Equal(values.Values, values2.Values)
})
}) {
return Different
}
if !a.Expiry().Equal(b.Expiry()) {
Expand Down Expand Up @@ -197,7 +209,7 @@ func compareKubernetesServers(a, b types.KubeServer) int {
if !cmp.Equal(a.GetCluster(), b.GetCluster()) {
return Different
}
if !cmp.Equal(a.GetProxyIDs(), b.GetProxyIDs()) {
if !slices.Equal(a.GetProxyIDs(), b.GetProxyIDs()) {
return Different
}
// OnlyTimestampsDifferent check must be after all Different checks.
Expand Down Expand Up @@ -227,7 +239,7 @@ func compareDatabaseServers(a, b types.DatabaseServer) int {
if !cmp.Equal(a.GetDatabase(), b.GetDatabase()) {
return Different
}
if !cmp.Equal(a.GetProxyIDs(), b.GetProxyIDs()) {
if !slices.Equal(a.GetProxyIDs(), b.GetProxyIDs()) {
return Different
}
// OnlyTimestampsDifferent check must be after all Different checks.
Expand All @@ -250,7 +262,7 @@ func compareWindowsDesktopServices(a, b types.WindowsDesktopService) int {
if a.GetTeleportVersion() != b.GetTeleportVersion() {
return Different
}
if !cmp.Equal(a.GetProxyIDs(), b.GetProxyIDs()) {
if !slices.Equal(a.GetProxyIDs(), b.GetProxyIDs()) {
return Different
}
// OnlyTimestampsDifferent check must be after all Different checks.
Expand Down

0 comments on commit a6a0006

Please sign in to comment.