Skip to content

Commit

Permalink
Update RoleBinding name (#1437)
Browse files Browse the repository at this point in the history
Signed-off-by: hmsayem <[email protected]>

Co-authored-by: Emruz Hossain <[email protected]>
  • Loading branch information
hmsayem and Emruz Hossain authored Apr 11, 2022
1 parent 2e328b9 commit 82de61a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
3 changes: 2 additions & 1 deletion pkg/rbac/cross_namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
core "k8s.io/api/core/v1"
rbac "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"kmodules.xyz/client-go/meta"
meta_util "kmodules.xyz/client-go/meta"
rbac_util "kmodules.xyz/client-go/rbac/v1"
)
Expand Down Expand Up @@ -95,7 +96,7 @@ func (opt *RBACOptions) ensureCrossNamespaceRoleBinding() error {
}

func (opt *RBACOptions) getRoleBindingName() string {
return strings.ReplaceAll(opt.ServiceAccount.Name, ".", "-")
return meta.NameWithSuffix(strings.ToLower(opt.Invoker.Kind), opt.Invoker.Name)
}

func (opt *RBACOptions) getCrossNamespaceRoleName() string {
Expand Down
9 changes: 1 addition & 8 deletions pkg/rbac/restore_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package rbac

import (
"context"
"strings"

"stash.appscode.dev/apimachinery/apis"
api_v1alpha1 "stash.appscode.dev/apimachinery/apis/stash/v1alpha1"
Expand Down Expand Up @@ -129,7 +128,7 @@ func (opt *RBACOptions) ensureRestoreJobClusterRole() error {
func (opt *RBACOptions) ensureRestoreJobRoleBinding() error {
meta := metav1.ObjectMeta{
Namespace: opt.Invoker.Namespace,
Name: getRestoreJobRoleBindingName(opt.ServiceAccount.Name),
Name: opt.getRoleBindingName(),
Labels: opt.OffshootLabels,
}
_, _, err := rbac_util.CreateOrPatchRoleBinding(context.TODO(), opt.KubeClient, meta, func(in *rbac.RoleBinding) *rbac.RoleBinding {
Expand All @@ -151,9 +150,3 @@ func (opt *RBACOptions) ensureRestoreJobRoleBinding() error {
}, metav1.PatchOptions{})
return err
}

func getRestoreJobRoleBindingName(name string) string {
// Create RoleBinding with name same as the ServiceAccount name.
// The ServiceAccount already has Stash specific prefix in it's name.
return strings.ReplaceAll(name, ".", "-")
}

0 comments on commit 82de61a

Please sign in to comment.