-
-
Notifications
You must be signed in to change notification settings - Fork 513
/
tm_cluster_role_binding.go
59 lines (48 loc) · 1.44 KB
/
tm_cluster_role_binding.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package resource
import (
"context"
"fmt"
rbac "k8s.io/api/rbac/v1"
"github.com/datawire/ambassador/pkg/kates"
"github.com/telepresenceio/telepresence/v2/pkg/install"
)
type tmClusterRoleBinding int
const TrafficManagerClusterRoleBinding = tmClusterRoleBinding(0)
var _ Instance = TrafficManagerClusterRoleBinding
func (ri tmClusterRoleBinding) roleBinding(ctx context.Context) *kates.ClusterRoleBinding {
cr := new(kates.ClusterRoleBinding)
cr.TypeMeta = kates.TypeMeta{
Kind: "ClusterRoleBinding",
APIVersion: "rbac.authorization.k8s.io/v1",
}
cr.ObjectMeta = kates.ObjectMeta{
Name: fmt.Sprintf("%s-%s", install.ManagerAppName, getScope(ctx).namespace),
}
return cr
}
func (ri tmClusterRoleBinding) Create(ctx context.Context) error {
clb := ri.roleBinding(ctx)
clb.Subjects = []rbac.Subject{
{
Kind: "ServiceAccount",
Name: "traffic-manager",
Namespace: getScope(ctx).namespace,
},
}
clb.RoleRef = rbac.RoleRef{
APIGroup: "rbac.authorization.k8s.io",
Kind: "ClusterRole",
Name: fmt.Sprintf("%s-%s", install.ManagerAppName, getScope(ctx).namespace),
}
return create(ctx, clb)
}
func (ri tmClusterRoleBinding) Exists(ctx context.Context) (bool, error) {
return exists(ctx, ri.roleBinding(ctx))
}
func (ri tmClusterRoleBinding) Delete(ctx context.Context) error {
return remove(ctx, ri.roleBinding(ctx))
}
func (ri tmClusterRoleBinding) Update(_ context.Context) error {
// Noop
return nil
}