7
7
"github.com/odigos-io/odigos/cli/pkg/containers"
8
8
"github.com/odigos-io/odigos/cli/pkg/kube"
9
9
"github.com/odigos-io/odigos/common"
10
+ "github.com/odigos-io/odigos/common/consts"
10
11
11
12
appsv1 "k8s.io/api/apps/v1"
12
13
corev1 "k8s.io/api/core/v1"
@@ -17,11 +18,16 @@ import (
17
18
)
18
19
19
20
const (
20
- SchedulerImage = "keyval/odigos-scheduler"
21
- SchedulerServiceName = "scheduler"
22
- SchedulerDeploymentName = "odigos-scheduler"
23
- SchedulerAppLabelValue = "odigos-scheduler"
24
- SchedulerContainerName = "manager"
21
+ SchedulerImage = "keyval/odigos-scheduler"
22
+ SchedulerServiceName = "scheduler"
23
+ SchedulerDeploymentName = "odigos-scheduler"
24
+ SchedulerAppLabelValue = SchedulerDeploymentName
25
+ SchedulerRoleName = SchedulerDeploymentName
26
+ SchedulerRoleBindingName = SchedulerDeploymentName
27
+ SchedulerClusterRoleName = SchedulerDeploymentName
28
+ SchedulerClusterRoleBindingName = SchedulerDeploymentName
29
+ SchedulerServiceAccountName = SchedulerDeploymentName
30
+ SchedulerContainerName = "manager"
25
31
)
26
32
27
33
func NewSchedulerServiceAccount (ns string ) * corev1.ServiceAccount {
@@ -31,13 +37,13 @@ func NewSchedulerServiceAccount(ns string) *corev1.ServiceAccount {
31
37
APIVersion : "v1" ,
32
38
},
33
39
ObjectMeta : metav1.ObjectMeta {
34
- Name : "odigos-scheduler" ,
40
+ Name : SchedulerServiceAccountName ,
35
41
Namespace : ns ,
36
42
},
37
43
}
38
44
}
39
45
40
- func NewSchedulerRoleBinding (ns string ) * rbacv1.RoleBinding {
46
+ func NewSchedulerLeaderElectionRoleBinding (ns string ) * rbacv1.RoleBinding {
41
47
return & rbacv1.RoleBinding {
42
48
TypeMeta : metav1.TypeMeta {
43
49
Kind : "RoleBinding" ,
@@ -50,7 +56,7 @@ func NewSchedulerRoleBinding(ns string) *rbacv1.RoleBinding {
50
56
Subjects : []rbacv1.Subject {
51
57
{
52
58
Kind : "ServiceAccount" ,
53
- Name : "odigos-scheduler" ,
59
+ Name : SchedulerServiceAccountName ,
54
60
},
55
61
},
56
62
RoleRef : rbacv1.RoleRef {
@@ -61,42 +67,48 @@ func NewSchedulerRoleBinding(ns string) *rbacv1.RoleBinding {
61
67
}
62
68
}
63
69
64
- func NewSchedulerClusterRole ( ) * rbacv1.ClusterRole {
65
- return & rbacv1.ClusterRole {
70
+ func NewSchedulerRole ( ns string ) * rbacv1.Role {
71
+ return & rbacv1.Role {
66
72
TypeMeta : metav1.TypeMeta {
67
- Kind : "ClusterRole " ,
73
+ Kind : "Role " ,
68
74
APIVersion : "rbac.authorization.k8s.io/v1" ,
69
75
},
70
76
ObjectMeta : metav1.ObjectMeta {
71
- Name : "odigos-scheduler" ,
77
+ Name : SchedulerRoleName ,
78
+ Namespace : ns ,
72
79
},
73
80
Rules : []rbacv1.PolicyRule {
74
81
{
75
82
Verbs : []string {
76
- "create" ,
77
- "delete" ,
78
83
"get" ,
79
84
"list" ,
80
- "patch" ,
81
- "update" ,
82
85
"watch" ,
83
86
},
84
87
APIGroups : []string {
85
- "odigos.io " ,
88
+ "" ,
86
89
},
87
90
Resources : []string {
88
- "collectorsgroups" ,
91
+ "configmaps" ,
92
+ },
93
+ ResourceNames : []string {
94
+ consts .OdigosConfigurationName ,
89
95
},
90
96
},
91
97
{
92
98
Verbs : []string {
99
+ "create" ,
100
+ "delete" ,
101
+ "get" ,
102
+ "list" ,
103
+ "patch" ,
93
104
"update" ,
105
+ "watch" ,
94
106
},
95
107
APIGroups : []string {
96
108
"odigos.io" ,
97
109
},
98
110
Resources : []string {
99
- "collectorsgroups/finalizers " ,
111
+ "collectorsgroups" ,
100
112
},
101
113
},
102
114
{
@@ -114,12 +126,8 @@ func NewSchedulerClusterRole() *rbacv1.ClusterRole {
114
126
},
115
127
{
116
128
Verbs : []string {
117
- "create" ,
118
- "delete" ,
119
129
"get" ,
120
130
"list" ,
121
- "patch" ,
122
- "update" ,
123
131
"watch" ,
124
132
},
125
133
APIGroups : []string {
@@ -129,17 +137,6 @@ func NewSchedulerClusterRole() *rbacv1.ClusterRole {
129
137
"destinations" ,
130
138
},
131
139
},
132
- {
133
- Verbs : []string {
134
- "update" ,
135
- },
136
- APIGroups : []string {
137
- "odigos.io" ,
138
- },
139
- Resources : []string {
140
- "destinations/finalizers" ,
141
- },
142
- },
143
140
{
144
141
Verbs : []string {
145
142
"get" ,
@@ -153,6 +150,44 @@ func NewSchedulerClusterRole() *rbacv1.ClusterRole {
153
150
"destinations/status" ,
154
151
},
155
152
},
153
+ },
154
+ }
155
+ }
156
+
157
+ func NewSchedulerRoleBinding (ns string ) * rbacv1.RoleBinding {
158
+ return & rbacv1.RoleBinding {
159
+ TypeMeta : metav1.TypeMeta {
160
+ Kind : "RoleBinding" ,
161
+ APIVersion : "rbac.authorization.k8s.io/v1" ,
162
+ },
163
+ ObjectMeta : metav1.ObjectMeta {
164
+ Name : SchedulerRoleBindingName ,
165
+ Namespace : ns ,
166
+ },
167
+ Subjects : []rbacv1.Subject {
168
+ {
169
+ Kind : "ServiceAccount" ,
170
+ Name : SchedulerServiceAccountName ,
171
+ },
172
+ },
173
+ RoleRef : rbacv1.RoleRef {
174
+ APIGroup : "rbac.authorization.k8s.io" ,
175
+ Kind : "Role" ,
176
+ Name : SchedulerRoleName ,
177
+ },
178
+ }
179
+ }
180
+
181
+ func NewSchedulerClusterRole () * rbacv1.ClusterRole {
182
+ return & rbacv1.ClusterRole {
183
+ TypeMeta : metav1.TypeMeta {
184
+ Kind : "ClusterRole" ,
185
+ APIVersion : "rbac.authorization.k8s.io/v1" ,
186
+ },
187
+ ObjectMeta : metav1.ObjectMeta {
188
+ Name : SchedulerClusterRoleName ,
189
+ },
190
+ Rules : []rbacv1.PolicyRule {
156
191
{
157
192
Verbs : []string {
158
193
"list" ,
@@ -173,19 +208,19 @@ func NewSchedulerClusterRoleBinding(ns string) *rbacv1.ClusterRoleBinding {
173
208
APIVersion : "rbac.authorization.k8s.io/v1" ,
174
209
},
175
210
ObjectMeta : metav1.ObjectMeta {
176
- Name : "odigos-scheduler" ,
211
+ Name : SchedulerClusterRoleBindingName ,
177
212
},
178
213
Subjects : []rbacv1.Subject {
179
214
{
180
215
Kind : "ServiceAccount" ,
181
- Name : "odigos-scheduler" ,
216
+ Name : SchedulerServiceAccountName ,
182
217
Namespace : ns ,
183
218
},
184
219
},
185
220
RoleRef : rbacv1.RoleRef {
186
221
APIGroup : "rbac.authorization.k8s.io" ,
187
222
Kind : "ClusterRole" ,
188
- Name : "odigos-scheduler" ,
223
+ Name : SchedulerClusterRoleName ,
189
224
},
190
225
}
191
226
}
@@ -285,7 +320,7 @@ func NewSchedulerDeployment(ns string, version string, imagePrefix string) *apps
285
320
},
286
321
},
287
322
TerminationGracePeriodSeconds : ptrint64 (10 ),
288
- ServiceAccountName : "odigos-scheduler" ,
323
+ ServiceAccountName : SchedulerServiceAccountName ,
289
324
SecurityContext : & corev1.PodSecurityContext {
290
325
RunAsNonRoot : ptrbool (true ),
291
326
},
@@ -313,6 +348,8 @@ func (a *schedulerResourceManager) Name() string { return "Scheduler" }
313
348
func (a * schedulerResourceManager ) InstallFromScratch (ctx context.Context ) error {
314
349
resources := []kube.Object {
315
350
NewSchedulerServiceAccount (a .ns ),
351
+ NewSchedulerLeaderElectionRoleBinding (a .ns ),
352
+ NewSchedulerRole (a .ns ),
316
353
NewSchedulerRoleBinding (a .ns ),
317
354
NewSchedulerClusterRole (),
318
355
NewSchedulerClusterRoleBinding (a .ns ),
0 commit comments