1
+ #! /bin/bash
2
+
3
+ # This script runs e2e tests on the AWS Load Balancer Controller
4
+
5
+ set -e
6
+
7
+ SECONDS=0
8
+ SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " > /dev/null 2>&1 && pwd ) "
9
+ echo " Running AWS Load Balancer Controller e2e tests with the following variables
10
+ KUBE CONFIG: $KUBE_CONFIG_PATH
11
+ CLUSTER_NAME: $CLUSTER_NAME
12
+ REGION: $REGION
13
+ OS_OVERRIDE: $OS_OVERRIDE "
14
+
15
+ function toggle_windows_scheduling(){
16
+ schedule=$1
17
+ nodes=$( kubectl get nodes -l kubernetes.io/os=windows | tail -n +2 | cut -d' ' -f1)
18
+ for n in $nodes
19
+ do
20
+ kubectl $schedule $n
21
+ done
22
+ }
23
+
24
+ if [[ -z " ${OS_OVERRIDE} " ]]; then
25
+ OS_OVERRIDE=linux
26
+ fi
27
+
28
+ GET_CLUSTER_INFO_CMD=" aws eks describe-cluster --name $CLUSTER_NAME --region $REGION "
29
+
30
+ if [[ -z " ${ENDPOINT} " ]]; then
31
+ CLUSTER_INFO=$( $GET_CLUSTER_INFO_CMD )
32
+ else
33
+ CLUSTER_INFO=$( $GET_CLUSTER_INFO_CMD --endpoint $ENDPOINT )
34
+ fi
35
+
36
+ echo " Cordon off windows nodes"
37
+ toggle_windows_scheduling " cordon"
38
+
39
+ VPC_ID=$( echo $CLUSTER_INFO | jq -r ' .cluster.resourcesVpcConfig.vpcId' )
40
+ ACCOUNT_ID=$( aws sts get-caller-identity | jq -r ' .Account' )
41
+
42
+ echo " VPC ID: $VPC_ID "
43
+
44
+ eksctl utils associate-iam-oidc-provider \
45
+ --region $REGION \
46
+ --cluster $CLUSTER_NAME \
47
+ --approve
48
+
49
+ echo " Creating AWSLoadbalancerController IAM Policy"
50
+ curl -o iam-policy.json https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/v2.2.1/docs/install/iam_policy.json
51
+
52
+ aws iam create-policy \
53
+ --policy-name AWSLoadBalancerControllerIAMPolicy \
54
+ --policy-document file://iam-policy.json || true
55
+
56
+ echo " Creating IAM serviceaccount"
57
+ eksctl create iamserviceaccount \
58
+ --cluster=$CLUSTER_NAME \
59
+ --namespace=kube-system \
60
+ --name=aws-load-balancer-controller \
61
+ --attach-policy-arn=arn:aws:iam::$ACCOUNT_ID :policy/AWSLoadBalancerControllerIAMPolicy \
62
+ --override-existing-serviceaccounts \
63
+ --approve || true
64
+
65
+ echo " Update helm repo eks"
66
+ helm repo add eks https://aws.github.io/eks-charts
67
+
68
+ helm repo update
69
+
70
+ echo " Install TargetGroupBinding CRDs"
71
+ kubectl apply -k " github.com/aws/eks-charts/stable/aws-load-balancer-controller//crds?ref=master"
72
+
73
+ echo " Install aws-load-balancer-controller"
74
+ 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
75
+
76
+ # Start the test
77
+ echo " Starting the ginkgo test suite"
78
+
79
+ (cd $SCRIPT_DIR && CGO_ENABLED=0 GOOS=$OS_OVERRIDE ginkgo -v -r --timeout 60m --failOnPending -- --kubeconfig=$KUBE_CONFIG_PATH --cluster-name=$CLUSTER_NAME --aws-region=$REGION --aws-vpc-id=$VPC_ID || true)
80
+
81
+ echo " Delete aws-load-balancer-controller"
82
+ helm delete aws-load-balancer-controller -n kube-system --timeout=10m || true
83
+
84
+ echo " Delete iamserviceaccount"
85
+ eksctl delete iamserviceaccount --name aws-load-balancer-controller --namespace kube-system --cluster $CLUSTER_NAME --timeout=10m || true
86
+
87
+ echo " Delete TargetGroupBinding CRDs"
88
+ kubectl delete -k " github.com/aws/eks-charts/stable/aws-load-balancer-controller//crds?ref=master" --timeout=10m || true
89
+
90
+ echo " Uncordon windows nodes"
91
+ toggle_windows_scheduling " uncordon"
92
+
93
+ echo " Successfully finished the test suite $(( $SECONDS / 60 )) minutes and $(( $SECONDS % 60 )) seconds"
0 commit comments