Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/install/installer/pkg/components/ws-daemon/rolebinding.go
2501 views
1
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package wsdaemon
6
7
import (
8
"fmt"
9
10
"github.com/gitpod-io/gitpod/installer/pkg/common"
11
12
rbacv1 "k8s.io/api/rbac/v1"
13
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14
"k8s.io/apimachinery/pkg/runtime"
15
)
16
17
func rolebinding(ctx *common.RenderContext) ([]runtime.Object, error) {
18
labels := common.DefaultLabels(Component)
19
20
bindings := []runtime.Object{
21
&rbacv1.ClusterRoleBinding{
22
TypeMeta: common.TypeMetaClusterRoleBinding,
23
ObjectMeta: metav1.ObjectMeta{
24
Name: fmt.Sprintf("%s-%s-rb-kube-rbac-proxy", ctx.Namespace, Component),
25
Labels: labels,
26
},
27
RoleRef: rbacv1.RoleRef{
28
Kind: "ClusterRole",
29
Name: fmt.Sprintf("%s-kube-rbac-proxy", ctx.Namespace),
30
APIGroup: "rbac.authorization.k8s.io",
31
},
32
Subjects: []rbacv1.Subject{
33
{
34
Kind: "ServiceAccount",
35
Name: Component,
36
Namespace: ctx.Namespace,
37
},
38
},
39
},
40
&rbacv1.ClusterRoleBinding{
41
TypeMeta: common.TypeMetaClusterRoleBinding,
42
ObjectMeta: metav1.ObjectMeta{
43
Name: fmt.Sprintf("%s-%s-rb", ctx.Namespace, Component),
44
Labels: labels,
45
},
46
RoleRef: rbacv1.RoleRef{
47
Kind: "ClusterRole",
48
Name: fmt.Sprintf("%s-ns-%s", ctx.Namespace, Component),
49
APIGroup: "rbac.authorization.k8s.io",
50
},
51
Subjects: []rbacv1.Subject{{
52
Kind: "ServiceAccount",
53
Name: Component,
54
Namespace: ctx.Namespace,
55
}},
56
},
57
&rbacv1.RoleBinding{
58
TypeMeta: common.TypeMetaRoleBinding,
59
ObjectMeta: metav1.ObjectMeta{
60
Name: Component,
61
Namespace: common.WorkspaceSecretsNamespace,
62
},
63
RoleRef: rbacv1.RoleRef{
64
APIGroup: "rbac.authorization.k8s.io",
65
Kind: "Role",
66
Name: Component,
67
},
68
Subjects: []rbacv1.Subject{
69
{
70
Kind: "ServiceAccount",
71
Name: Component,
72
Namespace: ctx.Namespace,
73
},
74
},
75
},
76
}
77
78
return bindings, nil
79
}
80
81