mirror of
https://github.com/sailor-sh/CK-X.git
synced 2026-02-14 17:39:51 +00:00
Merge pull request #55 from FabianHardt/fix/ckad-lab2-q2
fix CKAD lab2 question 2
This commit is contained in:
@@ -62,6 +62,9 @@ spec:
|
|||||||
volumeMounts:
|
volumeMounts:
|
||||||
- name: log-volume
|
- name: log-volume
|
||||||
mountPath: /var/log
|
mountPath: /var/log
|
||||||
|
- name: log-volume
|
||||||
|
mountPath: /var/log/nginx
|
||||||
|
subPath: nginx
|
||||||
- name: sidecar-container
|
- name: sidecar-container
|
||||||
image: busybox
|
image: busybox
|
||||||
command: ['sh', '-c', 'while true; do echo $(date) >> /var/log/app.log; sleep 5; done']
|
command: ['sh', '-c', 'while true; do echo $(date) >> /var/log/app.log; sleep 5; done']
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ VOLUME_NAME=$(kubectl get pod multi-container-pod -n multi-container -o jsonpath
|
|||||||
|
|
||||||
if [[ "$VOLUME_NAME" == "log-volume" ]]; then
|
if [[ "$VOLUME_NAME" == "log-volume" ]]; then
|
||||||
# Volume exists, now check if it's mounted in both containers
|
# Volume exists, now check if it's mounted in both containers
|
||||||
MAIN_CONTAINER_MOUNT=$(kubectl get pod multi-container-pod -n multi-container -o jsonpath='{.spec.containers[?(@.name=="main-container")].volumeMounts[?(@.name=="log-volume")].mountPath}' 2>/dev/null)
|
MAIN_CONTAINER_MOUNT=$(kubectl get pod multi-container-pod -n multi-container -o jsonpath='{.spec.containers[?(@.name=="main-container")].volumeMounts[?(@.name=="log-volume")]}' 2>/dev/null)
|
||||||
SIDECAR_CONTAINER_MOUNT=$(kubectl get pod multi-container-pod -n multi-container -o jsonpath='{.spec.containers[?(@.name=="sidecar-container")].volumeMounts[?(@.name=="log-volume")].mountPath}' 2>/dev/null)
|
SIDECAR_CONTAINER_MOUNT=$(kubectl get pod multi-container-pod -n multi-container -o jsonpath='{.spec.containers[?(@.name=="sidecar-container")].volumeMounts[?(@.name=="log-volume")].mountPath}' 2>/dev/null)
|
||||||
|
|
||||||
if [[ "$MAIN_CONTAINER_MOUNT" == "/var/log" && "$SIDECAR_CONTAINER_MOUNT" == "/var/log" ]]; then
|
if [[ "$MAIN_CONTAINER_MOUNT" == *"/var/log"* && "$SIDECAR_CONTAINER_MOUNT" == "/var/log" ]]; then
|
||||||
# Both containers have the volume mounted at the correct path
|
# Both containers have the volume mounted at the correct path
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
@@ -21,4 +21,4 @@ if [[ "$VOLUME_NAME" == "log-volume" ]]; then
|
|||||||
else
|
else
|
||||||
echo "Volume 'log-volume' does not exist in pod 'multi-container-pod'"
|
echo "Volume 'log-volume' does not exist in pod 'multi-container-pod'"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
Reference in New Issue
Block a user