Filip Pytloun | e08c488 | 2017-07-03 10:58:26 +0200 | [diff] [blame] | 1 | def common = new com.mirantis.mk.Common() |
| 2 | def salt = new com.mirantis.mk.Salt() |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 3 | def python = new com.mirantis.mk.Python() |
| 4 | def pepperEnv = "pepperEnv" |
Filip Pytloun | e08c488 | 2017-07-03 10:58:26 +0200 | [diff] [blame] | 5 | |
| 6 | targetExpression = TARGET_MINIONS ? TARGET_MINIONS : "E@kvm01.*" |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 7 | timeout(time: 12, unit: 'HOURS') { |
| 8 | node() { |
| 9 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
Filip Pytloun | e08c488 | 2017-07-03 10:58:26 +0200 | [diff] [blame] | 10 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 11 | common.infoMsg("Enforcing kubernetes state..") |
| 12 | stage("Update k8s control") { |
| 13 | salt.enforceState( |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 14 | pepperEnv, |
Filip Pytloun | 88f88b1 | 2017-07-03 12:20:58 +0200 | [diff] [blame] | 15 | targetExpression, |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 16 | 'kubernetes.control', |
| 17 | true |
Filip Pytloun | 88f88b1 | 2017-07-03 12:20:58 +0200 | [diff] [blame] | 18 | ) |
| 19 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 20 | stage("Update components") { |
| 21 | common.infoMsg("Setting up components..") |
| 22 | def extraCommand |
| 23 | try { |
| 24 | extraCommand = EXTRA_COMMAND |
| 25 | } catch (Throwable e) { |
| 26 | extraCommand = null |
| 27 | } |
| 28 | |
| 29 | if (extraCommand) { |
| 30 | salt.cmdRun( |
| 31 | pepperEnv, |
| 32 | targetExpression, |
| 33 | extraCommand |
| 34 | ) |
| 35 | } |
| 36 | out = salt.cmdRun( |
| 37 | pepperEnv, |
| 38 | targetExpression, |
| 39 | '/bin/bash -c \'find /srv/kubernetes/ -type d | grep -v jobs | while read i; do ls $i/*.yml &>/dev/null && (set -x; hyperkube kubectl apply -f $i || echo Command failed; set +x); done; jobs=$(hyperkube kubectl get jobs -o name); find /srv/kubernetes/jobs -type f -name "*.yml" | while read i; do name=$(grep "name:" $i | head -1 | awk "{print $NF}"); echo $jobs|grep $name >/dev/null || (set -x; hyperkube kubectl apply -f $i || echo Command failed; set +x);done\'' |
| 40 | ) |
| 41 | for (entry in out['return']) { |
| 42 | for (node in entry) { |
| 43 | if (node.value =~ /Command failed/) { |
| 44 | error("$node.key: $node.value") |
| 45 | } else { |
| 46 | println "$node.key: $node.value" |
| 47 | } |
Filip Pytloun | e08c488 | 2017-07-03 10:58:26 +0200 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | } |