Skip to content

Commit

Permalink
[apache#564] test(operator): add end-to-end test (apache#581)
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?
Add a script to start the e2e test environment.

### Why are the changes needed?
This address apache#564
Add a script to start the e2e test environment to support more e2e tests in the future.

### Does this PR introduce _any_ user-facing change?
For developers, they can quickly build a Kubernetes environment and run rss services and operators by docker and kind.

### How was this patch tested?
In /deploy/kubernetes/integration-test/e2e directory, run `start-e2e.sh` script.
  • Loading branch information
wangao1236 authored and advancedxy committed Mar 21, 2023
1 parent 975ac88 commit 15f9b8e
Show file tree
Hide file tree
Showing 9 changed files with 657 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ common/build/
integration-test/common/build/
storage/build/
build/
deploy/kubernetes/integration-test/e2e/rss.yaml
deploy/kubernetes/integration-test/e2e/rss-controller.yaml
deploy/kubernetes/integration-test/e2e/rss-webhook.yaml
4 changes: 3 additions & 1 deletion deploy/kubernetes/docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ RSS_DIR=../../..
cd $RSS_DIR || exit
RSS_VERSION=$(mvn help:evaluate -Dexpression=project.version 2>/dev/null | grep -v "INFO" | grep -v "WARNING" | tail -n 1)
RSS_FILE=rss-${RSS_VERSION}.tgz
echo "RSS_VERSION: $RSS_VERSION"
echo "RSS_FILE: $RSS_FILE"
if [ ! -e "$RSS_FILE" ]; \
then bash ./build_distribution.sh; \
else echo "$RSS_FILE has been built"; \
Expand All @@ -122,7 +124,7 @@ GIT_COMMIT=$(git describe --dirty --always --tags | sed 's/-/./g')
echo "image version: ${IMAGE_VERSION:=$RSS_VERSION-$GIT_COMMIT}"
IMAGE=$REGISTRY/rss-server:$IMAGE_VERSION
echo "building image: $IMAGE"
docker build -t "$IMAGE" \
docker build --network=host -t "$IMAGE" \
--build-arg RSS_VERSION="$RSS_VERSION" \
--build-arg HADOOP_VERSION="$HADOOP_VERSION" \
--build-arg AUTHOR="$AUTHOR" \
Expand Down
40 changes: 40 additions & 0 deletions deploy/kubernetes/integration-test/e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

# End-to-end Test

Currently, we can quickly pull up an e2e test environment locally by executing local-up-cluster.sh.

The kubernetes environment for local testing is built with [kind](https://github.com/kubernetes-sigs/kind).

The script reads parameters from the following environment variables, which are:

+ "TEST_REGISTRY": represents the url of the registry where the test image resides
+ "BUILD_NEW_CLUSTER": indicates whether a new kubernetes cluster needs to be built
+ "BUILD_RSS_IMAGE": indicates whether a new rss image needs to be built
+ "BUILD_RSS_OPERATOR": indicates whether a new operator image needs to be built

We can quickly build the environment by executing the following command:

```
$ TEST_REGISTRY=${users-registry-url} sh start-e2e.sh
```

## Dependence

We need to install [golang 1.17+](https://go.dev/doc/install), [docker](https://www.docker.com/get-started/) and
[kind](https://github.com/kubernetes-sigs/kind) first.
24 changes: 24 additions & 0 deletions deploy/kubernetes/integration-test/e2e/kind-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
- role: worker
184 changes: 184 additions & 0 deletions deploy/kubernetes/integration-test/e2e/set-up-local-cluster.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
#!/bin/bash

#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

set -o errexit
set -o nounset
set -o pipefail

STEP_BUILD_KIND_CLUSTER="true"
STEP_BUILD_NEW_RSS_IMAGE="true"
STEP_BUILD_NEW_OPERATOR="true"

KIND_K8S_IMAGE=kindest/node:v1.22.15@sha256:7d9708c4b0873f0fe2e171e2b1b7f45ae89482617778c1c875f1053d4cef2e41
KIND_CLUSTER_NAME=rss-test
TEST_REGISTRY="docker.io/library"
TEST_VERSION=$KIND_CLUSTER_NAME

RSS_BUILD_DIR=../../docker
OPERATOR_BUILD_DIR=../../operator

function pre_check() {
docker -v
res=$?
if [ $res -eq 0 ]; then
echo "--->>>docker has been installed"
else
echo "--->>>please install docker"
exit
fi

kind --version
res=$?
if [ $res -eq 0 ]; then
echo "--->>>kind has been installed"
else
echo "--->>>please install kind"
exit
fi
}

function prepare_local_k8s_cluster() {
# delete old cluster with the same name
kind delete cluster --name ${KIND_CLUSTER_NAME}
sleep 5
# create new cluster
kind create cluster --name ${KIND_CLUSTER_NAME} --image ${KIND_K8S_IMAGE} --config kind-config
# change context of kubeConfig
kubectl cluster-info --context kind-${KIND_CLUSTER_NAME}
}

function build_rss_image() {
cd $RSS_BUILD_DIR
export IMAGE_VERSION=$TEST_VERSION
sh ./build.sh --registry $TEST_REGISTRY
cd "$OLDPWD"
}

function build_operator_image() {
cd $OPERATOR_BUILD_DIR
export REGISTRY=$TEST_REGISTRY
export VERSION=$TEST_VERSION
make docker-push
cd "$OLDPWD"
}

pre_check

while (("$#")); do
case $1 in
--registry)
if [ -n "$2" ]; then
TEST_REGISTRY=$2
fi
shift
;;
--build-kind-cluster)
STEP_BUILD_KIND_CLUSTER="$2"
shift
;;
--build-rss-image)
STEP_BUILD_NEW_RSS_IMAGE="$2"
shift
;;
--build-operator)
STEP_BUILD_NEW_OPERATOR="$2"
shift
;;
--*)
echo "Error: $1 is not supported"
exit_with_usage
;;
-*)
break
;;
*)
echo "Error: $1 is not supported"
exit_with_usage
;;
esac
shift
done

