Skip to content

Commit

Permalink
[v15] Ignore AccessListsMember's IneligibleStatus field (#41050)
Browse files Browse the repository at this point in the history
* Ignore `AccessListsMember`'s `IneligibleStatus` field

This PR discards the `IneligibleStatus` field when comparing
`AccessListMember`.

This field is managed by `IneligibleStatusReconciler` and should be
ignored when using other reconcilers.

Signed-off-by: Tiago Silva <[email protected]>

* handle review comments

---------

Signed-off-by: Tiago Silva <[email protected]>
  • Loading branch information
tigrato authored Apr 30, 2024
1 parent b18a158 commit cb33198
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/services/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ func CompareResources[T any](resA, resB T) int {
cmpopts.IgnoreFields(types.UserSpecV2{}, "Status"),
cmpopts.IgnoreFields(accesslist.AccessList{}, "Status"),
cmpopts.IgnoreUnexported(headerv1.Metadata{}),
// Managed by IneligibleStatusReconciler, ignored by all others.
cmpopts.IgnoreFields(accesslist.AccessListMemberSpec{}, "IneligibleStatus"),
cmpopts.EquateEmpty(),
)
}
Expand Down
13 changes: 13 additions & 0 deletions lib/services/compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"testing"

"github.com/stretchr/testify/require"

"github.com/gravitational/teleport/api/types/accesslist"
)

func TestCompareResources(t *testing.T) {
Expand All @@ -31,6 +33,17 @@ func TestCompareResources(t *testing.T) {
// These results should be forced since we're going through a custom compare function.
compareTestCase(t, "IsEqual equal", &compareResourceWithEqual{true}, &compareResourceWithEqual{false}, Equal)
compareTestCase(t, "IsEqual not equal", &compareResourceWithEqual{false}, &compareResourceWithEqual{false}, Different)

// These results compare AccessListMemberSpec, which should ignore the IneligibleStatus field.
newAccessListMemberSpec := func(ineligibleStatus, accessList string) accesslist.AccessListMemberSpec {
return accesslist.AccessListMemberSpec{
AccessList: accessList,
IneligibleStatus: ineligibleStatus,
}
}
compareTestCase(t, "cmp equal with equal IneligibleStatus", newAccessListMemberSpec("status1", "accessList1"), newAccessListMemberSpec("status1", "accessList1"), Equal)
compareTestCase(t, "cmp equal with different IneligibleStatus", newAccessListMemberSpec("status1", "accessList1"), newAccessListMemberSpec("status2", "accessList1"), Equal)
compareTestCase(t, "cmp not equal", newAccessListMemberSpec("status1", "accessList1"), newAccessListMemberSpec("status1", "accessList2"), Different)
}

func compareTestCase[T any](t *testing.T, name string, resA, resB T, expected int) {
Expand Down

0 comments on commit cb33198

Please sign in to comment.