Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2e CI job use memory storage for etcd #2633

Merged
merged 12 commits into from
Jun 9, 2020
8 changes: 7 additions & 1 deletion ci/pingcap_tidb_operator_build_kind.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ spec:
# legacy docker path for cr.io/k8s-testimages/kubekins-e2e
- name: docker-graph
mountPath: /docker-graph
# use memory storage for etcd hostpath in kind cluster
- name: etcd-data-dir
mountPath: /mnt/tmpfs/etcd
volumes:
- name: modules
hostPath:
Expand All @@ -76,6 +79,9 @@ spec:
emptyDir: {}
- name: docker-graph
emptyDir: {}
- name: etcd-data-dir
emptyDir:
medium: Memory
tolerations:
- effect: NoSchedule
key: tidb-operator
Expand Down Expand Up @@ -301,7 +307,7 @@ def call(BUILD_BRANCH, CREDENTIALS_ID, CODECOV_CREDENTIALS_ID) {
}
}

def GLOBALS = "SKIP_BUILD=y SKIP_IMAGE_BUILD=y DOCKER_REPO=hub.pingcap.net/tidb-operator-e2e IMAGE_TAG=${GITHASH} DELETE_NAMESPACE_ON_FAILURE=true GINKGO_NO_COLOR=y"
def GLOBALS = "KIND_ETCD_DATADIR=/mnt/tmpfs/etcd SKIP_BUILD=y SKIP_IMAGE_BUILD=y DOCKER_REPO=hub.pingcap.net/tidb-operator-e2e IMAGE_TAG=${GITHASH} DELETE_NAMESPACE_ON_FAILURE=true GINKGO_NO_COLOR=y"
def builds = [:]
// We must not enable operator killer for Kubernetes before 1.15 in
// which webhook configuration does not support objectSelector. Webhook
Expand Down
83 changes: 59 additions & 24 deletions hack/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@ source "${ROOT}/hack/lib.sh"
# check bash version
BASH_MAJOR_VERSION=$(echo "$BASH_VERSION" | cut -d '.' -f 1)
# we need bash version >= 4
if [ $BASH_MAJOR_VERSION -lt 4 ]
then
echo "error: e2e.sh could not work with bash version earlier than 4 for now, please upgrade your bash"
exit 1
if [ $BASH_MAJOR_VERSION -lt 4 ]; then
echo "error: e2e.sh could not work with bash version earlier than 4 for now, please upgrade your bash"
exit 1
fi


