@@ -30,33 +30,40 @@ VCOMMA=''
30
30
CMFILES=' '
31
31
VOLUMECOUNT=0
32
32
33
+ TMPDIR=' /tmp'
34
+
33
35
EXITCODE=0
34
36
35
37
usage_exit () {
36
38
cat << EOF
37
39
38
- Usage: $( basename $0 ) [-i image] [-n namespace] [-c command]
39
- [-m pvc-name:mount-path]
40
- [-f local-file-name]
41
- [-t timeout]
40
+ Usage: $( basename $0 ) ...options...
42
41
43
- Run a 'one-off' command on a kubernetes cluster via a temporary pod,
44
- optionally specify pvc mounts and additional files to load.
42
+ Runs a 'one-off' command on a kubernetes cluster via a temporary pod.
43
+ Provides options to specify pvc mounts, hostpath mounts, or additional
44
+ files to load.
45
45
46
46
Parameters:
47
47
48
48
-i imagename - Image, default is "$IMAGE ".
49
49
-l imagepullpolicy - Image pull policy, default is "$IMAGEPULLPOLICY ".
50
50
-s imagesecret - Image pull secret. No default.
51
+
51
52
-n namespace - Namespace, default is "$NAMESPACE ".
52
53
-p podname - Pod name, default is "$PODNAME ".
54
+
53
55
-c command - Command, default is "$COMMAND ".
54
- -t timeout - Timeout in seconds, default is $MAXSECS seconds.
56
+
55
57
-m pvc-name:mount-path - PVC name and mount location. No default.
56
58
-m host-path:mount-path- Remote host-path and mount location. No default.
57
59
Host-path must begin with a '/'.
58
60
-f /path/filename - Copies local file to pod at /tmpmount/filename
59
61
62
+ -t timeout - Timeout in seconds, default is $MAXSECS seconds.
63
+
64
+ -d tmpdir - Location to put tmp file(s). Default is "$TMPDIR ".
65
+ Use this if your command's output might be large.
66
+
60
67
You can specify -f, -m, and -s more than once.
61
68
62
69
Limitation:
@@ -103,7 +110,7 @@ delete_pod_and_cm() {
103
110
kubectl delete -n ${NAMESPACE} cm ${PODNAME} -cm --ignore-not-found > /dev/null 2>&1
104
111
}
105
112
106
- while getopts m:t:i:c:n:f:p:l:s: OPT
113
+ while getopts m:t:i:c:n:f:p:l:s:d: OPT
107
114
do
108
115
case $OPT in
109
116
i) IMAGE=$OPTARG
121
128
;;
122
129
t) MAXSECS=$OPTARG
123
130
;;
131
+ d) TMPDIR=$OPTARG
132
+ ;;
124
133
f) # local file to make available in /tmpmount
125
134
if [ " $CMFILES " = " " ]; then
126
135
VOL_MOUNTS=" ${VOL_MOUNTS}${VCOMMA} {\" name\" : \" my-config-map-vol\" ,\" mountPath\" : \" /tmpmount\" }"
@@ -161,7 +170,9 @@ shift $(($OPTIND - 1))
161
170
162
171
# setup a tmp file /tmp/[script-file-name].[name-space].[pod-name].tmp.[pid]
163
172
164
- TEMPFILE=" /tmp/$( basename $0 ) .${NAMESPACE} .${PODNAME} .tmp.$$ "
173
+ [ ! -d " $TMPDIR " ] && echo " Error: temp dir \" $TMPDIR \" not found. Check parameters." && exit 1
174
+
175
+ TEMPFILE=" ${TMPDIR} /$( basename $0 ) .${NAMESPACE} .${PODNAME} .tmp.$$ "
165
176
166
177
# cleanup anything from previous run
167
178
@@ -253,3 +264,5 @@ cat $TEMPFILE | sed 's/{EXITCODE=0}//' \
253
264
rm -f $TEMPFILE
254
265
255
266
exit $EXITCODE
267
+
268
+
0 commit comments