blob: 5989deafadab91701228ba2e77cd6587a288919c [file] [log] [blame]
Filip Pytloune08c4882017-07-03 10:58:26 +02001def common = new com.mirantis.mk.Common()
2def salt = new com.mirantis.mk.Salt()
chnyda625f4b42017-10-11 14:10:31 +02003def python = new com.mirantis.mk.Python()
4def pepperEnv = "pepperEnv"
Filip Pytloune08c4882017-07-03 10:58:26 +02005
6targetExpression = TARGET_MINIONS ? TARGET_MINIONS : "E@kvm01.*"
7
8node() {
Dmitrii Kabanovf31c8962017-10-12 21:00:30 -07009 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
chnyda625f4b42017-10-11 14:10:31 +020010
Filip Pytloune08c4882017-07-03 10:58:26 +020011 common.infoMsg("Enforcing kubernetes state..")
12 stage("Update k8s control") {
13 salt.enforceState(
chnyda625f4b42017-10-11 14:10:31 +020014 pepperEnv,
Filip Pytloun5bd1f2c2017-07-03 11:11:16 +020015 targetExpression,
16 'kubernetes.control',
Filip Pytloune08c4882017-07-03 10:58:26 +020017 true
18 )
19 }
20 stage("Update components") {
Filip Pytloun68b73102017-07-03 11:23:08 +020021 common.infoMsg("Setting up components..")
Filip Pytloun88f88b12017-07-03 12:20:58 +020022 def extraCommand
23 try {
24 extraCommand = EXTRA_COMMAND
25 } catch (Throwable e) {
26 extraCommand = null
27 }
28
29 if (extraCommand) {
30 salt.cmdRun(
chnyda625f4b42017-10-11 14:10:31 +020031 pepperEnv,
Filip Pytloun88f88b12017-07-03 12:20:58 +020032 targetExpression,
33 extraCommand
34 )
35 }
Filip Pytloune08c4882017-07-03 10:58:26 +020036 out = salt.cmdRun(
chnyda625f4b42017-10-11 14:10:31 +020037 pepperEnv,
Filip Pytloun5bd1f2c2017-07-03 11:11:16 +020038 targetExpression,
Filip Pytloune08c4882017-07-03 10:58:26 +020039 '/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}