-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstarrocks-operator.tf
More file actions
290 lines (270 loc) · 6.32 KB
/
starrocks-operator.tf
File metadata and controls
290 lines (270 loc) · 6.32 KB
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#---------------------------------------------------------------
# StarRocks Namespace
#---------------------------------------------------------------
resource "kubectl_manifest" "starrocks_namespace" {
count = var.enable_starrocks_operator ? 1 : 0
yaml_body = <<-YAML
apiVersion: v1
kind: Namespace
metadata:
name: ${var.starrocks_namespace}
YAML
depends_on = [kubectl_manifest.starrocks_crd]
}
#---------------------------------------------------------------
# StarRocks Service Account
#---------------------------------------------------------------
resource "kubectl_manifest" "starrocks_service_account" {
count = var.enable_starrocks_operator ? 1 : 0
yaml_body = <<-YAML
apiVersion: v1
kind: ServiceAccount
metadata:
name: starrocks
namespace: ${var.starrocks_namespace}
YAML
depends_on = [kubectl_manifest.starrocks_namespace]
}
#---------------------------------------------------------------
# StarRocks ClusterRole
#---------------------------------------------------------------
resource "kubectl_manifest" "starrocks_cluster_role" {
count = var.enable_starrocks_operator ? 1 : 0
yaml_body = <<-YAML
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: kube-starrocks-operator
labels:
app: kube-starrocks-operator
rules:
- apiGroups:
- apps
resources:
- deployments
- statefulsets
verbs:
- '*'
- apiGroups:
- autoscaling
resources:
- horizontalpodautoscalers
verbs:
- '*'
- apiGroups:
- batch
resources:
- cronjobs
verbs:
- '*'
- apiGroups:
- ""
resources:
- configmaps
- serviceaccounts
- services
verbs:
- '*'
- apiGroups:
- ""
resources:
- endpoints
- pods
- secrets
verbs:
- get
- list
- watch
- apiGroups:
- starrocks.com
resources:
- starrocksclusters
- starrockswarehouses
verbs:
- '*'
- apiGroups:
- starrocks.com
resources:
- starrocksclusters/finalizers
- starrockswarehouses/finalizers
verbs:
- update
- apiGroups:
- starrocks.com
resources:
- starrocksclusters/status
- starrockswarehouses/status
verbs:
- get
- patch
- update
YAML
depends_on = [kubectl_manifest.starrocks_crd]
}
#---------------------------------------------------------------
# StarRocks ClusterRoleBinding
#---------------------------------------------------------------
resource "kubectl_manifest" "starrocks_cluster_role_binding" {
count = var.enable_starrocks_operator ? 1 : 0
yaml_body = <<-YAML
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: kube-starrocks-operator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: kube-starrocks-operator
subjects:
- kind: ServiceAccount
name: starrocks
namespace: ${var.starrocks_namespace}
YAML
depends_on = [
kubectl_manifest.starrocks_cluster_role,
kubectl_manifest.starrocks_service_account
]
}
#---------------------------------------------------------------
# StarRocks Leader Election Role
#---------------------------------------------------------------
resource "kubectl_manifest" "starrocks_leader_election_role" {
count = var.enable_starrocks_operator ? 1 : 0
yaml_body = <<-YAML
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: cn-leader-election-role
namespace: ${var.starrocks_namespace}
rules:
- apiGroups:
- ""
resources:
- configmaps
verbs:
- get
- list
- watch
- create
- update
- patch
- delete
- apiGroups:
- coordination.k8s.io
resources:
- leases
verbs:
- get
- list
- watch
- create
- update
- patch
- delete
- apiGroups:
- ""
resources:
- events
verbs:
- create
- patch
YAML
depends_on = [kubectl_manifest.starrocks_namespace]
}
#---------------------------------------------------------------
# StarRocks Leader Election RoleBinding
#---------------------------------------------------------------
resource "kubectl_manifest" "starrocks_leader_election_role_binding" {
count = var.enable_starrocks_operator ? 1 : 0
yaml_body = <<-YAML
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: cn-leader-election-rolebinding
namespace: ${var.starrocks_namespace}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: cn-leader-election-role
subjects:
- kind: ServiceAccount
name: starrocks
namespace: ${var.starrocks_namespace}
YAML
depends_on = [
kubectl_manifest.starrocks_leader_election_role,
kubectl_manifest.starrocks_service_account
]
}
#---------------------------------------------------------------
# StarRocks Operator Deployment
#---------------------------------------------------------------
resource "kubectl_manifest" "starrocks_operator_deployment" {
count = var.enable_starrocks_operator ? 1 : 0
yaml_body = <<-YAML
apiVersion: apps/v1
kind: Deployment
metadata:
name: kube-starrocks-operator
namespace: ${var.starrocks_namespace}
labels:
app: kube-starrocks-operator
spec:
selector:
matchLabels:
app: kube-starrocks-operator
replicas: 1
template:
metadata:
annotations:
kubectl.kubernetes.io/default-container: manager
labels:
app: kube-starrocks-operator
version: 1.10.2
spec:
automountServiceAccountToken: true
containers:
- command:
- /sroperator
args:
- --leader-elect
- --zap-time-encoding=iso8601
- --zap-encoder=console
- --volume-name-with-hash=true
env:
- name: TZ
value: Asia/Shanghai
image: "${var.starrocks_operator_image}"
imagePullPolicy: Always
name: manager
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
runAsNonRoot: true
livenessProbe:
httpGet:
path: /healthz
port: 8081
initialDelaySeconds: 15
periodSeconds: 20
readinessProbe:
httpGet:
path: /readyz
port: 8081
initialDelaySeconds: 5
periodSeconds: 10
resources:
limits:
cpu: 500m
memory: 800Mi
requests:
cpu: 500m
memory: 400Mi
serviceAccountName: starrocks
terminationGracePeriodSeconds: 10
YAML
depends_on = [
kubectl_manifest.starrocks_cluster_role_binding,
kubectl_manifest.starrocks_leader_election_role_binding
]
}