Sync with Longhorn Manager

commit 7344e505df6d3b779d46c4fb153c3169316fe753
Author: James Oliver <joliver@rancher.com>
Date:   Tue Aug 21 18:51:13 2018 -0700

    Detect flexvolume path by inspecting host pid namespace
This commit is contained in:
Sheng Yang 2018-08-21 20:10:20 -07:00
parent 4fe551be8a
commit 9098172019

View File

@ -39,23 +39,95 @@ spec:
args: ["/bin/sh", "-c", "sleep 1000000000"]
volumeMounts:
- name: mountpoint
mountPath: /mnt/tmp
mountPath: /tmp/longhorn-environment-check
mountPropagation: Bidirectional
securityContext:
privileged: true
volumes:
- name: mountpoint
hostPath:
path: /mnt/tmp
path: /tmp/longhorn-environment-check
EOF
kubectl create -f $TEMP_DIR/environment_check.yaml
}
create_pod() {
cat <<EOF > $TEMP_DIR/detect-flexvol-dir.yaml
apiVersion: v1
kind: Pod
metadata:
name: detect-flexvol-dir
spec:
containers:
- name: detect-flexvol-dir
image: busybox
command: ["/bin/sh"]
args:
- -c
- |
find_kubelet_proc() {
for proc in \`find /proc -type d -maxdepth 1\`; do
if [ ! -f \$proc/cmdline ]; then
continue
fi
if [[ "\$(cat \$proc/cmdline | tr '\000' '\n' | head -n1 | tr '/' '\n' | tail -n1)" == "kubelet" ]]; then
echo \$proc
return
fi
done
}
get_flexvolume_path() {
proc=\$(find_kubelet_proc)
if [ "\$proc" != "" ]; then
path=\$(cat \$proc/cmdline | tr '\000' '\n' | grep volume-plugin-dir | tr '=' '\n' | tail -n1)
if [ "\$path" == "" ]; then
echo '/usr/libexec/kubernetes/kubelet-plugins/volume/exec/'
else
echo \$path
fi
return
fi
echo 'no kubelet process found, dunno'
}
get_flexvolume_path
securityContext:
privileged: true
hostPID: true
restartPolicy: Never
EOF
kubectl create -f $TEMP_DIR/detect-flexvol-dir.yaml
}
cleanup() {
kubectl delete -f $TEMP_DIR/environment_check.yaml
kubectl delete -f $TEMP_DIR/environment_check.yaml &
a=$!
kubectl delete -f $TEMP_DIR/detect-flexvol-dir.yaml &
b=$!
wait $a
wait $b
rm -rf $TEMP_DIR
}
wait_pod_ready() {
while true; do
local pod=$(kubectl get po/detect-flexvol-dir -o json)
local phase=$(echo $pod | jq -r .status.phase)
if [ "$phase" == "Succeeded" ]; then
echo "pod/detect-flexvol-dir completed"
return
fi
echo "waiting for pod/detect-flexvol-dir to finish"
sleep 3
done
}
validate_pod() {
flexvol_path=$(kubectl logs detect-flexvol-dir)
echo -e "\n FlexVolume Path: ${flexvol_path}\n"
}
wait_ds_ready() {
while true; do
local ds=$(kubectl get ds/longhorn-environment-check -o json)
@ -72,7 +144,7 @@ wait_ds_ready() {
done
}
validate_pods() {
validate_ds() {
local allSupported=true
local pods=$(kubectl -l app=longhorn-environment-check get po -o json)
@ -101,7 +173,10 @@ validate_pods() {
dependencies kubectl jq mktemp
TEMP_DIR=$(mktemp -d)
trap cleanup EXIT
create_pod
create_ds
wait_pod_ready
wait_ds_ready
validate_pods
validate_pod
validate_ds
exit 0