blob: 968e4c957c8e7f97658861cef77ecc4bdc23d16c [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.*"
Jakub Josefa63f9862018-01-11 17:58:38 +01007timeout(time: 12, unit: 'HOURS') {
8 node() {
9 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Filip Pytloune08c4882017-07-03 10:58:26 +020010
Jakub Josefa63f9862018-01-11 17:58:38 +010011 common.infoMsg("Enforcing kubernetes state..")
12 stage("Update k8s control") {
13 salt.enforceState(
chnyda625f4b42017-10-11 14:10:31 +020014 pepperEnv,
Filip Pytloun88f88b12017-07-03 12:20:58 +020015 targetExpression,
Jakub Josefa63f9862018-01-11 17:58:38 +010016 'kubernetes.control',
17 true
Filip Pytloun88f88b12017-07-03 12:20:58 +020018 )
19 }
Jakub Josefa63f9862018-01-11 17:58:38 +010020 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 Pytloune08c4882017-07-03 10:58:26 +020048 }
49 }
50 }
51 }
52}