Skip to content

Commit e88bfee

Browse files
author
Chinmay Gadgil
committed
Added helper script to run e2e tests
Avoid abrupt script termination if there is an exception in ginkgo tests Fixed logging minor change
1 parent 92445ac commit e88bfee

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

test/e2e/run.sh

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/bin/bash
2+
3+
# This script runs e2e tests on the AWS Load Balancer Controller
4+
5+
set -e
6+
7+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
8+
echo "Running AWS Load Balancer Controller e2e tests with the following variables
9+
KUBE CONFIG: $KUBE_CONFIG_PATH
10+
CLUSTER_NAME: $CLUSTER_NAME
11+
REGION: $REGION
12+
OS_OVERRIDE: $OS_OVERRIDE"
13+
14+
if [[ -z "${OS_OVERRIDE}" ]]; then
15+
OS_OVERRIDE=linux
16+
fi
17+
18+
CLUSTER_INFO=$(aws eks describe-cluster --name $CLUSTER_NAME --region $REGION)
19+
20+
VPC_ID=$(echo $CLUSTER_INFO | jq -r '.cluster.resourcesVpcConfig.vpcId')
21+
SERVICE_ROLE_ARN=$(echo $CLUSTER_INFO | jq -r '.cluster.roleArn')
22+
ROLE_NAME=${SERVICE_ROLE_ARN##*/}
23+
24+
ACCOUNT_ID=$(aws sts get-caller-identity | jq -r '.Account')
25+
26+
echo "VPC ID: $VPC_ID, Service Role ARN: $SERVICE_ROLE_ARN, Role Name: $ROLE_NAME"
27+
28+
# Set up local resources
29+
echo "Attaching IAM Policy to Cluster Service Role"
30+
aws iam attach-role-policy \
31+
--policy-arn arn:aws:iam::aws:policy/AmazonEKSVPCResourceController \
32+
--role-name "$ROLE_NAME" > /dev/null
33+
34+
echo "Enabling Pod ENI on aws-node"
35+
kubectl set env daemonset aws-node -n kube-system ENABLE_POD_ENI=true
36+
37+
eksctl utils associate-iam-oidc-provider \
38+
--region $REGION \
39+
--cluster $CLUSTER_NAME \
40+
--approve
41+
42+
echo "Create AWSLoadbalancerController IAM Policy"
43+
curl -o iam-policy.json https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/v2.2.1/docs/install/iam_policy.json
44+
45+
aws iam create-policy \
46+
--policy-name AWSLoadBalancerControllerIAMPolicy \
47+
--policy-document file://iam-policy.json || true
48+
49+
echo "Create IAM serviceaccount"
50+
eksctl create iamserviceaccount \
51+
--cluster=$CLUSTER_NAME \
52+
--namespace=kube-system \
53+
--name=aws-load-balancer-controller \
54+
--attach-policy-arn=arn:aws:iam::$ACCOUNT_ID:policy/AWSLoadBalancerControllerIAMPolicy \
55+
--override-existing-serviceaccounts \
56+
--approve || true
57+
58+
echo "Update helm repo eks"
59+
helm repo add eks https://aws.github.io/eks-charts
60+
61+
helm repo update
62+
63+
echo "Install TargetGroupBinding CRDs"
64+
kubectl apply -k "github.com/aws/eks-charts/stable/aws-load-balancer-controller//crds?ref=master"
65+
66+
echo "Install aws-load-balacner-controller"
67+
helm upgrade -i aws-load-balancer-controller eks/aws-load-balancer-controller -n kube-system --set clusterName=$CLUSTER_NAME --set serviceAccount.create=false --set serviceAccount.name=aws-load-balancer-controller
68+
69+
#Start the test
70+
echo "Starting the ginkgo test suite"
71+
72+
(cd $SCRIPT_DIR && CGO_ENABLED=0 GOOS=$OS_OVERRIDE ginkgo -v -r -- --kubeconfig=$KUBE_CONFIG_PATH --cluster-name=$CLUSTER_NAME --aws-region=$REGION --aws-vpc-id=$VPC_ID || true)
73+
74+
echo "Successfully finished the test suite"
75+
76+
#Tear down local resources
77+
echo "Detaching the IAM Policy from Cluster Service Role"
78+
aws iam detach-role-policy \
79+
--policy-arn arn:aws:iam::aws:policy/AmazonEKSVPCResourceController \
80+
--role-name $ROLE_NAME || true
81+
82+
echo "Disabling Pod ENI on aws-node"
83+
kubectl set env daemonset aws-node -n kube-system ENABLE_POD_ENI=false
84+
85+
echo "Delete iamserviceaccount"
86+
eksctl delete iamserviceaccount --name aws-load-balancer-controller --namespace kube-system --cluster $CLUSTER_NAME || true
87+
88+
echo "Delete TargetGroupBinding CRDs"
89+
kubectl delete -k "github.com/aws/eks-charts/stable/aws-load-balancer-controller//crds?ref=master"
90+
91+
echo "Delete aws-load-balacner-controller"
92+
helm delete aws-load-balancer-controller -n kube-system

0 commit comments

Comments
 (0)