Skip to content

Commit

Permalink
update: add check on dashboard if userGroup not exist
Browse files Browse the repository at this point in the history
Signed-off-by: Wen Zhou <[email protected]>
  • Loading branch information
zdtsw committed Oct 4, 2024
1 parent 8c752fe commit 17f7e96
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
19 changes: 11 additions & 8 deletions components/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ var (
PathManagedDownstream = PathDownstream + "/addon"
OverridePath = ""
DefaultPath = ""
adminGroupsMap = map[cluster.Platform]string{
cluster.SelfManagedRhods: "rhods-admins",
cluster.ManagedRhods: "dedicated-admins",
cluster.OpenDataHub: "odh-admins",
cluster.Unknown: "odh-admins",
}
)

// Verifies that Dashboard implements ComponentInterface.
Expand Down Expand Up @@ -90,6 +96,10 @@ func (d *Dashboard) ReconcileComponent(ctx context.Context,
platform cluster.Platform,
currentComponentExist bool,
) error {
if err := cluster.CheckUserGroup(ctx, cli, adminGroupsMap[platform], dscispec.ApplicationsNamespace); err != nil {
return err
}

entryPath := DefaultPath
enabled := d.GetManagementState() == operatorv1.Managed
monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed
Expand Down Expand Up @@ -184,13 +194,6 @@ func (d *Dashboard) ReconcileComponent(ctx context.Context,
}

func updateKustomizeVariable(ctx context.Context, cli client.Client, platform cluster.Platform, dscispec *dsciv1.DSCInitializationSpec) (map[string]string, error) {
adminGroups := map[cluster.Platform]string{
cluster.SelfManagedRhods: "rhods-admins",
cluster.ManagedRhods: "dedicated-admins",
cluster.OpenDataHub: "odh-admins",
cluster.Unknown: "odh-admins",
}[platform]

sectionTitle := map[cluster.Platform]string{
cluster.SelfManagedRhods: "OpenShift Self Managed Services",
cluster.ManagedRhods: "OpenShift Managed Services",
Expand All @@ -210,7 +213,7 @@ func updateKustomizeVariable(ctx context.Context, cli client.Client, platform cl
}[platform]

return map[string]string{
"admin_groups": adminGroups,
"admin_groups": adminGroupsMap[platform],
"dashboard-url": consoleURL,
"section-title": sectionTitle,
}, nil
Expand Down
14 changes: 14 additions & 0 deletions pkg/cluster/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cluster
import (
"context"

userv1 "github.com/openshift/api/user/v1"
rbacv1 "k8s.io/api/rbac/v1"
k8serr "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -87,3 +88,16 @@ func DeleteClusterRoleBinding(ctx context.Context, cli client.Client, name strin

return cli.Delete(ctx, desiredClusterRoleBinding)
}

// Check if userGroup exists in the cluster

Check failure on line 92 in pkg/cluster/roles.go

View workflow job for this annotation

GitHub Actions / golangci-lint

Comment should end in a period (godot)
func CheckUserGroup(ctx context.Context, cli client.Client, userGroupName string, applicationsNamespace string) error {
userGroup := &userv1.Group{}
err := cli.Get(ctx, client.ObjectKey{
Name: userGroupName,
Namespace: applicationsNamespace,
}, userGroup)
if err != nil {
return err
}
return nil
}

0 comments on commit 17f7e96

Please sign in to comment.