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

add cni release test script #1971

Merged
merged 1 commit into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions scripts/run-cni-release-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env bash

# script to run integration and calico tests tests(no cluster creation & deletion/installing addons)
# use case: run script after CNI images are updated to the image to be verified (see update-cni-images.sh)

# CLUSTER_NAME: name of the cluster to run the test
# VPC_ID: cluster VPC ID
# REGION: default us-west-2
# KUBE_CONFIG_PATH: path to the kubeconfig file, default ~/.kube/config
# NG_LABEL_KEY: nodegroup label key, default "kubernetes.io/os"
# NG_LABEL_VAL: nodegroup label val, default "linux"
# CNI_METRICS_HELPER: cni metrics helper image tag, default "602401143452.dkr.ecr.us-west-2.amazonaws.com/cni-metrics-helper:v1.7.10"
# CALICO_VERSION: calico version, default 3.22.0

set -e

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
TEST_DIR="$SCRIPT_DIR/../test"
INTEGRATION_TEST_DIR="$TEST_DIR/integration-new"
CALICO_TEST_DIR="$TEST_DIR/e2e/calico"

source "$SCRIPT_DIR"/lib/cluster.sh
source "$SCRIPT_DIR"/lib/integration.sh

function run_integration_test() {
sushrk marked this conversation as resolved.
Show resolved Hide resolved
: "${NG_LABEL_KEY:=kubernetes.io/os}"
: "${NG_LABEL_VAL:=linux}"
TEST_RESULT=success
echo "Running cni integration tests"
START=$SECONDS
CGO_ENABLED=0 ginkgo -v $INTEGRATION_TEST_DIR/cni --timeout 60m --fail-on-pending -- --cluster-kubeconfig="$KUBE_CONFIG_PATH" --cluster-name="$CLUSTER_NAME" --aws-region="$REGION" --aws-vpc-id="$VPC_ID" --ng-name-label-key="$NG_LABEL_KEY" --ng-name-label-val="$NG_LABEL_VAL" || TEST_RESULT=fail
echo "cni test took $((SECONDS - START)) seconds."
echo "Running ipamd integration tests"
START=$SECONDS
CGO_ENABLED=0 ginkgo -v $INTEGRATION_TEST_DIR/ipamd --timeout 120m --fail-on-pending -- --cluster-kubeconfig="$KUBE_CONFIG_PATH" --cluster-name="$CLUSTER_NAME" --aws-region="$REGION" --aws-vpc-id="$VPC_ID" --ng-name-label-key="$NG_LABEL_KEY" --ng-name-label-val="$NG_LABEL_VAL" || TEST_RESULT=fail
echo "ipamd test took $((SECONDS - START)) seconds."

: "${CNI_METRICS_HELPER:=602401143452.dkr.ecr.us-west-2.amazonaws.com/cni-metrics-helper:v1.7.10}"
REPO_NAME=$(echo $CNI_METRICS_HELPER | cut -d ":" -f 1)
TAG=$(echo $CNI_METRICS_HELPER | cut -d ":" -f 2)
echo "Running cni-metrics-helper image($CNI_METRICS_HELPER) tests"
START=$SECONDS
CGO_ENABLED=0 ginkgo -v $INTEGRATION_TEST_DIR/metrics-helper --timeout 120m --fail-on-pending -- --cluster-kubeconfig="$KUBE_CONFIG_PATH" --cluster-name="$CLUSTER_NAME" --aws-region="$REGION" --aws-vpc-id="$VPC_ID" --ng-name-label-key="$NG_LABEL_KEY" --ng-name-label-val="$NG_LABEL_VAL" --cni-metrics-helper-image-repo=$REPO_NAME --cni-metrics-helper-image-tag=$TAG || TEST_RESULT=fail
echo "cni-metrics-helper test took $((SECONDS - START)) seconds."
if [[ "$TEST_RESULT" == fail ]]; then
echo "Integration test failed."
exit 1
fi
echo "Integration tests completed successfully!"
}

