Skip to content

Commit

Permalink
fix: correctly compare application destinations with inferred cluster…
Browse files Browse the repository at this point in the history
… URL (#4937)

Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
  • Loading branch information
Alexander Matyushentsev committed Dec 1, 2020
1 parent 6095fc5 commit c108e2f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/apis/application/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2423,6 +2423,17 @@ func (source *ApplicationSource) ExplicitType() (*ApplicationSourceType, error)

// Equals compares two instances of ApplicationDestination and return true if instances are equal.
func (dest ApplicationDestination) Equals(other ApplicationDestination) bool {
// ignore destination cluster name and isServerInferred fields during comparison
// since server URL is inferred from cluster name
if dest.isServerInferred {
dest.Server = ""
dest.isServerInferred = false
}

if other.isServerInferred {
other.Server = ""
other.isServerInferred = false
}
return reflect.DeepEqual(dest, other)
}

Expand Down
15 changes: 15 additions & 0 deletions pkg/apis/application/v1alpha1/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,21 @@ func TestAppDestinationEquality(t *testing.T) {
assert.False(t, left.Equals(*right))
}

func TestAppDestinationEquality_InferredServerURL(t *testing.T) {
left := ApplicationDestination{
Name: "in-cluster",
Namespace: "default",
}
right := ApplicationDestination{
Name: "in-cluster",
Server: "https://kubernetes.default.svc",
Namespace: "default",
isServerInferred: true,
}
assert.True(t, left.Equals(right))
assert.True(t, right.Equals(left))
}

func TestAppProjectSpec_DestinationClusters(t *testing.T) {
tests := []struct {
name string
Expand Down

0 comments on commit c108e2f

Please sign in to comment.