summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Anderson <craig.cigar.anderson@gmail.com>2018-11-29 01:47:48 +0000
committerCraig Anderson <craig.cigar.anderson@gmail.com>2018-12-04 18:22:51 +0000
commit012800d854acce0c9ab9fa02ffb1845e66c144af (patch)
treeba81aae4a12eb09ec1a72d5e5b6c911a8bbdc7c3
parent0731ac5d3a2d4c63dab0b9f519f403b6548bcce0 (diff)
Add new divingbell-exec module
Stopgap module to provide generic node exec capability until shift to [0] and [1]. [0] https://github.com/GoogleCloudPlatform/metacontroller [1] https://github.com/argoproj/argo Change-Id: I278548e1e09ed31dcc4212142f1e6465ee8d9792
Notes
Notes (review): Code-Review+2: Scott Hussey <sthussey@att.com> Code-Review+2: Aaron Sheffield <ajs@sheffieldfamily.net> Workflow+1: Aaron Sheffield <ajs@sheffieldfamily.net> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Mon, 10 Dec 2018 15:19:55 +0000 Reviewed-on: https://review.openstack.org/620765 Project: openstack/airship-divingbell Branch: refs/heads/master
-rw-r--r--divingbell/templates/bin/_exec.sh.tpl163
-rw-r--r--divingbell/templates/bin/_sysctl.sh.tpl6
-rw-r--r--divingbell/templates/daemonset-exec.yaml71
-rw-r--r--divingbell/templates/secret-exec.yaml29
-rw-r--r--divingbell/values.yaml12
-rw-r--r--doc/source/index.rst82
-rwxr-xr-xtools/gate/scripts/020-test-divingbell.sh225
7 files changed, 584 insertions, 4 deletions
diff --git a/divingbell/templates/bin/_exec.sh.tpl b/divingbell/templates/bin/_exec.sh.tpl
new file mode 100644
index 0000000..a042d55
--- /dev/null
+++ b/divingbell/templates/bin/_exec.sh.tpl
@@ -0,0 +1,163 @@
1#!/bin/bash
2
3{{/*
4# Copyright 2017 AT&T Intellectual Property. All other rights reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17*/}}
18
19set -e
20
21cat <<'UNIQUE_EOF_9c341059-25a0-4725-9489-1789e255e381' > {{ .Values.conf.chroot_mnt_path | quote }}/tmp/exec_host_{{ .Chart.Version }}.sh
22{{ include "divingbell.shcommon" . }}
23
24exec_path='/var/divingbell/exec'
25
26if [ ! -d "${exec_path}" ]; then
27 mkdir -p "${exec_path}"
28fi
29
30write_test "${exec_path}"
31cd "${exec_path}"
32
33{{- if hasKey .Values.conf "exec" }}
34 {{- $sorted_keys := keys $.Values.conf.exec | sortAlpha }}
35
36 {{- range $index, $script := $sorted_keys }}
37 {{- $keypath := index $.Values.conf.exec $script }}
38
39 {{/* Need to sort key/values before assessing hash, since helm only preserves order for lists */}}
40 {{- $_ := set $.Values "__values_hash" list }}
41 {{- range $i, $k := ($keypath | keys | sortAlpha) }}
42 {{/* env is the only nested dict, so the same operation needs to be repeated there lacking helm recursion */}}
43 {{- if eq $k "env" }}
44 {{- range $i2, $k2 := ($keypath.env | keys | sortAlpha) }}
45 {{- $_ := set $.Values "__values_hash" (append $.Values.__values_hash (print $.Values.__values_hash ";" ($k | toString) ":" ($k2 | toString) ":" (index $keypath.env $k2 | toString))) }}
46 {{- end }}
47 {{- else }}
48 {{- $_ := set $.Values "__values_hash" (append $.Values.__values_hash (print $.Values.__values_hash ";" ($k | toString) ":" (index $keypath $k | toString))) }}
49 {{- end }}
50 {{- end }}
51 {{- $hash := $.Values.__values_hash | toString | sha256sum }}
52
53 hash={{ $hash | squote }}
54 if [ ! -d "${hash}" ]; then
55 mkdir -p "${hash}"
56 fi
57
58 {{- $_ := set $.Values "__rerun_policy" "always" }}
59 {{- if hasKey $keypath "rerun_policy" }}
60 {{- if and (not (eq $keypath.rerun_policy "always")) (not (eq $keypath.rerun_policy "never")) (not (eq $keypath.rerun_policy "once_successfully")) }}
61 {{- fail (print "BAD 'rerun_policy' FOR '" $script "': Got '" $keypath.rerun_policy "', but expected 'always', 'never', or 'once_successfully'.") }}
62 {{- end }}
63 {{- $_ := set $.Values "__rerun_policy" $keypath.rerun_policy }}
64 {{- end }}
65
66 {{- $_ := set $.Values "__blocking_policy" "foreground" }}
67 {{- if hasKey $keypath "blocking_policy" }}
68 {{- if and (not (eq $keypath.blocking_policy "foreground")) (not (eq $keypath.blocking_policy "background")) (not (eq $keypath.blocking_policy "foreground_halt_pod_on_failure")) }}
69 {{- fail (print "BAD 'blocking_policy' FOR '" $script "': Got '" $keypath.blocking_policy "', but expected 'foreground', 'background', or 'foreground_halt_pod_on_failure'.") }}
70 {{- end }}
71 {{- if eq $keypath.blocking_policy "background" }}
72 {{- fail (print "NOT IMPLEMENTED: 'blocking_policy' FOR '" $script "'") }}
73 {{- end }}
74 {{- $_ := set $.Values "__blocking_policy" $keypath.blocking_policy }}
75 {{- end }}
76
77 {{- $_ := set $.Values "__timeout" 3600 }}
78 {{- if hasKey $keypath "timeout" }}
79 {{- fail (print "NOT IMPLEMENTED: 'timeout' FOR '" $script "'") }}
80 {{- $_ := set $.Values "__timeout" $keypath.timeout }}
81 {{- end }}
82
83 {{- $_ := set $.Values "__rerun_interval" "infinite" }}
84 {{- if hasKey $keypath "rerun_interval" }}
85 {{- fail (print "NOT IMPLEMENTED: 'rerun_interval' FOR '" $script "'") }}
86 {{- $_ := set $.Values "__rerun_interval" $keypath.rerun_interval }}
87 {{- end }}
88
89 {{- $_ := set $.Values "__rerun_interval_persist" "false" }}
90 {{- if hasKey $keypath "rerun_interval_persist" }}
91 {{- fail (print "NOT IMPLEMENTED: 'rerun_interval_persist' FOR '" $script "'") }}
92 {{- $_ := set $.Values "__rerun_interval_persist" $keypath.rerun_interval_persist }}
93 {{- end }}
94
95 {{- $_ := set $.Values "__rerun_max_count" "infinite" }}
96 {{- if hasKey $keypath "rerun_max_count" }}
97 {{- fail (print "NOT IMPLEMENTED: 'rerun_max_count' FOR '" $script "'") }}
98 {{- $_ := set $.Values "__rerun_max_count" $keypath.rerun_max_count }}
99 {{- end }}
100
101 {{- $_ := set $.Values "__retry_interval" $.Values.__rerun_interval }}
102 {{- if hasKey $keypath "retry_interval" }}
103 {{- fail (print "NOT IMPLEMENTED: 'retry_interval' FOR '" $script "'") }}
104 {{- $_ := set $.Values "__retry_interval" $keypath.retry_interval }}
105 {{- end }}
106
107 {{- $_ := set $.Values "__retry_interval_persist" "false" }}
108 {{- if hasKey $keypath "retry_interval_persist" }}
109 {{- fail (print "NOT IMPLEMENTED: 'retry_interval_persist' FOR '" $script "'") }}
110 {{- $_ := set $.Values "__retry_interval_persist" $keypath.retry_interval_persist }}
111 {{- end }}
112
113 {{- $_ := set $.Values "__retry_max_count" "infinite" }}
114 {{- if hasKey $keypath "retry_max_count" }}
115 {{- fail (print "NOT IMPLEMENTED: 'retry_max_count' FOR '" $script "'") }}
116 {{- $_ := set $.Values "__retry_max_count" $keypath.retry_max_count }}
117 {{- end }}
118 cat <<'UNIQUE_EOF_1840dbd4-09e1-4725-87f5-3b6944b80526' > {{ $script }}
119{{ $keypath.data }}
120UNIQUE_EOF_1840dbd4-09e1-4725-87f5-3b6944b80526
121 chmod 700 {{ $script }}
122 if [[ {{ $.Values.__rerun_policy }} = always ]] || \
123 [[ ! -f ${hash}/exit_code ]] || \
124 ([[ {{ $.Values.__rerun_policy }} = once_successfully ]] && \
125 [[ -f ${hash}/exit_code ]] && \
126 [[ $(cat ${hash}/exit_code) != 0 ]]); then
127 {{- if hasKey $keypath "env" }}
128 {{- range $env_key, $env_val := $keypath.env }}
129 {{ $env_key }}={{ $env_val | squote }} \
130 {{- end }}
131 {{- end }}
132 ./{{ $script | squote }} \
133 {{- if hasKey $keypath "args" }}
134 {{- range $arg := $keypath.args }}
135 {{ $arg | squote }} \
136 {{- end }}
137 {{- end }}
138 && echo 0 > "${hash}/exit_code" || echo $? > "${hash}/exit_code"
139 {{- if hasKey $keypath "blocking_policy" }}
140 {{- if eq $keypath.blocking_policy "foreground_halt_pod_on_failure" }}
141 if [[ $(cat "${hash}/exit_code") != '0' ]]; then
142 die "Killing pod due to non-zero exit code from '{{ $script }}'."
143 fi
144 {{- end }}
145 {{- end }}
146 fi
147 {{ end }}
148{{- end }}
149
150exit 0
151UNIQUE_EOF_9c341059-25a0-4725-9489-1789e255e381
152
153chmod 700 {{ .Values.conf.chroot_mnt_path | quote }}/tmp/exec_host_{{ .Chart.Version }}.sh
154chroot {{ .Values.conf.chroot_mnt_path | quote }} /tmp/exec_host_{{ .Chart.Version }}.sh
155
156sleep 1
157echo 'INFO Putting the daemon to sleep.'
158
159while [ 1 ]; do
160 sleep 300
161done
162
163exit 0
diff --git a/divingbell/templates/bin/_sysctl.sh.tpl b/divingbell/templates/bin/_sysctl.sh.tpl
index 064f68b..43e3401 100644
--- a/divingbell/templates/bin/_sysctl.sh.tpl
+++ b/divingbell/templates/bin/_sysctl.sh.tpl
@@ -96,9 +96,9 @@ add_sysctl_param {{ $key | squote }} {{ $value | squote }}
96# Revert any previously applied sysctl settings which are now absent 96# Revert any previously applied sysctl settings which are now absent
97prev_files="$(find "${defaults_path}" -type f)" 97prev_files="$(find "${defaults_path}" -type f)"
98if [ -n "${prev_files}" ]; then 98if [ -n "${prev_files}" ]; then
99 basename -a ${prev_files} | sort > /tmp/prev_settings 99 basename -a ${prev_files} | sort > /tmp/prev_sysctl
100 echo "${curr_settings}" | sort > /tmp/curr_settings 100 echo "${curr_settings}" | sort > /tmp/curr_sysctl
101 revert_list="$(comm -23 /tmp/prev_settings /tmp/curr_settings)" 101 revert_list="$(comm -23 /tmp/prev_sysctl /tmp/curr_sysctl)"
102 IFS=$'\n' 102 IFS=$'\n'
103 for orig_sysctl_setting in ${revert_list}; do 103 for orig_sysctl_setting in ${revert_list}; do
104 rm "${persist_path}/${orig_sysctl_setting}" 104 rm "${persist_path}/${orig_sysctl_setting}"
diff --git a/divingbell/templates/daemonset-exec.yaml b/divingbell/templates/daemonset-exec.yaml
new file mode 100644
index 0000000..c78e7ba
--- /dev/null
+++ b/divingbell/templates/daemonset-exec.yaml
@@ -0,0 +1,71 @@
1{{/*
2# Copyright 2017 AT&T Intellectual Property. All other rights reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15*/}}
16
17{{- define "divingbell.daemonset.exec" }}
18 {{- $daemonset := index . 0 }}
19 {{- $secretName := index . 1 }}
20 {{- $envAll := index . 2 }}
21 {{- with $envAll }}
22---
23apiVersion: extensions/v1beta1
24kind: DaemonSet
25metadata:
26 name: {{ $daemonset }}
27 annotations:
28 {{ tuple $envAll | include "helm-toolkit.snippets.release_uuid" }}
29spec:
30{{ tuple $envAll $daemonset | include "helm-toolkit.snippets.kubernetes_upgrades_daemonset" | indent 2 }}
31 template:
32 metadata:
33 labels:
34{{ list $envAll .Chart.Name $daemonset | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 8 }}
35 spec:
36 hostNetwork: true
37 hostPID: true
38 hostIPC: true
39 containers:
40 - name: {{ $daemonset }}
41 image: {{ .Values.images.divingbell }}
42 imagePullPolicy: {{ .Values.images.pull_policy }}
43{{ tuple $envAll $envAll.Values.pod.resources.exec | include "helm-toolkit.snippets.kubernetes_resources" | indent 8 }}
44 command:
45 - /tmp/{{ $daemonset }}.sh
46 volumeMounts:
47 - name: rootfs-{{ $daemonset }}
48 mountPath: {{ .Values.conf.chroot_mnt_path }}
49 - name: {{ $secretName }}
50 mountPath: /tmp/{{ $daemonset }}.sh
51 subPath: {{ $daemonset }}
52 readOnly: true
53 securityContext:
54 privileged: true
55 volumes:
56 - name: rootfs-{{ $daemonset }}
57 hostPath:
58 path: /
59 - name: {{ $secretName }}
60 secret:
61 secretName: {{ $secretName }}
62 defaultMode: 0555
63 {{- end }}
64{{- end }}
65{{- if .Values.manifests.daemonset_exec }}
66{{- $daemonset := "exec" }}
67{{- $secretName := "divingbell-exec" }}
68{{- $daemonset_yaml := list $daemonset $secretName . | include "divingbell.daemonset.exec" | toString | fromYaml }}
69{{- $secret_include := "divingbell.secret.exec" }}
70{{- list $daemonset $daemonset_yaml $secret_include $secretName . | include "helm-toolkit.utils.daemonset_overrides" }}
71{{- end }}
diff --git a/divingbell/templates/secret-exec.yaml b/divingbell/templates/secret-exec.yaml
new file mode 100644
index 0000000..0288aeb
--- /dev/null
+++ b/divingbell/templates/secret-exec.yaml
@@ -0,0 +1,29 @@
1{{/*
2Copyright 2017 The Openstack-Helm Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/}}
16
17{{- define "divingbell.secret.exec" }}
18{{- $secretName := index . 0 }}
19{{- $envAll := index . 1 }}
20{{- with $envAll }}
21---
22apiVersion: v1
23kind: Secret
24metadata:
25 name: {{ $secretName }}
26data:
27 exec: {{ tuple "bin/_exec.sh.tpl" . | include "helm-toolkit.utils.template" | b64enc }}
28{{- end }}
29{{- end }}
diff --git a/divingbell/values.yaml b/divingbell/values.yaml
index d8351f5..5d3fc55 100644
--- a/divingbell/values.yaml
+++ b/divingbell/values.yaml
@@ -121,6 +121,10 @@ pod:
121 enabled: true 121 enabled: true
122 min_ready_seconds: 0 122 min_ready_seconds: 0
123 max_unavailable: 100% 123 max_unavailable: 100%
124 exec:
125 enabled: true
126 min_ready_seconds: 0
127 max_unavailable: 100%
124 resources: 128 resources:
125 enabled: false 129 enabled: false
126 ethtool: 130 ethtool:
@@ -172,6 +176,13 @@ pod:
172 requests: 176 requests:
173 memory: "128Mi" 177 memory: "128Mi"
174 cpu: "100m" 178 cpu: "100m"
179 exec:
180 limits:
181 memory: "128Mi"
182 cpu: "100m"
183 requests:
184 memory: "128Mi"
185 cpu: "100m"
175 186
176manifests: 187manifests:
177 daemonset_ethtool: true 188 daemonset_ethtool: true
@@ -181,3 +192,4 @@ manifests:
181 daemonset_limits: true 192 daemonset_limits: true
182 daemonset_apt: true 193 daemonset_apt: true
183 daemonset_perm: true 194 daemonset_perm: true
195 daemonset_exec: true
diff --git a/doc/source/index.rst b/doc/source/index.rst
index 2fa9353..edc297f 100644
--- a/doc/source/index.rst
+++ b/doc/source/index.rst
@@ -170,6 +170,88 @@ way::
170 question_type: boolean 170 question_type: boolean
171 answer: false 171 answer: false
172 172
173exec
174^^^^
175
176Used to execute scripts on nodes, ex::
177
178 exec:
179 002-script2.sh:
180 data: |
181 #!/bin/bash
182 echo ${BASH_SOURCE}
183 001-script1.sh:
184 blocking_policy: foreground_halt_pod_on_failure
185 env:
186 env1: env1-val
187 env2: env2-val
188 args:
189 - arg1
190 - arg2
191 data: |
192 #!/bin/bash
193 echo script name: ${BASH_SOURCE}
194 echo args: $@
195 echo env: $env1 $env2 $env3
196
197Scripts are executed in alphanumeric order with the key names used. Therefore
198in this example, 001-script1.sh runs first, followed by 002-script2.sh.
199Targeting of directives to specific nodes by hostname or node label is
200achievable by use of the overrides capability described below.
201
202The following set of options are fully implemeneted::
203
204 ``rerun_policy`` may be optionally set to ``always``, ``never``, or
205 ``once_successfully`` for a given script. That script would always be rerun,
206 never be rerun, or rerun until the first successful execution respectively.
207 Default value is ``always``. This is tracked via a hash of the dict object
208 for the script (i.e. script name, script data, script args, script env, etc).
209 If any of that info changes, so will the hash, and it will be seen as a new
210 object which will be executed regardless of this setting.
211
212The following set of options are partially implemeneted::
213
214 ``blocking_policy`` may optionally be set to ``background``, ``foreground``,
215 or ``foreground_halt_pod_on_failure`` for a given script. This may be used to
216 run a script in the background (running in parallel, i.e. non-blocking) or
217 in the foreground (blocking). In either case, a failure of the script does
218 not cause a failure (crashloop) of the pod. The third option may be used
219 where the reverse behavior is desired (i.e., it would not proceed with
220 running the next script in the sequence until the current script ran
221 successfully). ``background`` option is not yet implemeneted. Default value
222 Deafult value is ``foreground``.
223
224The following set of options are not yet implemeneted::
225
226 ``script_timeout`` may optionally be set to the number of seconds to wait for
227 script completion before termination. Default value is ``3600`` (1 hour).
228
229 ``rerun_interval`` may be optionally set to the number of seconds to wait
230 between rerunning a given script which ran successfully the previous time.
231 Default value is ``infinite``.
232
233 ``rerun_interval_persist`` may be optionally set to ``true`` for
234 a given script. This allows a script to persist its rerun interval through a
235 pod/node restart. Otherwise, the time since last successful script execution
236 will not be considered on pod/node startup. Default value is ``false``.
237
238 ``rerun_max_count`` may be optionally set to the maximum number of times a
239 succeeding script should be retried. Successful exec count does not persist
240 through pod/node restart. Default value is ``infinite``.
241
242 ``retry_interval`` may be optionally set to the number of seconds to wait
243 between rerunning a given script which did not run successfully the previous
244 time. Default value is set to the ``rerun_interval``.
245
246 ``retry_interval_persist`` may be optionally set to ``true`` for
247 a given script. This allows a script to persist its retry interval through a
248 pod/node restart. Otherwise, the time since last failed script execution
249 will not be considered on pod/node startup. Default value is ``false``.
250
251 ``retry_max_count`` may be optionally set to the maximum number of times a
252 failing script should be retried. Failed exec count does not persist
253 through pod/node restart. Default value is ``infinite``.
254
173Operations 255Operations
174---------- 256----------
175 257
diff --git a/tools/gate/scripts/020-test-divingbell.sh b/tools/gate/scripts/020-test-divingbell.sh
index d766108..c408c66 100755
--- a/tools/gate/scripts/020-test-divingbell.sh
+++ b/tools/gate/scripts/020-test-divingbell.sh
@@ -55,6 +55,7 @@ APT_VERSION3=3.8.1-1ubuntu2
55APT_PACKAGE4=less 55APT_PACKAGE4=less
56APT_PACKAGE5=python-setuptools 56APT_PACKAGE5=python-setuptools
57APT_PACKAGE6=telnetd 57APT_PACKAGE6=telnetd
58EXEC_DIR=/var/${NAME}/exec
58type lshw || apt -y install lshw 59type lshw || apt -y install lshw
59nic_info="$(lshw -class network)" 60nic_info="$(lshw -class network)"
60physical_nic='' 61physical_nic=''
@@ -236,6 +237,31 @@ _test_sysctl_value(){
236 test "$(cat /etc/sysctl.d/60-${NAME}-${key}.conf)" = "${key}=${2}" 237 test "$(cat /etc/sysctl.d/60-${NAME}-${key}.conf)" = "${key}=${2}"
237} 238}
238 239
240_test_exec_match(){
241 expected_result="$1"
242 exec_testfile="$2"
243 testID="$3"
244 if [[ $expected_result != $(cat $exec_testfile) ]]; then
245 echo "[FAIL] exec $testID failed. Expected:"
246 echo $expected_result
247 echo but got:
248 echo $(cat $exec_testfile)
249 exit 1
250 fi
251 rm $exec_testfile
252}
253
254_test_exec_count(){
255 script_location="${1}"
256 script_name="${2}"
257 script_expected_run_count="${3}"
258 script_run_count=$(cat "${script_location}" | wc -l)
259 if [[ ${script_run_count} -ne ${script_expected_run_count} ]]; then
260 echo "[FAIL] Expected '${script_name}' to run '${script_expected_run_count}' times, but instead it ran '$script_run_count' times"
261 exit 1
262 fi
263}
264
239_test_clog_msg(){ 265_test_clog_msg(){
240 [[ $CLOGS = *${1}* ]] || 266 [[ $CLOGS = *${1}* ]] ||
241 (echo "Did not find expected string: '${1}'" 267 (echo "Did not find expected string: '${1}'"
@@ -958,6 +984,202 @@ test_apt(){
958 echo '[SUCCESS] apt test6 passed successfully' >> "${TEST_RESULTS}" 984 echo '[SUCCESS] apt test6 passed successfully' >> "${TEST_RESULTS}"
959} 985}
960 986
987# test exec module
988test_exec(){
989 # test script execution ordering, args, and env vars
990 local overrides_yaml=${LOGS_SUBDIR}/${FUNCNAME}-set1.yaml
991 echo 'conf:
992 exec:
993 030-script5.sh:
994 blocking_policy: foreground_halt_pod_on_failure
995 env:
996 env1: env1-val
997 env2: env2-val
998 env3: env3-val
999 args:
1000 - arg1
1001 - arg2
1002 - arg3
1003 data: |
1004 #!/bin/bash
1005 echo script name: ${BASH_SOURCE} >> exec_testfile
1006 echo args: "$@" >> exec_testfile
1007 echo env: "$env1 $env2 $env3" >> exec_testfile
1008 005-script1.sh:
1009 blocking_policy: foreground
1010 data: |
1011 #!/bin/bash
1012 rm exec_testfile 2> /dev/null || true
1013 echo script name: ${BASH_SOURCE} >> exec_testfile
1014 015-script3.sh:
1015 blocking_policy: foreground_halt_pod_on_failure
1016 data: |
1017 #!/bin/bash
1018 echo script name: ${BASH_SOURCE} >> exec_testfile
1019 008-script2.sh:
1020 data: |
1021 #!/bin/bash
1022 echo script name: ${BASH_SOURCE} >> exec_testfile
1023 025-script4.sh:
1024 data: |
1025 #!/bin/bash
1026 echo script name: ${BASH_SOURCE} >> exec_testfile' > "${overrides_yaml}"
1027 install_base "--values=${overrides_yaml}"
1028 get_container_status exec
1029 expected_result='script name: ./005-script1.sh
1030script name: ./008-script2.sh
1031script name: ./015-script3.sh
1032script name: ./025-script4.sh
1033script name: ./030-script5.sh
1034args: arg1 arg2 arg3
1035env: env1-val env2-val env3-val'
1036 _test_exec_match "$expected_result" "${EXEC_DIR}/exec_testfile" "test1"
1037 echo '[SUCCESS] exec test1 passed successfully' >> "${TEST_RESULTS}"
1038
1039 # Test blocking_policy
1040 local overrides_yaml=${LOGS_SUBDIR}/${FUNCNAME}-set2.yaml
1041 echo 'conf:
1042 exec:
1043 030-script5.sh:
1044 blocking_policy: foreground_halt_pod_on_failure
1045 env:
1046 env1: env1-val
1047 env2: env2-val
1048 env3: env3-val
1049 args:
1050 - arg1
1051 - arg2
1052 - arg3
1053 data: |
1054 #!/bin/bash
1055 echo script name: ${BASH_SOURCE} >> exec_testfile
1056 echo args: "$@" >> exec_testfile
1057 echo env: "$env1 $env2 $env3" >> exec_testfile
1058 005-script1.sh:
1059 blocking_policy: foreground
1060 data: |
1061 #!/bin/bash
1062 rm exec_testfile 2> /dev/null || true
1063 echo script name: ${BASH_SOURCE} >> exec_testfile
1064 015-script3.sh:
1065 blocking_policy: foreground_halt_pod_on_failure
1066 data: |
1067 #!/bin/bash
1068 echo script name: ${BASH_SOURCE} >> exec_testfile
1069 false
1070 008-script2.sh:
1071 data: |
1072 #!/bin/bash
1073 echo script name: ${BASH_SOURCE} >> exec_testfile
1074 025-script4.sh:
1075 data: |
1076 #!/bin/bash
1077 echo script name: ${BASH_SOURCE} >> exec_testfile' > "${overrides_yaml}"
1078 install_base "--values=${overrides_yaml}"
1079 get_container_status exec expect_failure
1080 expected_result='script name: ./005-script1.sh
1081script name: ./008-script2.sh
1082script name: ./015-script3.sh'
1083 _test_exec_match "$expected_result" "${EXEC_DIR}/exec_testfile" "test2"
1084 echo '[SUCCESS] exec test2 passed successfully' >> "${TEST_RESULTS}"
1085
1086 # Test invalid rerun_policy
1087 overrides_yaml=${LOGS_SUBDIR}/${FUNCNAME}-set3.yaml
1088 echo 'conf:
1089 exec:
1090 030-script5.sh:
1091 rerun_policy: foo
1092 data: |
1093 #!/bin/bash
1094 true' > "${overrides_yaml}"
1095 install_base "--values=${overrides_yaml}" 2>&1 | grep 'BAD .rerun_policy. FOR' || \
1096 (echo "[FAIL] exec test3 did not receive expected 'BAD .rerun_policy. FOR' error" && exit 1)
1097 echo '[SUCCESS] exec test3 passed successfully' >> "${TEST_RESULTS}"
1098
1099 # Test invalid blocking_policy
1100 overrides_yaml=${LOGS_SUBDIR}/${FUNCNAME}-set4.yaml
1101 echo 'conf:
1102 exec:
1103 030-script5.sh:
1104 blocking_policy: foo
1105 data: |
1106 #!/bin/bash
1107 true' > "${overrides_yaml}"
1108 install_base "--values=${overrides_yaml}" 2>&1 | grep 'BAD .blocking_policy. FOR' || \
1109 (echo "[FAIL] exec test4 did not receive expected 'BAD .blocking_policy. FOR' error" && exit 1)
1110 echo '[SUCCESS] exec test4 passed successfully' >> "${TEST_RESULTS}"
1111
1112 # Test rerun_policies:
1113 # 1. Unspecified
1114 # 2. always
1115 # 3. once_successfully, when script passes
1116 # 4. once_successfully, when script fails
1117 # 5. never
1118
1119 # first execution
1120 overrides_yaml=${LOGS_SUBDIR}/${FUNCNAME}-set5.yaml
1121 echo 'conf:
1122 exec:
1123 001-script1.sh:
1124 data: |
1125 #!/bin/bash
1126 echo script name: ${BASH_SOURCE} >> script1
1127 002-script2.sh:
1128 rerun_policy: always
1129 data: |
1130 #!/bin/bash
1131 echo script name: ${BASH_SOURCE} >> script2
1132 003-script3.sh:
1133 rerun_policy: once_successfully
1134 data: |
1135 #!/bin/bash
1136 echo script name: ${BASH_SOURCE} >> script3
1137 004-script4.sh:
1138 rerun_policy: once_successfully
1139 data: |
1140 #!/bin/bash
1141 echo script name: ${BASH_SOURCE} >> script4
1142 false
1143 005-script5.sh:
1144 rerun_policy: never
1145 data: |
1146 #!/bin/bash
1147 echo script name: ${BASH_SOURCE} >> script5
1148 env:
1149 env3: env3-val
1150 env1: env1-val
1151 env2: env2-val
1152 args:
1153 - arg2
1154 - arg1
1155 - arg3
1156manifests:
1157 daemonset_ethtool: false
1158 daemonset_mounts: false
1159 daemonset_uamlite: false
1160 daemonset_sysctl: false
1161 daemonset_limits: false
1162 daemonset_apt: false
1163 daemonset_perm: false' > "${overrides_yaml}"
1164
1165 install_base "--values=${overrides_yaml}"
1166 get_container_status exec
1167
1168 # run several times with the same values and evaluate results
1169 # (ensure no ordering issues cause hashing inconsistencies)
1170 for i in $(seq 0 11); do
1171 install_base "--values=${overrides_yaml}"
1172 get_container_status exec
1173 _test_exec_count "${EXEC_DIR}/script1" '001-script1.sh' $(($i + 2))
1174 _test_exec_count "${EXEC_DIR}/script2" '002-script1.sh' $(($i + 2))
1175 _test_exec_count "${EXEC_DIR}/script3" '003-script1.sh' '1'
1176 _test_exec_count "${EXEC_DIR}/script4" '004-script1.sh' $(($i + 2))
1177 _test_exec_count "${EXEC_DIR}/script5" '005-script1.sh' '1'
1178 echo "[SUCCESS] exec test$(($i + 5)) passed successfully" >> "${TEST_RESULTS}"
1179 done
1180
1181}
1182
961# test daemonset value overrides for hosts and labels 1183# test daemonset value overrides for hosts and labels
962test_overrides(){ 1184test_overrides(){
963 overrides_yaml=${LOGS_SUBDIR}/${FUNCNAME}-dryrun.yaml 1185 overrides_yaml=${LOGS_SUBDIR}/${FUNCNAME}-dryrun.yaml
@@ -1053,7 +1275,7 @@ test_overrides(){
1053 1275
1054 # Compare against expected number of generated daemonsets 1276 # Compare against expected number of generated daemonsets
1055 daemonset_count="$(echo "${tc_output}" | grep 'kind: DaemonSet' | wc -l)" 1277 daemonset_count="$(echo "${tc_output}" | grep 'kind: DaemonSet' | wc -l)"
1056 if [ "${daemonset_count}" != "15" ]; then 1278 if [ "${daemonset_count}" != "16" ]; then
1057 echo '[FAILURE] overrides test 1 failed' >> "${TEST_RESULTS}" 1279 echo '[FAILURE] overrides test 1 failed' >> "${TEST_RESULTS}"
1058 echo "Expected 15 daemonsets; got '${daemonset_count}'" >> "${TEST_RESULTS}" 1280 echo "Expected 15 daemonsets; got '${daemonset_count}'" >> "${TEST_RESULTS}"
1059 exit 1 1281 exit 1
@@ -1240,6 +1462,7 @@ if [[ -z $SKIP_BASE_TESTS ]]; then
1240 test_ethtool 1462 test_ethtool
1241 test_uamlite 1463 test_uamlite
1242 test_apt 1464 test_apt
1465 test_exec
1243fi 1466fi
1244purge_containers 1467purge_containers
1245test_overrides 1468test_overrides