/
backup-templates.go
264 lines (254 loc) · 7.91 KB
/
backup-templates.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
package templates
// Templates for backup job lifecycle
// MngClusterActCreateBackupNS creates namespace
const MngClusterActCreateBackupNS string = `
{{ template "actionGVK"}}
{{ template "metadata" . }}
spec:
actionType: Create
kube:
resource: namespace
template:
apiVersion: v1
kind: Namespace
metadata:
name: openshift-talo-backup
labels:
pod-security.kubernetes.io/enforce: privileged
annotations:
workload.openshift.io/allowed: management
`
// MngClusterActCreateSA creates serviceaccount
const MngClusterActCreateSA string = `
{{ template "actionGVK"}}
{{ template "metadata" . }}
spec:
actionType: Create
kube:
resource: serviceaccount
template:
apiVersion: v1
kind: ServiceAccount
metadata:
name: backup-agent
namespace: openshift-talo-backup
`
// MngClusterActCreateRB creates clusterrolebinding
const MngClusterActCreateRB string = `
{{ template "actionGVK"}}
{{ template "metadata" . }}
spec:
actionType: Create
kube:
resource: clusterrolebinding
template:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: backup-agent
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: backup-agent
namespace: openshift-talo-backup
`
// MngClusterActCreateBackupJob creates k8s job
// Security practices recommend only those directories which are essential to the job should be explicitly mounted.
// Thus, the host filesystem is mounted on a need-to-have basis with most volumes configured to have read-only privilege.
// The sysroot directory and log device are the exception in which these volumes are configured with read-write access.
const MngClusterActCreateBackupJob string = `
{{ template "actionGVK" }}
{{ template "metadata" . }}
spec:
actionType: Create
kube:
namespace: openshift-talo-backup
resource: job
template:
apiVersion: batch/v1
kind: Job
metadata:
name: backup-agent
namespace: openshift-talo-backup
annotations:
target.workload.openshift.io/management: '{"effect":"PreferredDuringScheduling"}'
spec:
activeDeadlineSeconds: {{ .JobTimeout }}
backoffLimit: 0
template:
metadata:
name: backup-agent
annotations:
target.workload.openshift.io/management: '{"effect":"PreferredDuringScheduling"}'
spec:
containers:
- args:
- launchBackup
image: {{ .WorkloadImage }}
name: container-image
securityContext:
privileged: true
runAsUser: 0
tty: true
volumeMounts:
- mountPath: /host
name: host
- mountPath: /host/boot
name: host-boot
readOnly: true
- mountPath: /host/dev/log
name: host-dev-log
- mountPath: /host/etc
name: host-etc
- mountPath: /host/proc
name: host-proc
readOnly: true
- mountPath: /host/run
name: host-run
- mountPath: /host/sysroot
name: host-sysroot
- mountPath: /host/tmp
name: host-tmp
- mountPath: /host/usr/bin
name: host-usr-bin
readOnly: true
- mountPath: /host/usr/lib
name: host-usr-lib
readOnly: true
- mountPath: /host/usr/lib64
name: host-usr-lib64
readOnly: true
- mountPath: /host/usr/libexec
name: host-usr-libexec
readOnly: true
- mountPath: /host/usr/local
name: host-usr-local
readOnly: true
- mountPath: /host/usr/share/containers
name: host-usr-share-containers
readOnly: true
- mountPath: /host/var/lib
name: host-var-lib
- mountPath: /host/var/recovery
name: host-var-recovery
- mountPath: /host/var/tmp
name: host-var-tmp
- mountPath: /host/sys/fs/cgroup
name: sys-fs-cgroup
readOnly: true
restartPolicy: Never
serviceAccountName: backup-agent
volumes:
- emptyDir: {}
name: host
- hostPath:
path: /boot
type: Directory
name: host-boot
- hostPath:
path: /dev/log
type: Socket
name: host-dev-log
- hostPath:
path: /etc
type: Directory
name: host-etc
- hostPath:
path: /proc
type: Directory
name: host-proc
- hostPath:
path: /run
type: Directory
name: host-run
- hostPath:
path: /sysroot
type: Directory
name: host-sysroot
- hostPath:
path: /tmp
type: Directory
name: host-tmp
- hostPath:
path: /usr/bin
type: Directory
name: host-usr-bin
- hostPath:
path: /usr/lib
type: Directory
name: host-usr-lib
- hostPath:
path: /usr/lib64
type: Directory
name: host-usr-lib64
- hostPath:
path: /usr/libexec
type: Directory
name: host-usr-libexec
- hostPath:
path: /usr/local
type: Directory
name: host-usr-local
- hostPath:
path: /usr/share/containers
type: Directory
name: host-usr-share-containers
- hostPath:
path: /var/lib
type: Directory
name: host-var-lib
- hostPath:
path: /var/recovery
type: DirectoryOrCreate
name: host-var-recovery
- hostPath:
path: /var/tmp
type: Directory
name: host-var-tmp
- hostPath:
path: /sys/fs/cgroup
type: Directory
name: sys-fs-cgroup
`
// MngClusterActDeleteBackupNS deletes namespace
const MngClusterActDeleteBackupNS string = `
{{ template "actionGVK"}}
{{ template "metadata" . }}
spec:
actionType: Delete
kube:
name: openshift-talo-backup
resource: namespace
`
// MngClusterActDeleteBackupCRB deletes namespace
const MngClusterActDeleteBackupCRB string = `
{{ template "actionGVK"}}
{{ template "metadata" . }}
spec:
actionType: Delete
kube:
name: backup-agent
resource: clusterrolebinding
`
// MngClusterViewBackupJob creates mcv to monitor k8s job
const MngClusterViewBackupJob string = `
{{ template "viewGVK"}}
{{ template "metadata" . }}
spec:
scope:
resource: jobs
name: backup-agent
namespace: openshift-talo-backup
`
// MngClusterViewBackupNS creates mcv to monitor spoke cluster's namespace
const MngClusterViewBackupNS string = `
{{ template "viewGVK"}}
{{ template "metadata" . }}
spec:
scope:
resource: namespaces
name: openshift-talo-backup
`