Last active
April 17, 2016 21:10
-
-
Save guybrush/76b71bd261fcd411cd342618cb4ace1f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Author
guybrush
commented
Apr 13, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment