Skip to content

Commit

Permalink
chore: support NewUpdatePodSecurityRoleBindingAction with multiple se…
Browse files Browse the repository at this point in the history
…rviceaccounts (#1358)

Signed-off-by: Wen Zhou <wenzhou@redhat.com>
  • Loading branch information
zdtsw authored Nov 8, 2024
1 parent f941791 commit 10197da
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
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())
}
})
}
}

0 comments on commit 10197da

Please sign in to comment.