# build k8s environment
if [ "$STEP_BUILD_KIND_CLUSTER" == "true" ]; then
echo "--->>>try to delete the old cluster and create a new cluster"
prepare_local_k8s_cluster
sleep 60
fi

# create rss-operator in environment
if [ "$STEP_BUILD_NEW_OPERATOR" == "true" ]; then
# build crd object
echo "--->>>create rss crd in cluster"
kubectl create -f ../../operator/config/crd/bases/uniffle.apache.org_remoteshuffleservices.yaml
sleep 5
# build operator image
echo "--->>>try to build test image of rss-operator"
build_operator_image
# generate operator yaml
echo "--->>>try to generate operator yaml from template"
export RSS_WEBHOOK_IMAGE=$TEST_REGISTRY/rss-webhook:$TEST_VERSION
export RSS_CONTROLLER_IMAGE=$TEST_REGISTRY/rss-controller:$TEST_VERSION
envsubst <template/rss-controller-template.yaml >rss-controller.yaml
envsubst <template/rss-webhook-template.yaml >rss-webhook.yaml
# build rss-operator
echo "--->>>try to apply rss-operator in cluster"
kubectl apply -f rss-controller.yaml
kubectl apply -f rss-webhook.yaml
echo "--->>>wait some time for rss-operator to be ready"
sleep 60
fi

# generate rss object yaml
if [ "$STEP_BUILD_NEW_RSS_IMAGE" == "true" ]; then
echo "--->>>try to build test image of rss"
build_rss_image
fi

echo "--->>>try to load image of rss"
export RSS_SERVER_IMAGE=$TEST_REGISTRY/rss-server:$TEST_VERSION
kind load docker-image --name ${KIND_CLUSTER_NAME} "${RSS_SERVER_IMAGE}"

echo "--->>>try to generate rss object yaml from template"
envsubst <template/rss-template.yaml >rss.yaml

# build rss object
echo "--->>>try to apply a rss object in cluster"
kubectl apply -f rss.yaml
echo "--->>>wait some time for the rss cluster to be ready"
sleep 30

target_cnt=3
target_times=5
times=0
for ((i = 1; i <= 15; i = i + 1)); do
running_cnt=$(kubectl get pod -nkube-system | grep -E "rss-coordinator|rss-shuffle-server" | grep -v "NAME" | grep -c "Running")
echo "--->>>running count: $running_cnt currently"
if [ "$running_cnt" -eq $target_cnt ]; then
times=$((times + 1))
if [ $times -eq $target_times ]; then
echo "rss running normally!"
exit
fi
else
echo "invalid running count"
times=0
fi
sleep 60
done
35 changes: 35 additions & 0 deletions deploy/kubernetes/integration-test/e2e/start-e2e.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

set -o errexit
set -o nounset
set -o pipefail

TEST_REGISTRY=${TEST_REGISTRY-"docker.io/library"}
BUILD_NEW_CLUSTER=${BUILD_NEW_CLUSTER-"true"}
BUILD_RSS_IMAGE=${BUILD_RSS_IMAGE-"true"}
BUILD_RSS_OPERATOR=${BUILD_RSS_OPERATOR-"true"}

echo "TEST_REGISTRY: $TEST_REGISTRY"
echo "BUILD_NEW_CLUSTER: $BUILD_NEW_CLUSTER"
echo "BUILD_RSS_IMAGE: $BUILD_RSS_IMAGE"
echo "BUILD_RSS_OPERATOR: $BUILD_RSS_OPERATOR"

sh set-up-local-cluster.sh --registry "$TEST_REGISTRY" --build-kind-cluster "$BUILD_NEW_CLUSTER" \
--build-rss-image "$BUILD_RSS_IMAGE" --build-operator "$BUILD_RSS_OPERATOR"
Loading

0 comments on commit 15f9b8e

Please sign in to comment.