function run_calico_tests(){
# get version from run-integration-tests.sh
: "${CALICO_VERSION:=3.22.0}"
echo "Running calico tests, version $CALICO_VERSION"
START=$SECONDS
TEST_RESULT=success
ginkgo -v $CALICO_TEST_DIR -- --cluster-kubeconfig=$KUBE_CONFIG_PATH --cluster-name=$CLUSTER_NAME --aws-region=$REGION --aws-vpc-id=$VPC_ID --calico-version=$CALICO_VERSION || TEST_RESULT=fail
if [[ "$TEST_RESULT" == fail ]]; then
echo "Calico tests failed."
exit 1
fi
echo "Calico tests completed successfully!"
}

if [[ -n "${ENDPOINT}" ]]; then
ENDPOINT_FLAG="--endpoint $ENDPOINT"
fi

echo "Running release tests on cluster: $CLUSTER_NAME in region: $REGION"
load_cluster_details
START=$SECONDS
cd $TEST_DIR
run_integration_test
run_calico_tests
echo "Completed running all tests in $((SECONDS - START)) seconds."
2 changes: 1 addition & 1 deletion scripts/update-cni-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ grep -r -q $AMAZON_K8S_CNI_INIT $AWS_K8S_CNI_MANIFEST
echo "Applying aws-k8s-cni.yaml manifest to aws-node daemonset"
kubectl apply -f $AWS_K8S_CNI_MANIFEST

check_ds_rollout "aws-node" "kube-system"
check_ds_rollout "aws-node" "kube-system" "4m"
5 changes: 5 additions & 0 deletions test/framework/controller/installation_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ func (d *defaultInstallationManager) InstallCNIMetricsHelper(image string, tag s
dir, _ := filepath.Abs(filepath.Dir(os.Args[0]))
projectRoot := strings.SplitAfter(dir, "amazon-vpc-cni-k8s")[0]

if dir == projectRoot {
// in prow tests, the repository name is "vpc-cni"
projectRoot = strings.SplitAfter(dir, "vpc-cni")[0]
}

values := map[string]interface{}{
"image": map[string]interface{}{
"repository": image,
Expand Down
2 changes: 2 additions & 0 deletions test/framework/helm/release_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package helm
import (
"fmt"
"log"
"time"

"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chart/loader"
Expand Down Expand Up @@ -51,6 +52,7 @@ func (d *defaultReleaseManager) InstallUnPackagedRelease(chart string, releaseNa
installAction.Namespace = namespace
installAction.Wait = true
installAction.ReleaseName = releaseName
installAction.Timeout = time.Minute

return installCharts(installAction, chart, values)
}
Expand Down
3 changes: 3 additions & 0 deletions test/integration-new/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ In order to test a custom image you need pass the following tags along with the

*IMPORTANT*: Should use an IPv6 cluster with Prefix Delegation enabled. VPC CNI only supports IPv6 mode with Prefix Delegation.

### Running release tests with scripts/run-cni-release-tests.sh
`run-cni-release-tests.sh` will run cni, ipamd, and cni-metrics-helper (integration tests)[https://github.com/aws/amazon-vpc-cni-k8s/tree/master/test/integration-new] and (Calico tests)[https://github.com/aws/amazon-vpc-cni-k8s/tree/master/test/e2e/calico]. The script _does not_ create a test cluster, instead it will run the test on cluster specified via variables required in the script. The tests are run on the vpc-cni version installed on the cluster(it does not upgrade/install any specific vpc-cni version). See script `update-cni-images.sh` to update the test cluster with required cni version before running the tests.

### Future Work
Currently the package is named as `integration-new` because we already have `integration` directory with existing Ginkgo test cases with a separate `go.mod`. Once the older package is completely deprecated we will rename this package to `integration`.

Expand Down