Skip to content

Fix RBAC in multicluster tool #99

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

Merged
merged 1 commit into from
May 9, 2025
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
22 changes: 17 additions & 5 deletions public/tools/multicluster/pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,14 @@ func createRoles(ctx context.Context, c KubeClient, serviceAccountName, serviceA
if telemetryClusterRoles {
clusterRoleTelemetry := buildClusterRoleTelemetry()
_, err = c.RbacV1().ClusterRoles().Create(ctx, &clusterRoleTelemetry, metav1.CreateOptions{})
if !errors.IsAlreadyExists(err) && err != nil {
return xerrors.Errorf("error creating cluster role: %w", err)
if err != nil {
if errors.IsAlreadyExists(err) {
if _, err := c.RbacV1().ClusterRoles().Update(ctx, &clusterRoleTelemetry, metav1.UpdateOptions{}); err != nil {
return xerrors.Errorf("error updating role: %w", err)
}
} else {
return xerrors.Errorf("error creating cluster role: %w", err)
}
}
fmt.Printf("created clusterrole: %s\n", clusterRoleTelemetry.Name)
if err = createClusterRoleBinding(ctx, c, serviceAccountName, serviceAccountNamespace, DefaultOperatorName+"-multi-telemetry-cluster-role-binding", clusterRoleTelemetry); err != nil {
Expand All @@ -594,7 +600,7 @@ func createRoles(ctx context.Context, c KubeClient, serviceAccountName, serviceA
}

_, err = c.RbacV1().Roles(namespace).Create(ctx, &role, metav1.CreateOptions{})
if !errors.IsAlreadyExists(err) && err != nil {
if err != nil {
if errors.IsAlreadyExists(err) {
if _, err := c.RbacV1().Roles(namespace).Update(ctx, &role, metav1.UpdateOptions{}); err != nil {
return xerrors.Errorf("error updating role: %w", err)
Expand Down Expand Up @@ -641,8 +647,14 @@ func createRoles(ctx context.Context, c KubeClient, serviceAccountName, serviceA
func createClusterRoleBinding(ctx context.Context, c KubeClient, serviceAccountName string, serviceAccountNamespace string, clusterRoleBindingName string, clusterRole rbacv1.ClusterRole) error {
clusterRoleBinding := buildClusterRoleBinding(clusterRole, serviceAccountName, serviceAccountNamespace, clusterRoleBindingName)
_, err := c.RbacV1().ClusterRoleBindings().Create(ctx, &clusterRoleBinding, metav1.CreateOptions{})
if !errors.IsAlreadyExists(err) && err != nil {
return xerrors.Errorf("error creating cluster role binding: %w", err)
if err != nil {
if errors.IsAlreadyExists(err) {
if _, err := c.RbacV1().ClusterRoleBindings().Update(ctx, &clusterRoleBinding, metav1.UpdateOptions{}); err != nil {
return xerrors.Errorf("error updating role: %w", err)
}
} else {
return xerrors.Errorf("error creating cluster role binding: %w", err)
}
}
fmt.Printf("created clusterrolebinding: %s\n", clusterRoleBinding.Name)
return nil
Expand Down
4 changes: 4 additions & 0 deletions scripts/evergreen/e2e/dump_diagnostic_information.sh
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ dump_namespace() {
dump_objects sts "StatefulSets" "${namespace}" describe > "logs/${prefix}z_statefulsets.txt"
dump_objects sts "StatefulSets Yaml" "${namespace}" >> "logs/${prefix}z_statefulsets.txt"
dump_objects serviceaccounts "ServiceAccounts" "${namespace}" > "logs/${prefix}z_service_accounts.txt"
dump_objects clusterrolebindings "ClusterRoleBindings" "${namespace}" > "logs/${prefix}z_clusterrolebindings.txt"
dump_objects clusterroles "ClusterRoles" "${namespace}" > "logs/${prefix}z_clusterroles.txt"
dump_objects rolebindings "RoleBindings" "${namespace}" > "logs/${prefix}z_rolebindings.txt"
dump_objects roles "Roles" "${namespace}" > "logs/${prefix}z_roles.txt"
dump_objects validatingwebhookconfigurations "Validating Webhook Configurations" "${namespace}" > "logs/${prefix}z_validatingwebhookconfigurations.txt"
dump_objects certificates.cert-manager.io "Cert-manager certificates" "${namespace}" 2> /dev/null > "logs/${prefix}z_certificates_certmanager.txt"
dump_objects catalogsources "OLM CatalogSources" "${namespace}" 2> /dev/null > "logs/${prefix}z_olm_catalogsources.txt"
Expand Down