-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add memberClusters selection #87
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package assets | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestShouldBeSkippedForMember1(t *testing.T) { | ||
// given | ||
member1Member2 := []string{"member1", "member2"} | ||
member2Member3 := []string{"member2", "member3"} | ||
testCases := map[string]struct { | ||
s Selector | ||
shouldBeSkipped bool | ||
mfrancisc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}{ | ||
"no selector": {s: Selector{}, shouldBeSkipped: false}, | ||
"different selected members": {s: Selector{MemberClusters: member2Member3}, shouldBeSkipped: true}, | ||
"in selected members": {s: Selector{MemberClusters: member1Member2}, shouldBeSkipped: false}, | ||
"listed in skipped members": {s: Selector{SkipMembers: member1Member2}, shouldBeSkipped: true}, | ||
"not listed in skipped members": {s: Selector{SkipMembers: member2Member3}, shouldBeSkipped: false}, | ||
"in selected members, but listed in skipped": { | ||
s: Selector{MemberClusters: member1Member2, SkipMembers: member1Member2}, shouldBeSkipped: true}, | ||
"in selected members, not listed in skipped": { | ||
s: Selector{MemberClusters: member1Member2, SkipMembers: member2Member3}, shouldBeSkipped: false}, | ||
"different selected members, not listed in skipped": { | ||
s: Selector{MemberClusters: member2Member3, SkipMembers: member2Member3}, shouldBeSkipped: true}, | ||
"different selected members, and listed in skipped": { | ||
s: Selector{MemberClusters: member2Member3, SkipMembers: member1Member2}, shouldBeSkipped: true}, | ||
} | ||
|
||
for testName, data := range testCases { | ||
t.Run(testName, func(t *testing.T) { | ||
// when | ||
shouldBeSkipped := data.s.ShouldBeSkippedForMember("member1") | ||
|
||
// then | ||
assert.Equal(t, data.shouldBeSkipped, shouldBeSkipped) | ||
}) | ||
} | ||
} | ||
|
||
func TestShouldBeSkippedForEmptyName(t *testing.T) { | ||
// given | ||
member1Member2 := []string{"member1", "member2"} | ||
testCases := map[string]struct { | ||
s Selector | ||
shouldBeSkipped bool | ||
}{ | ||
"no selector": {s: Selector{}, shouldBeSkipped: false}, | ||
"some selected members": {s: Selector{MemberClusters: member1Member2}, shouldBeSkipped: true}, | ||
"some skipped members": {s: Selector{SkipMembers: member1Member2}, shouldBeSkipped: false}, | ||
"some selected members and some skipped members": { | ||
s: Selector{MemberClusters: member1Member2, SkipMembers: member1Member2}, shouldBeSkipped: true}, | ||
} | ||
|
||
for testName, data := range testCases { | ||
t.Run(testName, func(t *testing.T) { | ||
// when | ||
shouldBeSkipped := data.s.ShouldBeSkippedForMember("") | ||
mfrancisc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// then | ||
assert.Equal(t, data.shouldBeSkipped, shouldBeSkipped) | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ package generate | |
|
||
import ( | ||
"github.com/kubesaw/ksctl/pkg/configuration" | ||
"k8s.io/utils/strings/slices" | ||
) | ||
|
||
type clusterContext struct { | ||
|
@@ -16,7 +15,7 @@ type clusterContext struct { | |
func ensureServiceAccounts(ctx *clusterContext, objsCache objectsCache) error { | ||
ctx.Printlnf("-> Ensuring ServiceAccounts and its RoleBindings...") | ||
for _, sa := range ctx.kubeSawAdmins.ServiceAccounts { | ||
if ctx.specificKMemberName != "" && slices.Contains(sa.Selector.SkipMembers, ctx.specificKMemberName) { | ||
if sa.Selector.ShouldBeSkippedForMember(ctx.specificKMemberName) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we keep the empty name check ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's already part of |
||
continue | ||
} | ||
|
||
|
@@ -47,7 +46,7 @@ func ensureUsers(ctx *clusterContext, objsCache objectsCache) error { | |
ctx.Printlnf("-> Ensuring Users and its RoleBindings...") | ||
|
||
for _, user := range ctx.kubeSawAdmins.Users { | ||
if ctx.specificKMemberName != "" && slices.Contains(user.Selector.SkipMembers, ctx.specificKMemberName) { | ||
if user.Selector.ShouldBeSkippedForMember(ctx.specificKMemberName) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we keep the empty name check here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the same, the check is part of the method |
||
continue | ||
} | ||
m := &permissionsManager{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean that there can be no "apply this entity to any member cluster"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. It's already the default behavior for the cases when you don't specify any permissions in any member cluster.