-
Notifications
You must be signed in to change notification settings - Fork 201
/
cstor_pool.go
460 lines (451 loc) · 16.9 KB
/
cstor_pool.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
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
/*
Copyright 2018 The OpenEBS Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// TODO
// Rename this file by removing the version suffix information
package v1alpha1
const cstorPoolYamls = `
---
apiVersion: openebs.io/v1alpha1
kind: CASTemplate
metadata:
name: cstor-pool-create-default
spec:
defaultConfig:
# CstorPoolImage is the container image that executes zpool replication and
# communicates with cstor iscsi target
- name: CstorPoolImage
value: {{env "OPENEBS_IO_CSTOR_POOL_IMAGE" | default "openebs/cstor-pool:latest"}}
# CstorPoolExporterImage is the container image that executes zpool and zfs binary
# to export various volume and pool metrics
- name: CstorPoolExporterImage
value: {{env "OPENEBS_IO_CSTOR_POOL_EXPORTER_IMAGE" | default "openebs/m-exporter:latest"}}
# CstorPoolMgmtImage runs cstor pool and cstor volume replica related CRUD
# operations
- name: CstorPoolMgmtImage
value: {{env "OPENEBS_IO_CSTOR_POOL_MGMT_IMAGE" | default "openebs/cstor-pool-mgmt:latest"}}
# HostPathType is a hostPath volume i.e. mounts a file or directory from the
# host node’s filesystem into a Pod. 'DirectoryOrCreate' value ensures
# nothing exists at the given path i.e. an empty directory will be created.
- name: HostPathType
value: DirectoryOrCreate
# OpenebsBaseDir is a hostPath directory to store process files on host machine
- name: OpenebsBaseDir
value: {{env "OPENEBS_IO_BASE_DIR" | default "/var/openebs"}}
# SparseDir is a hostPath directory where to look for sparse files
- name: SparseDir
value: {{env "OPENEBS_IO_CSTOR_POOL_SPARSE_DIR" | default "/var/openebs/sparse"}}
# RunNamespace is the namespace where namespaced resources related to pool
# will be placed
- name: RunNamespace
value: {{env "OPENEBS_NAMESPACE"}}
# ServiceAccountName is the account name assigned to pool management pod
# with permissions to view, create, edit, delete required custom resources
- name: ServiceAccountName
value: {{env "OPENEBS_SERVICE_ACCOUNT"}}
# PoolResourceRequests allow you to specify resource requests that need to be available
# before scheduling the containers. If not specified, the default is to use the limits
# from PoolResourceLimits or the default requests set in the cluster.
- name: PoolResourceRequests
value: "none"
# PoolResourceLimits allow you to set the limits on memory and cpu for pool pods
# The resource and limit value should be in the same format as expected by
# Kubernetes. Example:
#- name: PoolResourceLimits
# value: |-
# memory: 1Gi
- name: PoolResourceLimits
value: "none"
# AuxResourceRequests allow you to set requests on side cars. Requests have to be specified
# in the format expected by Kubernetes
- name: AuxResourceRequests
value: "none"
# AuxResourceLimits allow you to set limits on side cars. Limits have to be specified
# in the format expected by Kubernetes
- name: AuxResourceLimits
value: "none"
# ResyncInterval specifies duration after which a controller should
# resync the resource status
- name: ResyncInterval
value: "30"
# Toleration allows you to set tolerations for the cstor pool deployments
# against the nodes which has been tainted
- name: Tolerations
value: "none"
taskNamespace: {{env "OPENEBS_NAMESPACE"}}
run:
tasks:
# Following are the list of run tasks executed in this order to
# create a cstor storage pool
- cstor-pool-create-getspc-default
- cstor-pool-create-putcstorpoolcr-default
- cstor-pool-create-putcstorpooldeployment-default
- cstor-pool-create-patchstoragepoolclaim-default
---
# This run task get StoragePoolClaim
apiVersion: openebs.io/v1alpha1
kind: RunTask
metadata:
name: cstor-pool-create-getspc-default
spec:
meta: |
id: getspc
apiVersion: openebs.io/v1alpha1
kind: StoragePoolClaim
action: get
objectName: {{.Storagepool.owner}}
post: |
{{- jsonpath .JsonResult "{.metadata.uid}" | trim | addTo "getspc.objectUID" .TaskResult | noop -}}
---
apiVersion: openebs.io/v1alpha1
kind: RunTask
metadata:
name: cstor-pool-create-putcstorpoolcr-default
spec:
meta: |
apiVersion: openebs.io/v1alpha1
kind: CStorPool
action: put
id: putcstorpoolcr
post: |
{{- jsonpath .JsonResult "{.metadata.name}" | trim | addTo "putcstorpoolcr.objectName" .TaskResult | noop -}}
{{- jsonpath .JsonResult "{.metadata.uid}" | trim | addTo "putcstorpoolcr.objectUID" .TaskResult | noop -}}
{{- jsonpath .JsonResult "{.metadata.labels.kubernetes\\.io/hostname}" | trim | addTo "putcstorpoolcr.nodeName" .TaskResult | noop -}}
task: |-
{{- $storagePool:= toYaml .Storagepool | fromYaml -}}
apiVersion: openebs.io/v1alpha1
kind: CStorPool
metadata:
name: {{$storagePool.owner}}-{{randAlphaNum 4 |lower }}
labels:
openebs.io/storage-pool-claim: {{$storagePool.owner}}
kubernetes.io/hostname: {{$storagePool.nodeName}}
openebs.io/version: {{ .CAST.version }}
openebs.io/cas-template-name: {{ .CAST.castName }}
openebs.io/cas-type: cstor
ownerReferences:
- apiVersion: openebs.io/v1alpha1
blockOwnerDeletion: true
controller: true
kind: StoragePoolClaim
name: {{$storagePool.owner}}
uid: {{ .TaskResult.getspc.objectUID }}
spec:
group:
{{- range $k, $v := $storagePool.blockDeviceList }}
- blockDevice:
{{- range $ki, $blockDevice := $v.blockDevice }}
- name: {{$blockDevice.name}}
inUseByPool: true
deviceID: {{$blockDevice.deviceID}}
{{- end }}
{{- end }}
poolSpec:
poolType: {{$storagePool.poolType}}
cacheFile: {{$storagePool.poolCacheFile}}
overProvisioning: false
roThresholdLimit: {{$storagePool.poolROThreshold}}
status:
phase: Init
versionDetails:
status:
current: {{ .CAST.version }}
dependentsUpgraded: true
desired: {{ .CAST.version }}
autoUpgrade: false
---
apiVersion: openebs.io/v1alpha1
kind: RunTask
metadata:
name: cstor-pool-create-putcstorpooldeployment-default
spec:
meta: |
runNamespace: {{.Config.RunNamespace.value}}
apiVersion: apps/v1
kind: Deployment
action: put
id: putcstorpooldeployment
post: |
{{- jsonpath .JsonResult "{.metadata.name}" | trim | addTo "putcstorpooldeployment.objectName" .TaskResult | noop -}}
{{- jsonpath .JsonResult "{.metadata.uid}" | trim | addTo "putcstorpooldeployment.objectUID" .TaskResult | noop -}}
task: |
{{- $isTolerations := .Config.Tolerations.value | default "none" -}}
{{- $tolerationsVal := fromYaml .Config.Tolerations.value -}}
{{- $setResourceRequests := .Config.PoolResourceRequests.value | default "none" -}}
{{- $resourceRequestsVal := fromYaml .Config.PoolResourceRequests.value -}}
{{- $setResourceLimits := .Config.PoolResourceLimits.value | default "none" -}}
{{- $resourceLimitsVal := fromYaml .Config.PoolResourceLimits.value -}}
{{- $setAuxResourceRequests := .Config.AuxResourceRequests.value | default "none" -}}
{{- $auxResourceRequestsVal := fromYaml .Config.AuxResourceRequests.value -}}
{{- $setAuxResourceLimits := .Config.AuxResourceLimits.value | default "none" -}}
{{- $auxResourceLimitsVal := fromYaml .Config.AuxResourceLimits.value -}}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{.TaskResult.putcstorpoolcr.objectName}}
labels:
openebs.io/storage-pool-claim: {{.Storagepool.owner}}
openebs.io/cstor-pool: {{.TaskResult.putcstorpoolcr.objectName}}
app: cstor-pool
openebs.io/version: {{ .CAST.version }}
openebs.io/cas-template-name: {{ .CAST.castName }}
annotations:
openebs.io/monitoring: pool_exporter_prometheus
ownerReferences:
- apiVersion: openebs.io/v1alpha1
blockOwnerDeletion: true
controller: true
kind: CStorPool
name: {{ .TaskResult.putcstorpoolcr.objectName }}
uid: {{ .TaskResult.putcstorpoolcr.objectUID }}
spec:
strategy:
type: Recreate
replicas: 1
selector:
matchLabels:
app: cstor-pool
template:
metadata:
labels:
app: cstor-pool
openebs.io/storage-pool-claim: {{.Storagepool.owner}}
openebs.io/cstor-pool: {{.TaskResult.putcstorpoolcr.objectName}}
openebs.io/version: {{ .CAST.version }}
annotations:
openebs.io/monitoring: pool_exporter_prometheus
prometheus.io/path: /metrics
prometheus.io/port: "9500"
prometheus.io/scrape: "true"
cluster-autoscaler.kubernetes.io/safe-to-evict: "false"
spec:
serviceAccountName: {{ .Config.ServiceAccountName.value }}
nodeSelector:
kubernetes.io/hostname: {{.Storagepool.nodeName}}
containers:
- name: cstor-pool
image: {{ .Config.CstorPoolImage.value }}
resources:
{{- if ne $setResourceLimits "none" }}
limits:
{{- range $rKey, $rLimit := $resourceLimitsVal }}
{{ $rKey }}: {{ $rLimit }}
{{- end }}
{{- end }}
{{- if ne $setResourceRequests "none" }}
requests:
{{- range $rKey, $rReq := $resourceRequestsVal }}
{{ $rKey }}: {{ $rReq }}
{{- end }}
{{- end }}
ports:
- containerPort: 12000
protocol: TCP
- containerPort: 3233
protocol: TCP
- containerPort: 3232
protocol: TCP
livenessProbe:
exec:
command:
- /bin/sh
- -c
## timeout 120 is added to exit the command forcefully with non-zero exit code if command takes
## more than 120 seconds.
- timeout 120 zfs set io.openebs:livenesstimestamp="$(date +%s)" cstor-$OPENEBS_IO_CSTOR_ID
failureThreshold: 3
initialDelaySeconds: 300
## how often (in seconds) to perform the probe
periodSeconds: 60
## Number of seconds after which the probe times out. i.e informing
## to kubelet probe should timeout after 150 seconds(Note: It will
## not honour because of timeout 120 value before command)
timeoutSeconds: 150
securityContext:
privileged: true
volumeMounts:
- name: device
mountPath: /dev
- name: storagepath
mountPath: /var/openebs/cstor-pool
- name: tmp
mountPath: /tmp
- name: sparse
mountPath: {{ .Config.SparseDir.value }}
- name: udev
mountPath: /run/udev
- name: sockfile
mountPath: /var/tmp/sock
env:
# OPENEBS_IO_CSTOR_ID env has UID of cStorPool CR.
- name: OPENEBS_IO_CSTOR_ID
value: {{.TaskResult.putcstorpoolcr.objectUID}}
# To avoid clash between terminating and restarting pod
# in case older zrepl gets deleted faster, we keep initial delay
lifecycle:
postStart:
exec:
command: ["/bin/sh", "-c", "sleep 2"]
- name: cstor-pool-mgmt
image: {{ .Config.CstorPoolMgmtImage.value }}
resources:
{{- if ne $setAuxResourceRequests "none" }}
requests:
{{- range $rKey, $rLimit := $auxResourceRequestsVal }}
{{ $rKey }}: {{ $rLimit }}
{{- end }}
{{- end }}
{{- if ne $setAuxResourceLimits "none" }}
limits:
{{- range $rKey, $rLimit := $auxResourceLimitsVal }}
{{ $rKey }}: {{ $rLimit }}
{{- end }}
{{- end }}
securityContext:
privileged: true
volumeMounts:
- name: device
mountPath: /dev
- name: tmp
mountPath: /tmp
- name: storagepath
mountPath: /var/openebs/cstor-pool
- name: sparse
mountPath: {{ .Config.SparseDir.value }}
- name: udev
mountPath: /run/udev
- name: sockfile
mountPath: /var/tmp/sock
env:
# OPENEBS_IO_CSTOR_ID env has UID of cStorPool CR.
- name: OPENEBS_IO_CSTOR_ID
value: {{.TaskResult.putcstorpoolcr.objectUID}}
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: RESYNC_INTERVAL
value: {{ .Config.ResyncInterval.value }}
- name: maya-exporter
image: {{ .Config.CstorPoolExporterImage.value }}
resources:
{{- if ne $setAuxResourceRequests "none" }}
requests:
{{- range $rKey, $rLimit := $auxResourceRequestsVal }}
{{ $rKey }}: {{ $rLimit }}
{{- end }}
{{- end }}
{{- if ne $setAuxResourceLimits "none" }}
limits:
{{- range $rKey, $rLimit := $auxResourceLimitsVal }}
{{ $rKey }}: {{ $rLimit }}
{{- end }}
{{- end }}
command:
- maya-exporter
args:
- "-e=pool"
ports:
- containerPort: 9500
protocol: TCP
securityContext:
privileged: true
volumeMounts:
- mountPath: /dev
name: device
- name: tmp
mountPath: /tmp
- name: storagepath
mountPath: /var/openebs/cstor-pool
- mountPath: {{ .Config.SparseDir.value }}
name: sparse
- mountPath: /run/udev
name: udev
- name: sockfile
mountPath: /var/tmp/sock
tolerations:
{{- if ne $isTolerations "none" }}
{{- range $k, $v := $tolerationsVal }}
-
{{- range $kk, $vv := $v }}
{{ $kk }}: {{ $vv }}
{{- end }}
{{- end }}
{{- end }}
volumes:
- name: device
hostPath:
# directory location on host
path: /dev
# this field is optional
type: Directory
- name: storagepath
hostPath:
# host dir {{ .Config.OpenebsBaseDir.value }}/cstor-pool/<spc_name> is
# created to avoid clash if two pool pods run on same node.
path: {{ .Config.OpenebsBaseDir.value }}/cstor-pool/{{.Storagepool.owner}}
type: {{ .Config.HostPathType.value }}
## sockfile is used to communicates between side cars and pool container
- name: sockfile
emptyDir: {}
- name: tmp
hostPath:
# host dir {{ .Config.SparseDir.value }}/shared-<uid> is
# created to avoid clash if two pool pods run on same node.
path: {{ .Config.SparseDir.value }}/shared-{{.Storagepool.owner}}
type: {{ .Config.HostPathType.value }}
- name: sparse
hostPath:
path: {{ .Config.SparseDir.value }}
type: {{ .Config.HostPathType.value }}
- name: udev
hostPath:
path: /run/udev
type: Directory
---
apiVersion: openebs.io/v1alpha1
kind: RunTask
metadata:
name: cstor-pool-create-patchstoragepoolclaim-default
spec:
meta: |
id: patchstoragepoolclaim
apiVersion: openebs.io/v1alpha1
kind: StoragePoolClaim
objectName: {{.Storagepool.owner}}
action: patch
task: |-
type: merge
pspec: |-
status:
phase: Online
---
`
// CstorPoolArtifacts returns the cstor pool related artifacts corresponding to
// latest version
func CstorPoolArtifacts() (list artifactList) {
list.Items = append(list.Items, ParseArtifactListFromMultipleYamls(cstorPools{})...)
return
}
type cstorPools struct{}
// FetchYamls returns all the yamls related to cstor pool in a string
// format
//
// NOTE:
// This is an implementation of MultiYamlFetcher
func (c cstorPools) FetchYamls() string {
return cstorPoolYamls
}