Skip to content

Commit

Permalink
fix: add admin clusterrolebinding
Browse files Browse the repository at this point in the history
  • Loading branch information
matteogastaldello committed Sep 20, 2024
1 parent a32bd84 commit de8188e
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,
})

Check warning on line 237 in internal/tools/deploy/deploy.go

View check run for this annotation

Codecov / codecov/patch

internal/tools/deploy/deploy.go#L234-L237

Added lines #L234 - L237 were not covered by tests

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

Check warning on line 241 in internal/tools/deploy/deploy.go

View check run for this annotation

Codecov / codecov/patch

internal/tools/deploy/deploy.go#L239-L241

Added lines #L239 - L241 were not covered by tests
}

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{

Check warning on line 103 in internal/tools/rbactools/clusterrolebinding.go

View check run for this annotation

Codecov / codecov/patch

internal/tools/rbactools/clusterrolebinding.go#L89-L103

Added lines #L89 - L103 were not covered by tests
{
Kind: "ServiceAccount",
Name: opts.Name,
Namespace: opts.Namespace,
},
},

Check warning on line 109 in internal/tools/rbactools/clusterrolebinding.go

View check run for this annotation

Codecov / codecov/patch

internal/tools/rbactools/clusterrolebinding.go#L105-L109

Added lines #L105 - L109 were not covered by tests
}
}

0 comments on commit de8188e

Please sign in to comment.