From c20850fbd4c90cb6579c03ff17a42303734b4f9e Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Tue, 8 Jun 2021 08:26:13 -0400 Subject: [PATCH] fix CRB's not being able to specify names, fixed SA not being bound to their namespace Signed-off-by: Sebastian Malton --- .../api/endpoints/cluster-role-binding.api.ts | 1 + .../+cluster-role-bindings/dialog.tsx | 29 +++++++++------- .../+role-bindings/dialog.tsx | 33 +++++++------------ 3 files changed, 30 insertions(+), 33 deletions(-) diff --git a/src/renderer/api/endpoints/cluster-role-binding.api.ts b/src/renderer/api/endpoints/cluster-role-binding.api.ts index 2301e4124d..868f00261a 100644 --- a/src/renderer/api/endpoints/cluster-role-binding.api.ts +++ b/src/renderer/api/endpoints/cluster-role-binding.api.ts @@ -27,6 +27,7 @@ export interface ClusterRoleBindingSubject { kind: ClusterRoleBindingSubjectKind; name: string; apiGroup?: string; + namespace?: string; } export interface ClusterRoleBinding { diff --git a/src/renderer/components/+user-management/+cluster-role-bindings/dialog.tsx b/src/renderer/components/+user-management/+cluster-role-bindings/dialog.tsx index cb88e80635..9418d4fc4f 100644 --- a/src/renderer/components/+user-management/+cluster-role-bindings/dialog.tsx +++ b/src/renderer/components/+user-management/+cluster-role-bindings/dialog.tsx @@ -39,6 +39,7 @@ import { clusterRoleBindingsStore } from "./store"; import { clusterRolesStore } from "../+cluster-roles/store"; import { getRoleRefSelectOption, ServiceAccountOption } from "../select-options"; import { ObservableHashSet, nFircate } from "../../../utils"; +import { Input } from "../../input"; interface Props extends Partial { } @@ -94,6 +95,7 @@ export class ClusterRoleBindingDialog extends React.Component { const serviceAccounts = Array.from(this.selectedAccounts, sa => ({ name: sa.getName(), kind: "ServiceAccount" as const, + namespace: sa.getNs(), })); const users = Array.from(this.selectedUsers, user => ({ name: user, @@ -143,7 +145,7 @@ export class ClusterRoleBindingDialog extends React.Component { this.selectedRoleRef = clusterRolesStore .items .find(item => item.getName() === binding.roleRef.name); - this.bindingName = this.selectedRoleRef.getName(); + this.bindingName = this.clusterRoleBinding.getName(); const [saSubjects, uSubjects, gSubjects] = nFircate(binding.getSubjects(), "kind", ["ServiceAccount", "User", "Group"]); const accountNames = new Set(saSubjects.map(acc => acc.name)); @@ -152,7 +154,6 @@ export class ClusterRoleBindingDialog extends React.Component { serviceAccountsStore.items .filter(sa => accountNames.has(sa.getName())) ); - console.log("onOpen", this.selectedAccounts.size, this.selectedAccounts.toJSON()); this.selectedUsers.replace(uSubjects.map(user => user.name)); this.selectedGroups.replace(gSubjects.map(group => group.name)); }; @@ -197,7 +198,18 @@ export class ClusterRoleBindingDialog extends React.Component { isDisabled={this.isEditing} options={this.clusterRoleRefoptions} value={this.selectedRoleRef} - onChange={({ value }) => this.selectedRoleRef = value} + onChange={({ value }) => { + this.selectedRoleRef = value; + this.bindingName = this.selectedRoleRef.getName(); + }} + /> + + + this.bindingName = val} /> @@ -241,13 +253,8 @@ export class ClusterRoleBindingDialog extends React.Component { render() { const { ...dialogProps } = this.props; - const { isEditing, clusterRoleBinding, selectedRoleRef, selectedBindings } = this; - const clusterRoleBindingName = clusterRoleBinding?.getName(); - const header = clusterRoleBindingName - ?
Edit ClusterRoleBinding {clusterRoleBindingName}
- :
Add ClusterRoleBinding
; - const disableNext = !selectedRoleRef || !selectedBindings.length; - const nextLabel = isEditing ? "Update" : "Create"; + const [action, nextLabel] = this.isEditing ? ["Edit", "Update"] : ["Add", "Create"]; + const disableNext = !this.selectedRoleRef || !this.selectedBindings.length; return ( { onOpen={this.onOpen} > {action} ClusterRoleBinding} done={ClusterRoleBindingDialog.close} > { if (this.selectedRoleRef.kind === "Role") { this.bindingNamespace = this.selectedRoleRef.getNs(); } + + this.bindingName = this.selectedRoleRef.getName(); }} /> - {!this.isEditing && ( - <> - - this.bindingName = value} - /> - - )} + + this.bindingName = value} + /> @@ -276,18 +275,8 @@ export class RoleBindingDialog extends React.Component { render() { const { ...dialogProps } = this.props; - const { isEditing, roleBinding, selectedRoleRef, selectedBindings } = this; - const roleBindingName = roleBinding ? roleBinding.getName() : ""; - const header = ( -
- {roleBindingName - ? <>Edit RoleBinding {roleBindingName} - : "Add RoleBinding" - } -
- ); - const disableNext = !selectedRoleRef || !selectedBindings.length; - const nextLabel = isEditing ? "Update" : "Create"; + const [action, nextLabel] = this.isEditing ? ["Edit", "Update"] : ["Add", "Create"]; + const disableNext = !this.selectedRoleRef || !this.selectedBindings.length; return ( { onOpen={this.onOpen} > {action} RoleBinding} done={RoleBindingDialog.close} >