Skip to content
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

chore: support NewUpdatePodSecurityRoleBindingAction with multiple serviceaccounts #1358

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions controllers/components/dashboard/dashboard_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ var (
cluster.Unknown: PathUpstream,
}

serviceAccounts = map[cluster.Platform]string{
cluster.SelfManagedRhods: "rhods-dashboard",
cluster.ManagedRhods: "rhods-dashboard",
cluster.OpenDataHub: "odh-dashboard",
cluster.Unknown: "odh-dashboard",
serviceAccounts = map[cluster.Platform][]string{
cluster.SelfManagedRhods: {"rhods-dashboard"},
cluster.ManagedRhods: {"rhods-dashboard"},
cluster.OpenDataHub: {"odh-dashboard"},
cluster.Unknown: {"odh-dashboard"},
}

imagesMap = map[string]string{
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/actions/security/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/types"
)

func NewUpdatePodSecurityRoleBindingAction(roles map[cluster.Platform]string) actions.Fn {
func NewUpdatePodSecurityRoleBindingAction(roles map[cluster.Platform][]string) actions.Fn {
return func(ctx context.Context, rr *types.ReconciliationRequest) error {
v := roles[rr.Release.Name]
if v == "" {
if len(v) == 0 {
return nil
}

err := cluster.UpdatePodSecurityRolebinding(ctx, rr.Client, rr.DSCI.Spec.ApplicationsNamespace, v)
err := cluster.UpdatePodSecurityRolebinding(ctx, rr.Client, rr.DSCI.Spec.ApplicationsNamespace, v...)
if err != nil {
return fmt.Errorf("failed to update PodSecurityRolebinding for %s: %w", v, err)
}
Expand Down
15 changes: 8 additions & 7 deletions pkg/controller/actions/security/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,17 @@ func TestUpdatePodSecurityRoleBindingAction(t *testing.T) {

ctx := context.Background()

m := map[cluster.Platform]string{
cluster.Unknown: "odh-dashboard",
cluster.OpenDataHub: "odh-dashboard",
cluster.SelfManagedRhods: "rhods-dashboard",
cluster.ManagedRhods: "rhods-dashboard",
m := map[cluster.Platform][]string{
cluster.OpenDataHub: {"odh-dashboard"},
cluster.SelfManagedRhods: {"rhods-dashboard"},
cluster.ManagedRhods: {"rhods-dashboard", "fake-account"},
}

action := security.NewUpdatePodSecurityRoleBindingAction(m)

for p, s := range m {
k := p
v := s
vl := s

t.Run(string(k), func(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -74,7 +73,9 @@ func TestUpdatePodSecurityRoleBindingAction(t *testing.T) {
err = cl.Get(ctx, client.ObjectKey{Namespace: ns, Name: ns}, &rb)

g.Expect(err).ShouldNot(HaveOccurred())
g.Expect(cluster.SubjectExistInRoleBinding(rb.Subjects, v, ns)).Should(BeTrue())
for _, v := range vl {
g.Expect(cluster.SubjectExistInRoleBinding(rb.Subjects, v, ns)).Should(BeTrue())
}
})
}
}