Skip to content

Commit 43d9eec

Browse files
author
Fawad Khaliq
authored
Add integration tests to gh actions kind setup (#381)
1 parent 1f912cc commit 43d9eec

File tree

6 files changed

+104
-17
lines changed

6 files changed

+104
-17
lines changed

scripts/install-cert-manager.sh

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,37 @@
66

77
set -Eo pipefail
88

9+
SCRIPTS_DIR=$(cd "$(dirname "$0")" || exit 1; pwd)
910
DEFAULT_CERT_MANAGER_VERSION="v0.14.3"
1011

12+
source "$SCRIPTS_DIR/lib/k8s.sh"
13+
source "$SCRIPTS_DIR/lib/common.sh"
14+
1115
check_is_installed kubectl "You can install kubectl with the helper scripts/install-kubectl.sh"
1216

1317
__cert_manager_version="$1"
1418
if [ "z$__cert_manager_version" == "z" ]; then
1519
__cert_manager_version=${CERT_MANAGER_VERSION:-$DEFAULT_CERT_MANAGER_VERSION}
1620
fi
1721

18-
echo -n "installing cert-manager ... "
19-
__cert_manager_url="https://github.com/jetstack/cert-manager/releases/download/${__cert_manager_version}/cert-manager.yaml"
20-
echo -n "installing cert-manager from $__cert_manager_url ... "
21-
kubectl apply --validate=false -f $__cert_manager_url
22-
echo "ok."
22+
install() {
23+
echo -n "installing cert-manager ... "
24+
__cert_manager_url="https://github.com/jetstack/cert-manager/releases/download/${__cert_manager_version}/cert-manager.yaml"
25+
echo -n "installing cert-manager from $__cert_manager_url ... "
26+
kubectl apply --validate=false -f $__cert_manager_url
27+
echo "ok."
28+
}
29+
30+
check() {
31+
echo -n "checking cert-manager deployments have rolled out ... "
32+
local __ns="cert-manager"
33+
local __timeout="4m"
34+
check_deployment_rollout cert-manager-webhook $__ns $__timeout
35+
check_deployment_rollout cert-manager $__ns
36+
check_deployment_rollout cert-manager-cainjector $__ns
37+
echo "ok."
38+
}
39+
40+
41+
install
42+
check

scripts/lib/aws.sh

100644100755
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ ecr_login() {
2323
local __err_msg="Failed ECR login. Please make sure you have IAM permissions to access ECR."
2424
if [ $AWS_CLI_VERSION -gt 1 ]; then
2525
( aws ecr get-login-password --region $__aws_region | \
26-
docker login --username AWS --password-stdin $__ecr_url ) ||
27-
( echo "\n$__err_msg" && exit 1 )
26+
docker login --username AWS --password-stdin $__ecr_url ) ||
27+
( echo "\n$__err_msg" && exit 1 )
2828
else
29-
$( aws ecr get-login --no-include-email ) || ( echo "\n$__err_msg" && exit 1 )
29+
$( aws ecr get-login --no-include-email ) || ( echo "\n$__err_msg" && exit 1 )
3030
fi
3131
echo "ok."
3232
}

