Skip to content

Commit

Permalink
[FLINK-17857][test] Make K8s e2e tests could run on Mac
Browse files Browse the repository at this point in the history
This closes #14012.
  • Loading branch information
wangyang0918 authored and tillrohrmann committed May 11, 2021
1 parent 12010db commit 35ca4cf
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions flink-end-to-end-tests/test-scripts/common_kubernetes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ MINIKUBE_START_RETRIES=3
MINIKUBE_START_BACKOFF=5
RESULT_HASH="e682ec6622b5e83f2eb614617d5ab2cf"
MINIKUBE_VERSION="v1.8.2"
MINIKUBE_PATH="/usr/local/bin/minikube-$MINIKUBE_VERSION"

NON_LINUX_ENV_NOTE="****** Please start/stop minikube manually in non-linux environment. ******"

Expand All @@ -43,16 +42,18 @@ function setup_kubernetes_for_linux {
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/$version/bin/linux/$arch/kubectl && \
chmod +x kubectl && sudo mv kubectl /usr/local/bin/
fi
# Download minikube.
if ! [ -x "$(command -v minikube)" ] || ! [[ $(minikube version) =~ "$MINIKUBE_VERSION" ]]; then
echo "Installing minikube to $MINIKUBE_PATH ..."
# Download minikube when it is not installed beforehand.
if ! [ -x "$(command -v minikube)" ]; then
echo "Installing minikube $MINIKUBE_VERSION ..."
curl -Lo minikube https://storage.googleapis.com/minikube/releases/$MINIKUBE_VERSION/minikube-linux-$arch && \
chmod +x minikube && sudo mv minikube $MINIKUBE_PATH
chmod +x minikube && sudo mv minikube /usr/bin/minikube
fi
# conntrack is required for minikube 1.9 and later
sudo apt-get install conntrack
}

function check_kubernetes_status {
$MINIKUBE_PATH status
minikube status
return $?
}

Expand All @@ -75,15 +76,15 @@ function start_kubernetes_if_not_running {
# here.
# Similarly, the kubelets are marking themself as "low disk space",
# causing Flink to avoid this node (again, failing the test)
sudo CHANGE_MINIKUBE_NONE_USER=true $MINIKUBE_PATH start --vm-driver=none \
sudo CHANGE_MINIKUBE_NONE_USER=true minikube start --vm-driver=none \
--extra-config=kubelet.image-gc-high-threshold=99 \
--extra-config=kubelet.image-gc-low-threshold=98 \
--extra-config=kubelet.minimum-container-ttl-duration=120m \
--extra-config=kubelet.eviction-hard="memory.available<5Mi,nodefs.available<1Mi,imagefs.available<1Mi" \
--extra-config=kubelet.eviction-soft="memory.available<5Mi,nodefs.available<2Mi,imagefs.available<2Mi" \
--extra-config=kubelet.eviction-soft-grace-period="memory.available=2h,nodefs.available=2h,imagefs.available=2h"
# Fix the kubectl context, as it's often stale.
$MINIKUBE_PATH update-context
minikube update-context
fi

check_kubernetes_status
Expand All @@ -99,23 +100,25 @@ function start_kubernetes {
# Mount Flink dist into minikube virtual machine because we need to mount hostPath as usrlib
minikube mount $FLINK_DIR:$FLINK_DIR &
export minikube_mount_pid=$!
echo "The mounting process is running with pid $minikube_mount_pid"
else
setup_kubernetes_for_linux
if ! retry_times ${MINIKUBE_START_RETRIES} ${MINIKUBE_START_BACKOFF} start_kubernetes_if_not_running; then
echo "Could not start minikube. Aborting..."
exit 1
fi
fi
eval $($MINIKUBE_PATH docker-env)
eval $(minikube docker-env)
}

function stop_kubernetes {
if [[ "${OS_TYPE}" != "linux" ]]; then
echo "$NON_LINUX_ENV_NOTE"
echo "Killing mounting process $minikube_mount_pid"
kill $minikube_mount_pid 2> /dev/null
else
echo "Stopping minikube ..."
stop_command="sudo $MINIKUBE_PATH stop"
stop_command="sudo minikube stop"
if ! retry_times ${MINIKUBE_START_RETRIES} ${MINIKUBE_START_BACKOFF} "${stop_command}"; then
echo "Could not stop minikube. Aborting..."
exit 1
Expand Down Expand Up @@ -178,18 +181,6 @@ function cleanup {
stop_kubernetes
}

function setConsoleLogging {
cat >> $FLINK_DIR/conf/log4j.properties <<END
rootLogger.appenderRef.console.ref = ConsoleAppender
# Log all infos to the console
appender.console.name = ConsoleAppender
appender.console.type = CONSOLE
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%t] %-60c %x - %m%n
END
}

function get_host_machine_address {
if [[ "${OS_TYPE}" != "linux" ]]; then
echo $(minikube ssh "route -n | grep ^0.0.0.0 | awk '{ print \$2 }' | tr -d '[:space:]'")
Expand Down

0 comments on commit 35ca4cf

Please sign in to comment.