blob: a09ae85331d910038d66e2f3db1e41a9d79e32a0 [file] [log] [blame]
Victor Ryzhenkinef34a022018-06-22 19:36:13 +04001/**
2 * Update kuberentes cluster
3 *
4 * Expected parameters:
5 * SALT_MASTER_CREDENTIALS Credentials to the Salt API.
6 * SALT_MASTER_URL Full Salt API address [https://10.10.10.1:8000].
7 * KUBERNETES_HYPERKUBE_IMAGE Target kubernetes version. May be null in case of reclass-system rollout
8 * KUBERNETES_PAUSE_IMAGE Kubernetes pause image should have same version as hyperkube. May be null in case of reclass-system rollout
9 * TARGET_UPDATES Comma separated list of nodes to update (Valid values are ctl,cmp)
10 * CTL_TARGET Salt targeted kubernetes CTL nodes (ex. I@kubernetes:master). Kubernetes control plane
11 * CMP_TARGET Salt targeted compute nodes (ex. cmp* and 'I@kubernetes:pool') Kubernetes computes
12 * PER_NODE Target nodes will be managed one by one (bool)
Victor Ryzhenkin42e4b382018-09-11 17:57:56 +040013 * SIMPLE_UPGRADE Use previous version of upgrade without conron/drain abilities
14 * UPGRADE_DOCKER Upgrade docker component
Victor Ryzhenkinae22a5a2018-10-12 15:52:27 +040015 * CONFORMANCE_RUN_AFTER Run Kubernetes conformance tests after update
16 * CONFORMANCE_RUN_BEFORE Run Kubernetes conformance tests before update
17 * TEST_K8S_API_SERVER Kubernetes API server address for test execution
18 * ARTIFACTORY_URL Artifactory URL where docker images located. Needed to correctly fetch conformance images.
Aleksei Kasatkinff9d5b52018-10-26 11:47:46 +020019 * UPGRADE_CALICO_V2_TO_V3 Perform Calico upgrade from v2 to v3.
20 * KUBERNETES_CALICO_IMAGE Target calico/node image. May be null in case of reclass-system rollout.
21 * KUBERNETES_CALICO_CALICOCTL_IMAGE Target calico/ctl image. May be null in case of reclass-system rollout.
22 * KUBERNETES_CALICO_CNI_IMAGE Target calico/cni image. May be null in case of reclass-system rollout.
23 * KUBERNETES_CALICO_KUBE_CONTROLLERS_IMAGE Target calico/kube-controllers image. May be null in case of reclass-system rollout.
24 * CALICO_UPGRADE_VERSION Version of "calico-upgrade" utility to be used ("v1.0.5" for Calico v3.1.3 target).
Victor Ryzhenkinef34a022018-06-22 19:36:13 +040025 *
26**/
Aleksei Kasatkin9ce11842018-11-23 14:27:33 +010027import groovy.json.JsonSlurper
28
Victor Ryzhenkinef34a022018-06-22 19:36:13 +040029def common = new com.mirantis.mk.Common()
30def salt = new com.mirantis.mk.Salt()
31def python = new com.mirantis.mk.Python()
Victor Ryzhenkin723bd062018-12-11 17:09:06 +040032def test = new com.mirantis.mk.Test()
Victor Ryzhenkinef34a022018-06-22 19:36:13 +040033
34def updates = TARGET_UPDATES.tokenize(",").collect{it -> it.trim()}
35def pepperEnv = "pepperEnv"
36
Aleksei Kasatkinff9d5b52018-10-26 11:47:46 +020037def POOL = "I@kubernetes:pool"
38def calicoImagesValid = false
39
Aleksei Kasatkin1f4f5ba2018-11-20 18:30:36 +010040ETCD_ENDPOINTS = ""
41
Victor Ryzhenkinef34a022018-06-22 19:36:13 +040042def overrideKubernetesImage(pepperEnv) {
43 def salt = new com.mirantis.mk.Salt()
44
45 def k8sSaltOverrides = """
46 kubernetes_hyperkube_image: ${KUBERNETES_HYPERKUBE_IMAGE}
47 kubernetes_pause_image: ${KUBERNETES_PAUSE_IMAGE}
48 """
49 stage("Override kubernetes images to target version") {
50 salt.setSaltOverrides(pepperEnv, k8sSaltOverrides)
51 }
52}
53
Aleksei Kasatkinff9d5b52018-10-26 11:47:46 +020054def overrideCalicoImages(pepperEnv) {
55 def salt = new com.mirantis.mk.Salt()
56
57 def calicoSaltOverrides = """
58 kubernetes_calico_image: ${KUBERNETES_CALICO_IMAGE}
59 kubernetes_calico_calicoctl_image: ${KUBERNETES_CALICO_CALICOCTL_IMAGE}
60 kubernetes_calico_cni_image: ${KUBERNETES_CALICO_CNI_IMAGE}
61 kubernetes_calico_kube_controllers_image: ${KUBERNETES_CALICO_KUBE_CONTROLLERS_IMAGE}
62 """
63 stage("Override calico images to target version") {
64 salt.setSaltOverrides(pepperEnv, calicoSaltOverrides)
65 }
66}
67
68def downloadCalicoUpgrader(pepperEnv, target) {
69 def salt = new com.mirantis.mk.Salt()
70
71 stage("Downloading calico-upgrade utility") {
72 salt.cmdRun(pepperEnv, target, "rm -f ./calico-upgrade")
73 salt.cmdRun(pepperEnv, target, "wget https://github.com/projectcalico/calico-upgrade/releases/download/${CALICO_UPGRADE_VERSION}/calico-upgrade")
74 salt.cmdRun(pepperEnv, target, "chmod +x ./calico-upgrade")
75 }
76}
77
78def pullCalicoImages(pepperEnv, target) {
79 def salt = new com.mirantis.mk.Salt()
80
81 stage("Pulling updated Calico docker images") {
82 salt.cmdRun(pepperEnv, target, "docker pull ${KUBERNETES_CALICO_IMAGE}")
83 salt.cmdRun(pepperEnv, target, "docker pull ${KUBERNETES_CALICO_CALICOCTL_IMAGE}")
84 salt.cmdRun(pepperEnv, target, "docker pull ${KUBERNETES_CALICO_CNI_IMAGE}")
85 salt.cmdRun(pepperEnv, target, "docker pull ${KUBERNETES_CALICO_KUBE_CONTROLLERS_IMAGE}")
86 }
87}
88
Victor Ryzhenkinef34a022018-06-22 19:36:13 +040089def performKubernetesComputeUpdate(pepperEnv, target) {
90 def salt = new com.mirantis.mk.Salt()
91
92 stage("Execute Kubernetes compute update on ${target}") {
93 salt.enforceState(pepperEnv, target, 'kubernetes.pool')
94 salt.runSaltProcessStep(pepperEnv, target, 'service.restart', ['kubelet'])
95 }
96}
97
98def performKubernetesControlUpdate(pepperEnv, target) {
99 def salt = new com.mirantis.mk.Salt()
100
101 stage("Execute Kubernetes control plane update on ${target}") {
102 salt.enforceStateWithExclude(pepperEnv, target, "kubernetes", "kubernetes.master.setup")
103 // Restart kubelet
104 salt.runSaltProcessStep(pepperEnv, target, 'service.restart', ['kubelet'])
105 }
106}
107
Aleksei Kasatkinff9d5b52018-10-26 11:47:46 +0200108def startCalicoUpgrade(pepperEnv, target) {
109 def salt = new com.mirantis.mk.Salt()
110
111 stage("Starting upgrade using calico-upgrade: migrate etcd schema and lock Calico") {
Aleksei Kasatkinff9d5b52018-10-26 11:47:46 +0200112 def cmd = "export APIV1_ETCD_ENDPOINTS=${ETCD_ENDPOINTS} && " +
113 "export APIV1_ETCD_CA_CERT_FILE=/var/lib/etcd/ca.pem && " +
114 "export APIV1_ETCD_CERT_FILE=/var/lib/etcd/etcd-client.crt && " +
115 "export APIV1_ETCD_KEY_FILE=/var/lib/etcd/etcd-client.key && " +
116 "export ETCD_ENDPOINTS=${ETCD_ENDPOINTS} && " +
117 "export ETCD_CA_CERT_FILE=/var/lib/etcd/ca.pem && " +
118 "export ETCD_CERT_FILE=/var/lib/etcd/etcd-client.crt && " +
119 "export ETCD_KEY_FILE=/var/lib/etcd/etcd-client.key && " +
120 "rm /root/upg_complete -f && " +
121 "./calico-upgrade start --no-prompts --ignore-v3-data > upgrade-start.log && " +
122 "until [ -f /root/upg_complete ]; do sleep 0.1; done && " +
123 "./calico-upgrade complete --no-prompts > upgrade-complete.log && " +
124 "rm /root/upg_complete -f"
125 // "saltArgs = ['async']" doesn't work, so we have to run "cmd.run --async"
126 salt.cmdRun(pepperEnv, "I@salt:master", "salt -C '${target}' cmd.run '${cmd}' --async")
127 salt.cmdRun(pepperEnv, target, "until [ -f /root/upgrade-start.log ]; do sleep 0.1; done")
128 }
129}
130
131def completeCalicoUpgrade(pepperEnv, target) {
132 def salt = new com.mirantis.mk.Salt()
133
134 stage("Complete upgrade using calico-upgrade: unlock Calico") {
135 salt.cmdRun(pepperEnv, target, "echo 'true' > /root/upg_complete")
136 salt.cmdRun(pepperEnv, target, "while [ -f /root/upg_complete ]; do sleep 0.1; done")
137 salt.cmdRun(pepperEnv, target, "cat /root/upgrade-start.log")
138 salt.cmdRun(pepperEnv, target, "cat /root/upgrade-complete.log")
139 }
140}
141
142def performCalicoConfigurationUpdateAndServicesRestart(pepperEnv, target) {
143 def salt = new com.mirantis.mk.Salt()
144
145 stage("Performing Calico configuration update and services restart") {
146 salt.enforceState(pepperEnv, target, "kubernetes.pool.calico")
147 salt.runSaltProcessStep(pepperEnv, target, 'service.restart', ['kubelet'])
148 }
149}
150
Victor Ryzhenkin42e4b382018-09-11 17:57:56 +0400151def cordonNode(pepperEnv, target) {
152 def salt = new com.mirantis.mk.Salt()
153 def originalTarget = "I@kubernetes:master and not ${target}"
154
155 stage("Cordoning ${target} kubernetes node") {
156 def nodeShortName = target.tokenize(".")[0]
157 salt.cmdRun(pepperEnv, originalTarget, "kubectl cordon ${nodeShortName}", true, 1)
158 }
159}
160
161def uncordonNode(pepperEnv, target) {
162 def salt = new com.mirantis.mk.Salt()
163 def originalTarget = "I@kubernetes:master and not ${target}"
164
165 stage("Uncordoning ${target} kubernetes node") {
166 def nodeShortName = target.tokenize(".")[0]
167 salt.cmdRun(pepperEnv, originalTarget, "kubectl uncordon ${nodeShortName}", true, 1)
168 }
169}
170
171def drainNode(pepperEnv, target) {
172 def salt = new com.mirantis.mk.Salt()
173 def originalTarget = "I@kubernetes:master and not ${target}"
174
175 stage("Draining ${target} kubernetes node") {
176 def nodeShortName = target.tokenize(".")[0]
177 salt.cmdRun(pepperEnv, originalTarget, "kubectl drain --force --ignore-daemonsets --grace-period 100 --timeout 300s --delete-local-data ${nodeShortName}", true, 1)
178 }
179}
180
181def regenerateCerts(pepperEnv, target) {
182 def salt = new com.mirantis.mk.Salt()
183
184 stage("Regenerate certs for ${target}") {
185 salt.enforceState(pepperEnv, target, 'salt.minion.cert')
186 }
187}
188
Victor Ryzhenkinae909182018-10-02 17:49:18 +0400189def updateAddons(pepperEnv, target) {
190 def salt = new com.mirantis.mk.Salt()
191
192 stage("Upgrading Addons at ${target}") {
Victor Ryzhenkin40625bc2018-10-04 16:15:27 +0400193 salt.enforceState(pepperEnv, target, "kubernetes.master.kube-addons")
Victor Ryzhenkinfd9677f2018-10-16 16:14:40 +0400194 }
195}
196
197def updateAddonManager(pepperEnv, target) {
198 def salt = new com.mirantis.mk.Salt()
199
200 stage("Upgrading AddonManager at ${target}") {
Victor Ryzhenkinae909182018-10-02 17:49:18 +0400201 salt.enforceState(pepperEnv, target, "kubernetes.master.setup")
202 }
203}
204
Victor Ryzhenkin42e4b382018-09-11 17:57:56 +0400205def upgradeDocker(pepperEnv, target) {
206 def salt = new com.mirantis.mk.Salt()
207
208 stage("Upgrading docker at ${target}") {
209 salt.enforceState(pepperEnv, target, 'docker.host')
210 }
211}
Victor Ryzhenkinef34a022018-06-22 19:36:13 +0400212
Victor Ryzhenkinae22a5a2018-10-12 15:52:27 +0400213def runConformance(pepperEnv, target, k8s_api, image) {
214 def salt = new com.mirantis.mk.Salt()
215 def containerName = 'conformance_tests'
216 output_file = image.replaceAll('/', '-') + '.output'
217 def output_file_full_path = "/tmp/" + image.replaceAll('/', '-') + '.output'
218 def artifacts_dir = '_artifacts/'
219 salt.cmdRun(pepperEnv, target, "docker rm -f ${containerName}", false)
220 salt.cmdRun(pepperEnv, target, "docker run -d --name ${containerName} --net=host -e API_SERVER=${k8s_api} ${image}")
221 sleep(10)
222
223 print("Waiting for tests to run...")
224 salt.runSaltProcessStep(pepperEnv, target, 'cmd.run', ["docker wait ${containerName}"], null, false)
225
226 print("Writing test results to output file...")
227 salt.runSaltProcessStep(pepperEnv, target, 'cmd.run', ["docker logs -t ${containerName} > ${output_file_full_path}"])
228 print("Conformance test output saved in " + output_file_full_path)
229
230 // collect output
231 sh "mkdir -p ${artifacts_dir}"
232 file_content = salt.getFileContent(pepperEnv, target, '/tmp/' + output_file)
233 writeFile file: "${artifacts_dir}${output_file}", text: file_content
234 sh "cat ${artifacts_dir}${output_file}"
235 try {
236 sh "cat ${artifacts_dir}${output_file} | grep 'Test Suite Failed' && exit 1 || exit 0"
237 } catch (Throwable e) {
238 print("Conformance tests failed. Please check output")
239 currentBuild.result = "FAILURE"
240 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
241 throw e
242 }
243}
244
245def buildImageURL(pepperEnv, target, mcp_repo) {
246 def salt = new com.mirantis.mk.Salt()
247 def raw_version = salt.cmdRun(pepperEnv, target, "kubectl version --short -o json")['return'][0].values()[0].replaceAll('Salt command execution success','')
248 print("Kubernetes version: " + raw_version)
249 def serialized_version = readJSON text: raw_version
250 def short_version = (serialized_version.serverVersion.gitVersion =~ /([v])(\d+\.)(\d+\.)(\d+\-)(\d+)/)[0][0]
251 print("Kubernetes short version: " + short_version)
252 def conformance_image = mcp_repo + "/mirantis/kubernetes/k8s-conformance:" + short_version
253 return conformance_image
254}
255
256def executeConformance(pepperEnv, target, k8s_api, mcp_repo) {
257 stage("Running conformance tests") {
258 def image = buildImageURL(pepperEnv, target, mcp_repo)
259 print("Using image: " + image)
260 runConformance(pepperEnv, target, k8s_api, image)
261 }
262}
263
Victor Ryzhenkin723bd062018-12-11 17:09:06 +0400264def containerDinstalled(pepperEnv, target) {
265 def salt = new com.mirantis.mk.Salt()
266 return salt.cmdRun(pepperEnv, target, "containerd --version 2>1 1>/dev/null && echo 'true' || echo 'false'"
267 )['return'][0].values()[0].replaceAll('Salt command execution success','').trim().toBoolean()
268}
269
270def containerDenabled(pepperEnv, target) {
271 def salt = new com.mirantis.mk.Salt()
Victor Ryzhenkin71ecdf42018-12-11 22:22:50 +0400272 return salt.getPillar(pepperEnv, target, "kubernetes:common:containerd:enabled"
Victor Ryzhenkin723bd062018-12-11 17:09:06 +0400273 )["return"][0].values()[0].toBoolean()
274}
275
276def conformancePodDefExists(pepperEnv, target) {
277 def salt = new com.mirantis.mk.Salt()
278 return salt.cmdRun(pepperEnv, target, "test -e /srv/kubernetes/conformance.yml && echo 'true' || echo 'false'"
279 )['return'][0].values()[0].replaceAll('Salt command execution success','').trim().toBoolean()
280}
281
Aleksei Kasatkinff9d5b52018-10-26 11:47:46 +0200282def checkCalicoUpgradeSuccessful(pepperEnv, target) {
283 def salt = new com.mirantis.mk.Salt()
284
285 stage("Checking cluster state after Calico upgrade") {
286 // TODO add auto-check of results
287 salt.cmdRun(pepperEnv, target, "calicoctl version | grep -i version")
288 salt.cmdRun(pepperEnv, target, "calicoctl node status")
Aleksei Kasatkin1f4f5ba2018-11-20 18:30:36 +0100289 salt.cmdRun(pepperEnv, target, "calicoctl node checksystem")
290 }
291}
292
293def checkCalicoUpgradePossibility(pepperEnv, target) {
294 def salt = new com.mirantis.mk.Salt()
295
296 stage("Verification of Calico upgrade possibility") {
297 // check Calico version
298 def versionResult = salt.cmdRun(
299 pepperEnv, target, "calicoctl version | grep 'Cluster Version'"
300 )['return'][0].values()[0].split("\n")[0].trim()
301 versionStr = (versionResult - "Cluster Version:").trim()
302 version = versionStr.tokenize(".")
303 if ((version.size() < 3) || (version[0] != "v2") || (version[1] != "6") || (version[2].toInteger() < 5)) {
304 error(
305 "Current Calico ${versionStr} cannot be upgraded to v3.x. " +
306 "Calico v2.6.x starting from v2.6.5 can be upgraded. " +
307 "For earlier versions, please update to v2.6.5 first."
308 )
309 }
310 print("Calico version was determined: ${versionStr}")
311
312 // check Calico is switched on
313 def readinessResult = salt.cmdRun(
314 pepperEnv, target, ". /var/lib/etcd/configenv && etcdctl get /calico/v1/Ready"
315 )['return'][0].values()[0].split("\n")[0].trim()
316 print("Calico readiness check result: ${readinessResult}")
317 if (readinessResult != "true") {
318 // try set it to true
319 readinessResult = salt.cmdRun(
320 pepperEnv, target, ". /var/lib/etcd/configenv && etcdctl set /calico/v1/Ready true"
321 )['return'][0].values()[0].split("\n")[0].trim()
322 print("Calico readiness result 2nd attempt: ${readinessResult}")
323 if (readinessResult != "true") {
324 error("Calico is not ready. '/calico/v1/Ready': '${readinessResult}'")
325 }
326 }
327
328 // Calico data upgrade dry-run
329 def cmd = "export APIV1_ETCD_ENDPOINTS=${ETCD_ENDPOINTS} && " +
330 "export APIV1_ETCD_CA_CERT_FILE=/var/lib/etcd/ca.pem && " +
331 "export APIV1_ETCD_CERT_FILE=/var/lib/etcd/etcd-client.crt && " +
332 "export APIV1_ETCD_KEY_FILE=/var/lib/etcd/etcd-client.key && " +
333 "export ETCD_ENDPOINTS=${ETCD_ENDPOINTS} && " +
334 "export ETCD_CA_CERT_FILE=/var/lib/etcd/ca.pem && " +
335 "export ETCD_CERT_FILE=/var/lib/etcd/etcd-client.crt && " +
336 "export ETCD_KEY_FILE=/var/lib/etcd/etcd-client.key && " +
337 "./calico-upgrade dry-run --ignore-v3-data"
338 def dryRunResult = salt.cmdRun(pepperEnv, target, cmd)['return'][0].values()[0]
339 // check dry-run result
340 def validationSuccessStr = "Successfully validated v1 to v3 conversion"
341 if (!dryRunResult.contains(validationSuccessStr)) {
342 error("Calico data upgrade dry-run has failed")
343 }
Aleksei Kasatkinff9d5b52018-10-26 11:47:46 +0200344 }
345}
Victor Ryzhenkinae22a5a2018-10-12 15:52:27 +0400346
Aleksei Kasatkin9ce11842018-11-23 14:27:33 +0100347def checkCalicoPolicySetting(pepperEnv, target) {
348 def common = new com.mirantis.mk.Common()
349 def salt = new com.mirantis.mk.Salt()
350
351 stage("Checking of Calico network policy setting") {
352 // check Calico policy enabled
353 def cniPolicy = false
354 def addonsPolicy = false
355 def kubeCtrlRunning = false
356
357 // check CNI config
358 def cniCfgResult = salt.cmdRun(
359 pepperEnv, target, "cat /etc/cni/net.d/10-calico.conf"
360 )['return'][0].values()[0].toString()
361 def cniCfg = new JsonSlurper().parseText(cniCfgResult)
362 if (cniCfg.get("policy") != null) {
363 if (cniCfg["policy"].get("type") == "k8s") {
364 cniPolicy = true
365 } else {
366 common.warningMsg("Calico policy type is unknown or not set.")
367 }
368 }
369
370 // check k8s addons
371 def addonsResult = salt.cmdRun(
372 pepperEnv, target, "ls /etc/kubernetes/addons"
373 )['return'][0].values()[0].toString()
374 if (addonsResult.contains("calico_policy")) {
375 addonsPolicy = true
376 }
377
378 // check kube-controllers is running
379 def kubeCtrlResult = salt.cmdRun(
380 pepperEnv, target, "kubectl get pod -n kube-system --selector=k8s-app=calico-kube-controllers"
381 )['return'][0].values()[0].toString()
382 if (kubeCtrlResult.contains("Running")) {
383 kubeCtrlRunning = true
384 }
385
386 // It's safe to enable Calico policy any time, but it may be unsafe to disable it.
387 // So, no need to disable Calico policy for v3.x if it's not in use currently.
388 // But if Calico policy is in use already, it should be enabled after upgrade as well.
389
390 // check for consistency
391 if ((cniPolicy != addonsPolicy) || (addonsPolicy != kubeCtrlRunning)) {
392 caution = "ATTENTION. Calico policy setting cannot be determined reliably (enabled in CNI config: ${cniPolicy}, " +
393 "presence in k8s addons: ${addonsPolicy}, kube-controllers is running: ${kubeCtrlRunning})."
394 currentBuild.description += "<br><b>${caution}</b><br><br>"
395 common.warningMsg(caution)
396 } else {
397 common.infoMsg("Current Calico policy state is detected as: ${cniPolicy}")
398 if (cniPolicy) {
399 // Calico policy is in use. Check policy setting for v3.x.
400 common.infoMsg("Calico policy is in use. It should be enabled for v3.x as well.")
401 def saltPolicyResult = salt.getPillar(
402 pepperEnv, target, "kubernetes:pool:network:calico:policy"
403 )["return"][0].values()[0].toString()
404
405 common.infoMsg("kubernetes.pool.network.calico.policy: ${saltPolicyResult}")
406 if (saltPolicyResult.toLowerCase().contains("true")) {
407 common.infoMsg("Calico policy setting for v3.x is detected as: true")
408 } else {
409 caution = "ATTENTION. Currently, Calico is running with policy switched on. " +
410 "Calico policy setting for v3.x is not set to true. " +
411 "After upgrade is completed, Calico policy will be switched off. " +
412 "You will need to switch it on manually if required."
413 currentBuild.description += "<br><b>${caution}</b><br><br>"
414 common.warningMsg(caution)
415 }
416 }
417 }
418
419 if (addonsPolicy) {
420 // Remove v2.6.x policy-related addons on masters to not interfere with v3.x kube-controllers
421 salt.cmdRun(pepperEnv, CTL_TARGET, "rm -rf /etc/kubernetes/addons/calico_policy")
422 }
423 }
424}
425
Victor Ryzhenkinef34a022018-06-22 19:36:13 +0400426timeout(time: 12, unit: 'HOURS') {
427 node() {
428 try {
429
430 stage("Setup virtualenv for Pepper") {
431 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
432 }
433
Victor Ryzhenkinae22a5a2018-10-12 15:52:27 +0400434 if (CONFORMANCE_RUN_BEFORE.toBoolean()) {
435 def target = CTL_TARGET
436 def mcp_repo = ARTIFACTORY_URL
437 def k8s_api = TEST_K8S_API_SERVER
438 firstTarget = salt.getFirstMinion(pepperEnv, target)
Victor Ryzhenkin723bd062018-12-11 17:09:06 +0400439 def containerd_enabled = containerDenabled(pepperEnv, firstTarget)
440 def containerd_installed = containerDinstalled(pepperEnv, firstTarget)
441 def conformance_pod_ready = conformancePodDefExists(pepperEnv, firstTarget)
442 if (containerd_enabled && containerd_installed && conformance_pod_ready) {
443 def config = ['master': pepperEnv,
444 'target': firstTarget,
445 'junitResults': false,
446 'autodetect': true]
447 test.executeConformance(config)
448 } else {
449 executeConformance(pepperEnv, firstTarget, k8s_api, mcp_repo)
450 }
Victor Ryzhenkinae22a5a2018-10-12 15:52:27 +0400451 }
452
Victor Ryzhenkinef34a022018-06-22 19:36:13 +0400453 if ((common.validInputParam('KUBERNETES_HYPERKUBE_IMAGE')) && (common.validInputParam('KUBERNETES_PAUSE_IMAGE'))) {
454 overrideKubernetesImage(pepperEnv)
455 }
456
Aleksei Kasatkinff9d5b52018-10-26 11:47:46 +0200457 if ((common.validInputParam('KUBERNETES_CALICO_IMAGE'))
458 && (common.validInputParam('KUBERNETES_CALICO_CALICOCTL_IMAGE'))
459 && (common.validInputParam('KUBERNETES_CALICO_CNI_IMAGE'))
460 && (common.validInputParam('KUBERNETES_CALICO_KUBE_CONTROLLERS_IMAGE'))
461 ) {
462 calicoImagesValid = true
463 overrideCalicoImages(pepperEnv)
464 }
465
Victor Ryzhenkinef34a022018-06-22 19:36:13 +0400466 /*
Aleksei Kasatkinff9d5b52018-10-26 11:47:46 +0200467 * Execute Calico upgrade if needed (only for v2 to v3 upgrade).
468 * This part causes workloads operations downtime.
469 * It is only required for Calico v2.x to v3.x upgrade when etcd is in use for Calico
470 * as Calico etcd schema has different formats for Calico v2.x and Calico v3.x.
471 */
472 if (UPGRADE_CALICO_V2_TO_V3.toBoolean()) {
473 // one CTL node will be used for running upgrade of Calico etcd schema
474 def ctl_node = salt.getMinionsSorted(pepperEnv, CTL_TARGET)[0]
475
Aleksei Kasatkin1f4f5ba2018-11-20 18:30:36 +0100476 // get ETCD_ENDPOINTS in use by Calico
477 def ep_str = salt.cmdRun(pepperEnv, ctl_node, "cat /etc/calico/calicoctl.cfg | grep etcdEndpoints")['return'][0].values()[0]
478 ETCD_ENDPOINTS = ep_str.split("\n")[0].tokenize(' ')[1]
479 print("ETCD_ENDPOINTS in use by Calico: '${ETCD_ENDPOINTS}'")
480
481 // download calico-upgrade utility
Aleksei Kasatkinff9d5b52018-10-26 11:47:46 +0200482 downloadCalicoUpgrader(pepperEnv, ctl_node)
Aleksei Kasatkin1f4f5ba2018-11-20 18:30:36 +0100483
484 // check the possibility of upgrading of Calico
485 checkCalicoUpgradePossibility(pepperEnv, ctl_node)
486
487 // prepare for upgrade. when done in advance, this will decrease downtime during upgrade
Aleksei Kasatkinff9d5b52018-10-26 11:47:46 +0200488 if (calicoImagesValid) {
489 pullCalicoImages(pepperEnv, POOL)
490 }
491
Aleksei Kasatkin9ce11842018-11-23 14:27:33 +0100492 // check and adjust Calico policy setting
493 checkCalicoPolicySetting(pepperEnv, ctl_node)
494
Aleksei Kasatkinff9d5b52018-10-26 11:47:46 +0200495 // this sequence implies workloads operations downtime
496 startCalicoUpgrade(pepperEnv, ctl_node)
497 performCalicoConfigurationUpdateAndServicesRestart(pepperEnv, POOL)
498 completeCalicoUpgrade(pepperEnv, ctl_node)
499 // after that no downtime is expected
500
501 checkCalicoUpgradeSuccessful(pepperEnv, POOL)
502 }
503
504 /*
505 * Execute k8s update
Victor Ryzhenkinef34a022018-06-22 19:36:13 +0400506 */
507 if (updates.contains("ctl")) {
508 def target = CTL_TARGET
509
510 if (PER_NODE.toBoolean()) {
511 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
512
513 for (t in targetHosts) {
Victor Ryzhenkin42e4b382018-09-11 17:57:56 +0400514 if (SIMPLE_UPGRADE.toBoolean()) {
515 performKubernetesControlUpdate(pepperEnv, t)
516 } else {
517 cordonNode(pepperEnv, t)
518 drainNode(pepperEnv, t)
519 regenerateCerts(pepperEnv, t)
520 if (UPGRADE_DOCKER.toBoolean()) {
521 upgradeDocker(pepperEnv, t)
522 }
523 performKubernetesControlUpdate(pepperEnv, t)
Victor Ryzhenkinfd9677f2018-10-16 16:14:40 +0400524 updateAddonManager(pepperEnv, t)
Victor Ryzhenkin42e4b382018-09-11 17:57:56 +0400525 uncordonNode(pepperEnv, t)
526 }
Victor Ryzhenkinef34a022018-06-22 19:36:13 +0400527 }
528 } else {
529 performKubernetesControlUpdate(pepperEnv, target)
530 }
Victor Ryzhenkinfd9677f2018-10-16 16:14:40 +0400531 if (!SIMPLE_UPGRADE.toBoolean()) {
Aleksei Kasatkinff9d5b52018-10-26 11:47:46 +0200532 // Addons upgrade should be performed after all nodes will be upgraded
Victor Ryzhenkinfd9677f2018-10-16 16:14:40 +0400533 updateAddons(pepperEnv, target)
534 // Wait for 90 sec for addons reconciling
535 sleep(90)
536 }
Victor Ryzhenkinef34a022018-06-22 19:36:13 +0400537 }
538
539 if (updates.contains("cmp")) {
540 def target = CMP_TARGET
541
542 if (PER_NODE.toBoolean()) {
543 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
544
545 for (t in targetHosts) {
Victor Ryzhenkin42e4b382018-09-11 17:57:56 +0400546 if (SIMPLE_UPGRADE.toBoolean()) {
547 performKubernetesComputeUpdate(pepperEnv, t)
548 } else {
549 cordonNode(pepperEnv, t)
550 drainNode(pepperEnv, t)
551 regenerateCerts(pepperEnv, t)
552 if (UPGRADE_DOCKER.toBoolean()) {
553 upgradeDocker(pepperEnv, t)
554 }
555 performKubernetesComputeUpdate(pepperEnv, t)
556 uncordonNode(pepperEnv, t)
557 }
Victor Ryzhenkinef34a022018-06-22 19:36:13 +0400558 }
559 } else {
560 performKubernetesComputeUpdate(pepperEnv, target)
561 }
562 }
Victor Ryzhenkinae22a5a2018-10-12 15:52:27 +0400563
564 if (CONFORMANCE_RUN_AFTER.toBoolean()) {
565 def target = CTL_TARGET
566 def mcp_repo = ARTIFACTORY_URL
567 def k8s_api = TEST_K8S_API_SERVER
568 firstTarget = salt.getFirstMinion(pepperEnv, target)
Victor Ryzhenkin723bd062018-12-11 17:09:06 +0400569 def containerd_enabled = containerDenabled(pepperEnv, firstTarget)
570 def containerd_installed = containerDinstalled(pepperEnv, firstTarget)
571 def conformance_pod_ready = conformancePodDefExists(pepperEnv, firstTarget)
572 if (containerd_enabled && containerd_installed && conformance_pod_ready) {
573 def config = ['master': pepperEnv,
574 'target': firstTarget,
575 'junitResults': false,
576 'autodetect': true]
577 test.executeConformance(config)
578 } else {
579 executeConformance(pepperEnv, firstTarget, k8s_api, mcp_repo)
580 }
Victor Ryzhenkinae22a5a2018-10-12 15:52:27 +0400581 }
Victor Ryzhenkinef34a022018-06-22 19:36:13 +0400582 } catch (Throwable e) {
583 // If there was an error or exception thrown, the build failed
584 currentBuild.result = "FAILURE"
585 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
586 throw e
587 }
588 }
589}