Skip to content

Commit

Permalink
Add conformance as a github action
Browse files Browse the repository at this point in the history
Signed-off-by: Dyanngg <[email protected]>
  • Loading branch information
Dyanngg committed Jul 14, 2023
1 parent e6b84f1 commit 85d10c0
Show file tree
Hide file tree
Showing 2 changed files with 228 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/kind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,47 @@ jobs:
path: log.tar.gz
retention-days: 30

test-network-policy-conformance-encap:
name: Conformance tests on a Kind cluster on Linux
needs: [build-antrea-coverage-image]
runs-on: [ubuntu-latest]
steps:
- name: Free disk space
# https://github.com/actions/virtual-environments/issues/709
run: |
sudo apt-get clean
df -h
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
- name: Download Antrea image from previous job
uses: actions/download-artifact@v3
with:
name: antrea-ubuntu-cov
- name: Load Antrea image
run: |
docker load -i antrea-ubuntu.tar
- name: Install Kind
run: |
curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-$(uname)-amd64
chmod +x ./kind
sudo mv kind /usr/local/bin
- name: Run conformance tests
run: |
mkdir log
ANTREA_LOG_DIR=$PWD/log ./ci/kind/test-conformance-kind.sh --encap-mode encap
- name: Tar log files
if: ${{ failure() }}
run: tar -czf log.tar.gz log
- name: Upload test log
uses: actions/upload-artifact@v3
if: ${{ failure() }}
with:
name: conformance-kind-encap.tar.gz
path: log.tar.gz
retention-days: 30

test-upgrade-from-N-1:
name: Upgrade from Antrea version N-1
needs: build-antrea-coverage-image
Expand Down Expand Up @@ -649,6 +690,7 @@ jobs:
- test-compatible-N-2
- validate-prometheus-metrics-doc
- test-e2e-flow-visibility
- test-network-policy-conformance-encap
runs-on: [ubuntu-latest]
steps:
- name: Delete antrea-ubuntu-cov
Expand Down
186 changes: 186 additions & 0 deletions ci/kind/test-conformance-kind.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
#!/usr/bin/env bash

# Copyright 2023 Antrea Authors
#
# Licensed 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.

# The script runs kind e2e tests with different traffic encapsulation modes.

set -eo pipefail

function echoerr {
>&2 echo "$@"
}

_usage="Usage: $0 [--encap-mode <mode>] [--ip-family <v4|v6>] [--help|-h]
--encap-mode Traffic encapsulation mode. (default is 'encap').
--ip-family Configures the ipFamily for the KinD cluster.
--feature-gates A comma-separated list of key=value pairs that describe feature gates, e.g. AntreaProxy=true,Egress=false.
--setup-only Only perform setting up the cluster and run test.
--cleanup-only Only perform cleaning up the cluster.
--test-only Only run test on current cluster. Not set up/clean up the cluster.
--help, -h Print this message and exit.
"

function print_usage {
echoerr -n "$_usage"
}

TESTBED_CMD=$(dirname $0)"/kind-setup.sh"
YML_CMD=$(dirname $0)"/../../hack/generate-manifest.sh"

function quit {
result=$?
if [[ $setup_only || $test_only ]]; then
exit $result
fi
echoerr "Cleaning testbed"
$TESTBED_CMD destroy kind
}

mode=""
ipfamily="v4"
feature_gates="AdminNetworkPolicy=true"
setup_only=false
cleanup_only=false
test_only=false
while [[ $# -gt 0 ]]
do
key="$1"

case $key in
--feature-gates)
feature_gates="$2"
shift 2
;;
--ip-family)
ipfamily="$2"
shift 2
;;
--encap-mode)
mode="$2"
shift 2
;;
--setup-only)
setup_only=true
shift
;;
--cleanup-only)
cleanup_only=true
shift
;;
--test-only)
test_only=true
shift
;;
-h|--help)
print_usage
exit 0
;;
*) # unknown option
echoerr "Unknown option $1"
exit 1
;;
esac
done

if [[ $cleanup_only == "true" ]];then
$TESTBED_CMD destroy kind
exit 0
fi

trap "quit" INT EXIT

manifest_args="$manifest_args --verbose-log"
if [ -n "$feature_gates" ]; then
manifest_args="$manifest_args --feature-gates $feature_gates"
fi

IMAGE_LIST=("registry.k8s.io/e2e-test-images/agnhost:2.43" \
"antrea/antrea-ubuntu-coverage:latest")

for image in "${IMAGE_LIST[@]}"; do
for i in $(seq 3); do
docker pull $image && break
sleep 1
done
done

printf -v IMAGES "%s " "${IMAGE_LIST[@]}"

function setup_cluster {
args=$1

if [[ "$ipfamily" == "v6" ]]; then
args="$args --ip-family ipv6 --pod-cidr fd00:10:244::/56"
elif [[ "$ipfamily" != "v4" ]]; then
echoerr "invalid value for --ip-family \"$ipfamily\", expected \"v4\" or \"v6\""
exit 1
fi

echo "creating test bed with args $args"
eval "timeout 600 $TESTBED_CMD create kind $args"
}

function run_test {
current_mode=$1

# Install the network-policy-api CRDs in the kind cluster
kubectl apply -f https://github.com/kubernetes-sigs/network-policy-api/releases/download/v0.1.0/install.yaml
echo "Generating Antrea manifest with args $manifest_args"
$YML_CMD --encap-mode $current_mode $manifest_args | kubectl apply -f -
$YML_CMD --encap-mode $current_mode $manifest_args | docker exec -i kind-control-plane dd of=/root/antrea.yml

sleep 5
kubectl get deployment antrea-controller -nkube-system -o yaml
PO=$(kubectl get po -nkube-system -l component=antrea-controller | grep antrea-controller | cut -d' ' -f1)
kubectl logs $PO -nkube-system

kubectl rollout status --timeout=1m deployment.apps/antrea-controller -n kube-system
kubectl rollout status --timeout=1m daemonset/antrea-agent -n kube-system
timeout="5m"

sleep 1
export KUBERNETES_CONFORMANCE_TEST=y
export KUBE_CONTAINER_RUNTIME=remote
export KUBE_CONTAINER_RUNTIME_ENDPOINT=unix:///run/containerd/containerd.sock
export KUBE_CONTAINER_RUNTIME_NAME=containerd

pushd "$(dirname "$0")"/../../test/conformance
go mod download
go test -v -timeout=$timeout
popd
}

if [[ "$mode" == "" ]] || [[ "$mode" == "encap" ]]; then
echo "======== Test encap mode =========="
if [[ $test_only == "false" ]];then
setup_cluster "--images \"$IMAGES\""
fi
run_test encap
fi
if [[ "$mode" == "" ]] || [[ "$mode" == "noEncap" ]]; then
echo "======== Test noencap mode =========="
if [[ $test_only == "false" ]];then
setup_cluster "--images \"$IMAGES\""
fi
run_test noEncap
fi
if [[ "$mode" == "" ]] || [[ "$mode" == "hybrid" ]]; then
echo "======== Test hybrid mode =========="
if [[ $test_only == "false" ]];then
setup_cluster "--subnets \"20.20.20.0/24\" --images \"$IMAGES\""
fi
run_test hybrid
fi
exit 0

0 comments on commit 85d10c0

Please sign in to comment.