function usage() {
cat <<'EOF'
This script is entrypoint to run e2e tests.
Expand Down Expand Up @@ -64,6 +62,7 @@ Environments:
GCR_IO_MIRROR configure mirror for gcr.io
QUAY_IO_MIRROR configure mirror for quay.io
KIND_DATA_HOSTPATH (kind only) the host path of data directory for kind cluster, defaults: none
KIND_ETCD_DATADIR (kind only) the host path of etcd data directory for kind cluster, defaults: none
GCP_PROJECT (gke only) the GCP project to run in
GCP_CREDENTIALS (gke only) the GCP service account to use
GCP_REGION (gke only) the GCP region, if specified a regional cluster is creaetd
Expand Down Expand Up @@ -162,7 +161,7 @@ EOF

while getopts "h?" opt; do
case "$opt" in
h|\?)
h | \?)
usage
exit 0
;;
Expand All @@ -187,6 +186,7 @@ SKIP_TEST=${SKIP_TEST:-}
SKIP_DUMP=${SKIP_DUMP:-}
REUSE_CLUSTER=${REUSE_CLUSTER:-}
KIND_DATA_HOSTPATH=${KIND_DATA_HOSTPATH:-none}
KIND_ETCD_DATADIR=${KIND_ETCD_DATADIR:-none}
GCP_PROJECT=${GCP_PROJECT:-}
GCP_CREDENTIALS=${GCP_CREDENTIALS:-}
GCP_REGION=${GCP_REGION:-}
Expand Down Expand Up @@ -219,6 +219,7 @@ echo "SKIP_DOWN: $SKIP_DOWN"
echo "SKIP_TEST: $SKIP_TEST"
echo "SKIP_DUMP: $SKIP_DUMP"
echo "KIND_DATA_HOSTPATH: $KIND_DATA_HOSTPATH"
echo "KIND_ETCD_DATADIR: $KIND_ETCD_DATADIR"
echo "GCP_PROJECT: $GCP_PROJECT"
echo "GCP_CREDENTIALS: $GCP_CREDENTIALS"
echo "GCP_REGION: $GCP_REGION"
Expand Down Expand Up @@ -267,9 +268,9 @@ function e2e::__restart_docker() {
local MAX_WAIT=5
while true; do
# docker ps -q should only work if the daemon is ready
docker ps -q > /dev/null 2>&1 && break
docker ps -q >/dev/null 2>&1 && break
if [[ ${WAIT_N} -lt ${MAX_WAIT} ]]; then
WAIT_N=$((WAIT_N+1))
WAIT_N=$((WAIT_N + 1))
echo "info; Waiting for docker to be ready, sleeping for ${WAIT_N} seconds."
sleep ${WAIT_N}
else
Expand All @@ -282,7 +283,7 @@ function e2e::__restart_docker() {

function e2e::__configure_docker_mirror_for_dind() {
echo "info: configure docker.io mirror '$DOCKER_IO_MIRROR' for DinD"
cat <<EOF > /etc/docker/daemon.json.tmp
cat <<EOF >/etc/docker/daemon.json.tmp
{
"registry-mirrors": ["$DOCKER_IO_MIRROR"]
}
Expand All @@ -298,7 +299,7 @@ EOF

function e2e::create_kindconfig() {
local tmpfile=${1}
cat <<EOF > $tmpfile
cat <<EOF >$tmpfile
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
kubeadmConfigPatches:
Expand Down Expand Up @@ -338,51 +339,85 @@ kubeadmConfigPatches:
v: "4"
EOF
if [ -n "$DOCKER_IO_MIRROR" -o -n "$GCR_IO_MIRROR" -o -n "$QUAY_IO_MIRROR" ]; then
cat <<EOF >> $tmpfile
cat <<EOF >>$tmpfile
containerdConfigPatches:
- |-
EOF
if [ -n "$DOCKER_IO_MIRROR" ]; then
cat <<EOF >> $tmpfile
cat <<EOF >>$tmpfile
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]
endpoint = ["$DOCKER_IO_MIRROR"]
EOF
fi
if [ -n "$GCR_IO_MIRROR" ]; then
cat <<EOF >> $tmpfile
cat <<EOF >>$tmpfile
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."gcr.io"]
endpoint = ["$GCR_IO_MIRROR"]
EOF
fi
if [ -n "$QUAY_IO_MIRROR" ]; then
cat <<EOF >> $tmpfile
cat <<EOF >>$tmpfile
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."quay.io"]
endpoint = ["$QUAY_IO_MIRROR"]
EOF
fi
fi
# control-plane
cat <<EOF >> $tmpfile
cat <<EOF >>$tmpfile
nodes:
- role: control-plane
EOF
if [[ "$KIND_DATA_HOSTPATH" != "none" ]]; then
if [ ! -d "$KIND_DATA_HOSTPATH" ]; then
echo "error: '$KIND_DATA_HOSTPATH' is not a directory"
exit 1
# check $KIND_ETCD_DATADIR
if [[ "$KIND_ETCD_DATADIR" != "none" ]]; then
# check $KIND_DATA_HOSTPATH
if [[ "$KIND_DATA_HOSTPATH" != "none" ]]; then
if [ ! -d "$KIND_DATA_HOSTPATH" ]; then
echo "error: '$KIND_DATA_HOSTPATH' is not a directory"
exit 1
fi
if [ ! -d "$KIND_ETCD_DATADIR" ]; then
echo "error: '$KIND_ETCD_DATADIR' is not a directory"
exit 1
fi
local hostWorkerPath="${KIND_DATA_HOSTPATH}/control-plane"
test -d $hostWorkerPath || mkdir $hostWorkerPath
# set custom KIND_DATA_HOSTPATH and KIND_ETCD_DATADIR
cat <<EOF >>$tmpfile
extraMounts:
- containerPath: /mnt/disks/
hostPath: "$hostWorkerPath"
propagation: HostToContainer
- containerPath: /var/lib/etcd
hostPath: "$KIND_ETCD_DATADIR"
EOF
else
# set custom KIND_ETCD_DATADIR
cat <<EOF >>$tmpfile
extraMounts:
- containerPath: /var/lib/etcd
hostPath: "$KIND_ETCD_DATADIR"
EOF
fi
local hostWorkerPath="${KIND_DATA_HOSTPATH}/control-plane"
test -d $hostWorkerPath || mkdir $hostWorkerPath
cat <<EOF >> $tmpfile
else
if [[ "$KIND_DATA_HOSTPATH" != "none" ]]; then
if [ ! -d "$KIND_DATA_HOSTPATH" ]; then
echo "error: '$KIND_DATA_HOSTPATH' is not a directory"
exit 1
fi
local hostWorkerPath="${KIND_DATA_HOSTPATH}/control-plane"
test -d $hostWorkerPath || mkdir $hostWorkerPath
# set custom KIND_DATA_HOSTPATH
cat <<EOF >>$tmpfile
shonge marked this conversation as resolved.
Show resolved Hide resolved
extraMounts:
- containerPath: /mnt/disks/
hostPath: "$hostWorkerPath"
propagation: HostToContainer
EOF
fi
fi
# workers
for ((i = 1; i <= $KUBE_WORKERS; i++)) {
cat <<EOF >> $tmpfile
cat <<EOF >>$tmpfile
- role: worker
EOF
if [[ "$KIND_DATA_HOSTPATH" != "none" ]]; then
Expand All @@ -392,7 +427,7 @@ EOF
fi
local hostWorkerPath="${KIND_DATA_HOSTPATH}/worker${i}"
test -d $hostWorkerPath || mkdir $hostWorkerPath
cat <<EOF >> $tmpfile
cat <<EOF >>$tmpfile
extraMounts:
- containerPath: /mnt/disks/
hostPath: "$hostWorkerPath"
Expand Down