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() |
| 3 | |
| 4 | targetExpression = TARGET_MINIONS ? TARGET_MINIONS : "E@kvm01.*" |
| 5 | |
| 6 | node() { |
Filip Pytloun | 5bd1f2c | 2017-07-03 11:11:16 +0200 | [diff] [blame] | 7 | def saltMaster |
| 8 | stage('Connect to Salt master') { |
| 9 | saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 10 | } |
Filip Pytloun | e08c488 | 2017-07-03 10:58:26 +0200 | [diff] [blame] | 11 | common.infoMsg("Enforcing kubernetes state..") |
| 12 | stage("Update k8s control") { |
| 13 | salt.enforceState( |
Filip Pytloun | 5bd1f2c | 2017-07-03 11:11:16 +0200 | [diff] [blame] | 14 | saltMaster, |
| 15 | targetExpression, |
| 16 | 'kubernetes.control', |
Filip Pytloun | e08c488 | 2017-07-03 10:58:26 +0200 | [diff] [blame] | 17 | true |
| 18 | ) |
| 19 | } |
| 20 | stage("Update components") { |
Filip Pytloun | 68b7310 | 2017-07-03 11:23:08 +0200 | [diff] [blame] | 21 | common.infoMsg("Setting up components..") |
Filip Pytloun | 88f88b1 | 2017-07-03 12:20:58 +0200 | [diff] [blame] | 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 | saltMaster, |
| 32 | targetExpression, |
| 33 | extraCommand |
| 34 | ) |
| 35 | } |
Filip Pytloun | e08c488 | 2017-07-03 10:58:26 +0200 | [diff] [blame] | 36 | out = salt.cmdRun( |
Filip Pytloun | 62f9268 | 2017-07-03 11:25:12 +0200 | [diff] [blame] | 37 | saltMaster, |
Filip Pytloun | 5bd1f2c | 2017-07-03 11:11:16 +0200 | [diff] [blame] | 38 | targetExpression, |
Filip Pytloun | e08c488 | 2017-07-03 10:58:26 +0200 | [diff] [blame] | 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 | } |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | } |