Skip to content

Commit

Permalink
fix: add admin clusterrolebinding (#78)
Browse files Browse the repository at this point in the history
Co-authored-by: Matteo Gastaldello <matteo.gastaldellomiotto@gmail.com>
  • Loading branch information
braghettos and matteogastaldello authored Sep 20, 2024
1 parent a32bd84 commit 3907db4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
10 changes: 10 additions & 0 deletions internal/tools/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,16 @@ func Deploy(ctx context.Context, kube client.Client, opts DeployOptions) (err er
}
}

crbAdmin := rbactools.CreateClusterRoleBindingAdmin(types.NamespacedName{
Namespace: opts.NamespacedName.Namespace,
Name: opts.NamespacedName.Name,
})

err = rbactools.InstallClusterRoleBinding(ctx, opts.KubeClient, &crbAdmin)
if err != nil {
return err, rbacErr
}

dep, err := deployment.CreateDeployment(gvr, opts.NamespacedName, opts.CDCImageTag)
if err != nil {
return err, rbacErr
Expand Down
25 changes: 25 additions & 0 deletions internal/tools/rbactools/clusterrolebinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rbactools

import (
"context"
"fmt"

"github.com/avast/retry-go"
rbacv1 "k8s.io/api/rbac/v1"
Expand Down Expand Up @@ -84,3 +85,27 @@ func CreateClusterRoleBinding(opts types.NamespacedName) rbacv1.ClusterRoleBindi
},
}
}

func CreateClusterRoleBindingAdmin(opts types.NamespacedName) rbacv1.ClusterRoleBinding {
return rbacv1.ClusterRoleBinding{
TypeMeta: metav1.TypeMeta{
APIVersion: "rbac.authorization.k8s.io/v1",
Kind: "ClusterRoleBinding",
},
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-admin", opts.Name),
},
RoleRef: rbacv1.RoleRef{
APIGroup: "rbac.authorization.k8s.io",
Kind: "ClusterRole",
Name: "cluster-admin",
},
Subjects: []rbacv1.Subject{
{
Kind: "ServiceAccount",
Name: opts.Name,
Namespace: opts.Namespace,
},
},
}
}

0 comments on commit 3907db4

Please sign in to comment.