scripts/lib/common.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ is_installed() {
3939
# vpc id is needed for setting up AWS CloudMap namespaces
4040
vpc_id() {
4141
local __md_url="http://169.254.169.254/latest/meta-data/network/interfaces"
42-
local __macid=$( curl $__md_url/macs/ || exit 1 )
43-
local __vpcid=$( curl $__md_url/macs/${macid}/vpc-id || exit 1 )
42+
local __macid=$( curl ${__md_url}/macs/ || exit 1 )
43+
local __vpcid=$( curl ${__md_url}/macs/${__macid}vpc-id || exit 1 )
4444
echo "$__vpcid"
4545

4646
}

scripts/lib/k8s.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
3+
THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
4+
ROOT_DIR="$THIS_DIR/../.."
5+
SCRIPTS_DIR="$ROOT_DIR/scripts"
6+
7+
# resource_exists returns 0 when the supplied resource can be found, 1
8+
# otherwise. An optional second parameter overrides the Kubernetes namespace
9+
# argument
10+
k8s_resource_exists() {
11+
local __res_name=${1:-}
12+
local __namespace=${2:-}
13+
local __args=""
14+
if [ -n "$__namespace" ]; then
15+
__args="$__args-n $__namespace"
16+
fi
17+
kubectl get $__args "$__res_name" >/dev/null 2>&1
18+
}
19+
20+
21+
# check_deployment_rollout watches the status of the latest rollout
22+
# until it's done or until the timeout. Namespace and timeout are optional
23+
# parameters
24+
check_deployment_rollout() {
25+
local __dep_name=${1:-}
26+
local __namespace=${2:-}
27+
local __timeout=${3:-"2m"}
28+
local __args=""
29+
if [ -n "$__namespace" ]; then
30+
__args="$__args-n $__namespace"
31+
fi
32+
kubectl rollout status deployment/"$__dep_name" $__args --timeout=$__timeout
33+
}

scripts/test-with-kind.sh

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ IMAGE=${ECR_URL}/${IMAGE_NAME}
1818

1919

2020
CLUSTER_NAME_BASE="test"
21+
CLUSTER_NAME=""
2122
K8S_VERSION="1.17"
2223
TMP_DIR=""
2324

2425
source "$SCRIPTS_DIR/lib/aws.sh"
2526
source "$SCRIPTS_DIR/lib/common.sh"
27+
source "$SCRIPTS_DIR/lib/k8s.sh"
2628

2729
check_is_installed curl
2830
check_is_installed docker
@@ -56,8 +58,26 @@ function build_and_publish_controller {
5658
echo "ok."
5759
}
5860

59-
function run_integration_tests {
60-
echo "Not implemented"
61+
function install_controller {
62+
echo -n "installing appmesh controller ... "
63+
local __controller_name="appmesh-controller"
64+
local __ns="appmesh-system"
65+
AWS_ACCOUNT=$AWS_ACCOUNT_ID AWS_REGION=$AWS_REGION make deploy
66+
check_deployment_rollout $__controller_name $__ns
67+
echo -n "check the pods in appmesh-system namespace ... "
68+
kubectl get pod -n $__ns
69+
echo "ok."
70+
71+
}
72+
73+
function run_integration_test {
74+
local __type=$1
75+
local __vpc_id=$( vpc_id )
76+
echo -n "running integration test type $__type ... "
77+
ginkgo -v -r test/integration/$__type -- --cluster-kubeconfig=${KUBECONFIG} \
78+
--cluster-name=${CLUSTER_NAME} --aws-region=${AWS_REGION} \
79+
--aws-vpc-id=$__vpc_id
80+
echo "ok."
6181
}
6282

6383
function clean_up {
@@ -89,5 +109,19 @@ install_crds
89109
# Install cert-manager
90110
$SCRIPTS_DIR/install-cert-manager.sh
91111

112+
# Install the controller
113+
install_controller
114+
92115
# Show the installed CRDs
93116
kubectl get crds
117+
118+
#FIXME sometimes the test controller "deployment" is ready but internally process is not ready
119+
# leading to tests failing. Added this hack to workaround. Will be replaced with a better
120+
# check later
121+
sleep 15
122+
123+
# Run integration tests
124+
run_integration_test mesh
125+
run_integration_test virtualservice
126+
run_integration_test virtualrouter
127+
run_integration_test gatewayroute

test/framework/utils/poll.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package utils
33
import "time"
44

55
const (
6-
PollIntervalShort = 2 * time.Second
7-
PollIntervalMedium = 10 * time.Second
8-
PollRetries = 5
6+
PollIntervalShort = 5 * time.Second
7+
PollIntervalMedium = 15 * time.Second
8+
PollRetries = 10
99

10-
AWSPollIntervalShort = 1 * time.Second
11-
AWSPollIntervalMedium = 5 * time.Second
10+
AWSPollIntervalShort = 5 * time.Second
11+
AWSPollIntervalMedium = 15 * time.Second
1212
)

0 commit comments

Comments
 (0)