Skip to content

Instantly share code, notes, and snippets.

@guybrush
Last active April 17, 2016 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guybrush/76b71bd261fcd411cd342618cb4ace1f to your computer and use it in GitHub Desktop.
Save guybrush/76b71bd261fcd411cd342618cb4ace1f to your computer and use it in GitHub Desktop.
#!/bin/bash
echo "
this script
1) creates a configmap: test-configmap-configmap
2) creates a pod: test-configmap-busybox which mounts the configmap as volume
3) checks the modification-time of the file inside the volume -> m1
4) changes the data of test-configmap-configmap and waits until the content
of the file changes
5) checks the modification-time of the file inside the volume -> m2
now m1 should be older then m2, but it is not
"
# make sure test-resources dont exist
echo "make sure test-resource configmap doesnt exist"
while $(kubectl get configmap test-configmap-configmap &> /dev/null); do
kubectl delete configmap test-configmap-configmap &> /dev/null
sleep 1
done
echo "make sure test-resource busybox doesnt exist"
while $(kubectl get po test-configmap-busybox &> /dev/null); do
kubectl delete po test-configmap-busybox &> /dev/null
sleep 1
done
echo "========================================= 1"
echo "
apiVersion: v1
kind: ConfigMap
metadata:
name: test-configmap-configmap
data:
some-file.txt: |
version:1
" | kubectl create -f -
echo "========================================= 2"
echo '
apiVersion: v1
kind: Pod
metadata:
name: test-configmap-busybox
spec:
containers:
- name: busybox
image: busybox
command: ["/bin/sh", "-c", "while true; do sleep 3600; done"]
volumeMounts:
- name: data
mountPath: /test
readOnly: true
volumes:
- name: data
configMap:
name: test-configmap-configmap
' | kubectl create -f -
until $(kubectl exec test-configmap-busybox date &> /dev/null); do sleep 1; done
echo "========================================= 3"
kubectl exec test-configmap-busybox -- cat /test/some-file.txt
kubectl exec test-configmap-busybox -- ls -al /test
MODTIME_1=$(kubectl exec test-configmap-busybox -- stat /test/some-file.txt | grep "^Modify")
echo "========================================= 4"
echo "
apiVersion: v1
kind: ConfigMap
metadata:
name: test-configmap-configmap
data:
some-file.txt: |
version:2
" | kubectl apply -f -
echo "waiting for file content to change"
CONTENT=$(kubectl exec test-configmap-busybox -- cat /test/some-file.txt)
declare -i n=0
while [ $CONTENT != "version:2" ]; do
echo -n .
sleep 1
n=$n+1
CONTENT=$(kubectl exec test-configmap-busybox -- cat /test/some-file.txt)
# echo -n $CONTENT
done
echo "$n seconds"
echo "========================================= 5"
MODTIME_2=$(kubectl exec test-configmap-busybox -- stat /test/some-file.txt | grep "^Modify")
echo "modtime 1: "$MODTIME_1
echo "modtime 2: "$MODTIME_2
echo "========================================="
echo "now you will enter pod:test-configmap-busybox"
echo "all resources will be cleaned up on exit"
kubectl exec -ti test-configmap-busybox sh
kubectl delete po test-configmap-busybox
kubectl delete configmap test-configmap-configmap
@guybrush
Copy link
Author

$ ./test-configmap.sh

this script

1) creates a configmap: test-configmap-configmap
2) creates a pod: test-configmap-busybox which mounts the configmap as volume
3) checks the modification-time of the file inside the volume -> m1
4) changes the data of test-configmap-configmap and waits until the content
   of the file changes
5) checks the modification-time of the file inside the volume -> m2

now m1 should be older then m2, but it is not

make sure test-resource configmap doesnt exist
make sure test-resource busybox doesnt exist
========================================= 1
configmap "test-configmap-configmap" created
========================================= 2
pod "test-configmap-busybox" created
========================================= 3
version:1
total 4
drwxrwxrwt    3 root     root           100 Apr 13 21:00 .
drwxr-xr-x   20 root     root          4096 Apr 13 21:00 ..
drwx------    2 root     root            60 Apr 13 21:00 ..4984_13_04_23_00_44.228447895
lrwxrwxrwx    1 root     root            31 Apr 13 21:00 ..data -> ..4984_13_04_23_00_44.228447895
lrwxrwxrwx    1 root     root            20 Apr 13 21:00 some-file.txt -> ..data/some-file.txt
========================================= 4
configmap "test-configmap-configmap" configured
waiting for file content to change
..................................................50 seconds
========================================= 5
modtime 1: Modify: 2016-04-13 21:00:44.000000000
modtime 2: Modify: 2016-04-13 21:00:44.000000000
=========================================
now you will enter pod:test-configmap-busybox
all resources will be cleaned up on exit
/ # exit
pod "test-configmap-busybox" deleted
configmap "test-configmap-configmap" deleted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment