blob: 5a0bf9dcc601815afe807e0d0662fb902c55984e [file] [log] [blame]
Filip Pytloune08c4882017-07-03 10:58:26 +02001def common = new com.mirantis.mk.Common()
2def salt = new com.mirantis.mk.Salt()
3
4targetExpression = TARGET_MINIONS ? TARGET_MINIONS : "E@kvm01.*"
5
6node() {
Filip Pytloun5bd1f2c2017-07-03 11:11:16 +02007 def saltMaster
8 stage('Connect to Salt master') {
9 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
10 }
Filip Pytloune08c4882017-07-03 10:58:26 +020011 common.infoMsg("Enforcing kubernetes state..")
12 stage("Update k8s control") {
13 salt.enforceState(
Filip Pytloun5bd1f2c2017-07-03 11:11:16 +020014 saltMaster,
15 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(
31 saltMaster,
32 targetExpression,
33 extraCommand
34 )
35 }
Filip Pytloune08c4882017-07-03 10:58:26 +020036 out = salt.cmdRun(
Filip Pytloun62f92682017-07-03 11:25:12 +020037 saltMaster,
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}