-
Notifications
You must be signed in to change notification settings - Fork 5
/
operator.cue
272 lines (248 loc) · 5.57 KB
/
operator.cue
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
// Copyright 2017-2021 Authors of Cilium
// SPDX-License-Identifier: Apache-2.0
package operator
constants: {
name: "cilium-olm"
}
_commonMetadata: {
name: constants.name
labels: name: constants.name
namespace: parameters.namespace
}
_workload: {
metadata: _commonMetadata
spec: _workloadSpec
}
_related_images_env_vars: [{
name: "RELATED_IMAGE_CILIUM"
value: parameters.ciliumImage
},
{
name: "RELATED_IMAGE_HUBBLE_RELAY"
value: parameters.hubbleRelayImage
},
{
name: "RELATED_IMAGE_CILIUM_OPERATOR"
value: parameters.operatorImage
},
{
name: "RELATED_IMAGE_PREFLIGHT"
value: parameters.preflightImage
},
{
name: "RELATED_IMAGE_CLUSTERMESH"
value: parameters.clustermeshImage
},
{
name: "RELATED_IMAGE_CERTGEN"
value: parameters.certgenImage
},
{
name: "RELATED_IMAGE_HUBBLE_UI_BE"
value: parameters.hubbleUIBackendImage
},
{
name: "RELATED_IMAGE_HUBBLE_UI_FE"
value: parameters.hubbleUIFrontendImage
},
{
name: "RELATED_IMAGE_ETCD_OPERATOR"
value: parameters.etcdOperatorImage
},
{
name: "RELATED_IMAGE_NODEINIT"
value: parameters.nodeInitImage
}]
_extra_related_images_env_vars: [
if parameters.clustermeshEtcdImage != "nothing" {
{
name: "RELATED_IMAGE_CLUSTERMESH_ETCD"
value: parameters.clustermeshEtcdImage
},
},
]
_workloadSpec: {
template: {
metadata: labels: _commonMetadata.labels
spec: {
hostNetwork: true
tolerations: [{operator: "Exists"}]
serviceAccount: constants.name
volumes: [{
name: "tmp"
emptyDir: {}
}]
containers: [{
name: "operator"
command: _command
image: parameters.image
ports: [{
containerPort: 9443
name: "https"
protocol: "TCP"
}]
env: [{
name: "WATCH_NAMESPACE"
valueFrom: fieldRef: fieldPath: "metadata.namespace"
}] + _related_images_env_vars + _extra_related_images_env_vars
volumeMounts: [{
name: "tmp"
mountPath: "/tmp"
}]
resources: {
requests: {
cpu: "100m"
memory: "512Mi"
}
}
}]
terminationGracePeriodSeconds: 10
}
}
}
_command: [...string]
if !parameters.test {
_workload: {
apiVersion: "apps/v1"
kind: "Deployment"
}
_workloadSpec: {
replicas: 1
selector: matchLabels: _commonMetadata.labels
template: {
metadata: labels: _commonMetadata.labels
}
}
_command: [
"/usr/local/bin/helm-operator",
"run",
"--watches-file=watches.yaml",
"--enable-leader-election",
"--leader-election-id=\(constants.name)",
"--zap-devel",
"--metrics-addr=localhost:8082",
"--health-probe-bind-address=localhost:8081",
]
}
if parameters.test {
_workload: {
apiVersion: "batch/v1"
kind: "Job"
}
_workloadSpec: {
backoffLimit: 0
template: spec: restartPolicy: "Never"
}
_command: [
"test.\(constants.name)-controllers",
"-test.v",
"-test.timeout=25m", // this must be kept greater then the sum of all polling timeouts
]
}
_serviceAccount: {
apiVersion: "v1"
kind: "ServiceAccount"
metadata: _commonMetadata
}
_serviceSelector: {
if !parameters.test {
name: constants.name
}
if parameters.test {
"job-name": constants.name
}
}
_service: {
apiVersion: "v1"
kind: "Service"
metadata: _commonMetadata
spec: {
selector: _serviceSelector
ports: [{
name: "https"
port: 443
targetPort: 9443
}]
}
}
_rbac_ClusterRoleBinding: {
apiVersion: "rbac.authorization.k8s.io/v1beta1"
kind: "ClusterRoleBinding"
metadata: {
name: "\(parameters.namespace)-\(constants.name)"
labels: _commonMetadata.labels
}
roleRef: {
kind: "ClusterRole"
name: constants.name
apiGroup: "rbac.authorization.k8s.io"
}
subjects: [{
kind: "ServiceAccount"
name: constants.name
namespace: parameters.namespace
}]
}
namespace: [...{}]
if parameters.namespace != "kube-system" {
namespace: [{
apiVersion: "v1"
kind: "Namespace"
metadata: {
name: parameters.namespace
annotations: {
// node selector is required to make cilium-operator run on control plane nodes
"openshift.io/node-selector": ""
}
labels: {
name: parameters.namespace
// run level sets priority for Cilium to be deployed prior to other components
"openshift.io/run-level": "0"
// enable cluster logging for Cilium namespace
"openshift.io/cluster-logging": "true"
// enable cluster monitoring for Cilium namespace
"openshift.io/cluster-monitoring": "true"
}
}
}]
}
_rbac_items: _roles + _roleBindings + _clusterRoles + _clusterRoleBindings
_core_items: namespace + [
_serviceAccount,
_workload,
_service,
] + _rbac_items + _olm_items
#WorkloadTemplate: {
kind: "List"
apiVersion: "v1"
items: _core_items
}
#WorkloadParameters: {
replaces: string
image: string
test: bool
ciliumVersion: string
ciliumMajorMinor: string
onlyCSV: bool
namespace: string | *"cilium"
configVersionSuffix: string
ciliumImage: string | *""
hubbleRelayImage: string | *""
operatorImage: string | *""
preflightImage: string | *""
clustermeshImage: string | *""
certgenImage: string | *""
hubbleUIBackendImage: string | *""
hubbleUIFrontendImage: string | *""
etcdOperatorImage: string | *""
nodeInitImage: string | *""
clustermeshEtcdImage: string | *""
}
parameters: #WorkloadParameters
template: {}
if parameters.onlyCSV {
template: #CSVWorkloadTemplate
}
if !parameters.onlyCSV {
template: #WorkloadTemplate
}