-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipeline.yml
231 lines (219 loc) · 6.06 KB
/
pipeline.yml
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
---
resource_types:
- name: email
type: registry-image
source:
repository: pcfseceng/email-resource
resources:
- name: config
icon: git
type: git
source: ((k0sctl.config))
- name: backup
icon: git
type: git
source: ((k0sctl.backup))
- name: pingtime
icon: check-network
type: time
source: ((timer.ping))
- name: backuptime
icon: backup-restore
type: time
source: ((timer.backup))
- name: k0sctl
icon: lambda
type: registry-image
source:
repository: omegasquad82/k0sctl-handler
- name: email
icon: email-alert
type: email
source: ((email))
shell_task: &shell_task
image: k0sctl
config: &shell_config
platform: linux
inputs:
- name: backup
optional: true
- name: config
optional: true
- name: restore
optional: true
outputs:
- name: auditlog
- name: backuprepo
k0sctl_task: &k0sctl_task
task: k0sctl
image: k0sctl
config: &k0sctl_config
platform: linux
inputs:
- name: config
optional: true
- name: restore
optional: true
- name: auditlog
optional: true
outputs:
- name: auditlog
- name: backup
- name: config
params: &k0sctl_params
DISABLE_TELEMETRY: ((k0sctl.flags.no_telemetry))
K0SCTL_GPG_KEY: ((k0sctl.cluster.gpg_pair))
K0SCTL_SSH_KEY: ((k0sctl.cluster._key))
run:
path: k0sctl-handler.sh
jobs:
- name: ping
public: true
serial: true
plan:
- do:
- in_parallel:
- get: pingtime
trigger: true
- get: config
trigger: true
- get: k0sctl
- <<: *shell_task
task: discover
config:
<<: *shell_config
run:
path: bash
user: root
args:
- -c
- |
. common.sh
tracerouteSSH config/*.yaml
on_failure: ¬ify_failure
put: email
inputs:
- auditlog
params:
subject_text: "((k0sctl.cluster.name)): k0sctl execution failed"
body_text: "please see attachments for further analysis"
attachment_globs: ["auditlog/*"]
# https://docs.k0sproject.io/latest/k0sctl-install/#install-using-k0sctl
- name: install
serial_groups: [k0sctl]
plan:
- do:
- in_parallel:
- get: config
trigger: true
passed: [ping]
- get: restore
resource: backup
- get: k0sctl
- <<: *k0sctl_task
params:
<<: *k0sctl_params
K0SCTL_CMD_NAME: install
on_failure:
<<: *notify_failure
on_success: ¬ify_success
put: email
inputs:
- auditlog
params:
subject_text: "((k0sctl.cluster.name)): k0sctl execution succeeded"
body_text: "please see attachments for further analysis"
attachment_globs: ["auditlog/*"]
# https://docs.k0sproject.io/latest/backup/#backuprestore-a-k0s-cluster-using-k0sctl
- name: init
serial: true
plan:
- in_parallel:
- get: k0sctl
- <<: *shell_task
task: prepare
config:
<<: *shell_config
params:
key_pair: ((k0sctl.cluster.gpg_pair))
run:
path: bash
user: root
args:
- -c
- |
. common.sh
prepareGPG "$key_pair"
git config --global init.defaultBranch main
git init backuprepo
prepareGIT backuprepo "((k0sctl.cluster.mail))" "((k0sctl.cluster.name))"
initBranch "((k0sctl.backup.branch))" "((k0sctl.cluster.mail))"
on_success:
put: backup
params:
force: true # drop
repository: backuprepo
- name: backup
serial_groups: [k0sctl]
plan:
- do:
- in_parallel:
- get: backuptime
trigger: true
- get: restore
resource: backup
- get: config
trigger: true
passed: [install]
- get: k0sctl
- <<: *k0sctl_task
params:
<<: *k0sctl_params
K0SCTL_CMD_NAME: backup
on_success:
do:
- <<: *shell_task
task: commit-backup
config:
<<: *shell_config
params:
key_pair: ((k0sctl.cluster.gpg_pair))
run:
path: bash
user: root
args:
- -c
- |
. common.sh
BAK="$(pwd)/backup"
prepareGPG "$key_pair"
runCMD git clone restore backuprepo
prepareGIT backuprepo "((k0sctl.cluster.mail))" "((k0sctl.cluster.name))"
runCMD git checkout "((k0sctl.backup.branch))"
runCMD mv -f "$BAK"/* .
commitSigned "$(cat "$BAK"/.message)"
- put: backup
params:
rebase: true
repository: backuprepo
on_failure:
<<: *notify_failure
on_success:
<<: *notify_success
# https://docs.k0sproject.io/latest/reset/#uninstall-a-k0s-cluster-using-k0sctl
- name: uninstall
serial_groups: [k0sctl]
plan:
- do:
- in_parallel:
- get: config
passed: [ping]
- get: k0sctl
- <<: *k0sctl_task
params:
<<: *k0sctl_params
K0SCTL_CMD_NAME: uninstall
on_failure:
<<: *notify_failure
on_success:
<<: *notify_success