Skip to content

Commit ed1f080

Browse files
author
cgchinmay
authored
e2e test changes to support china regions (#2723)
* Use Colorteller application image from public docker registry * Updated e2e test runner script to support china regions * Updated ColortellerImage tag
1 parent a292571 commit ed1f080

File tree

4 files changed

+38
-14
lines changed

4 files changed

+38
-14
lines changed

scripts/run-e2e-test.sh

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,17 @@ function cleanUp(){
3232

3333
# IAM role and polcies are AWS Account specific, so need to clean them up if any from previous run
3434
echo "detach IAM policy if it exists"
35-
aws iam detach-role-policy --role-name $ROLE_NAME --policy-arn arn:aws:iam::$ACCOUNT_ID:policy/AWSLoadBalancerControllerIAMPolicy || true
35+
aws iam detach-role-policy --role-name $ROLE_NAME --policy-arn arn:${AWS_PARTITION}:iam::$ACCOUNT_ID:policy/AWSLoadBalancerControllerIAMPolicy || true
3636

37+
# wait for 10 sec to complete detaching of IAM policy
38+
sleep 10
39+
3740
echo "delete $ROLE_NAME if it exists"
3841
aws iam delete-role --role-name $ROLE_NAME || true
3942

4043
# Need to do this as last step
4144
echo "delete AWSLoadBalancerControllerIAMPolicy if it exists"
42-
aws iam delete-policy --policy-arn arn:aws:iam::$ACCOUNT_ID:policy/AWSLoadBalancerControllerIAMPolicy || true
45+
aws iam delete-policy --policy-arn arn:${AWS_PARTITION}:iam::$ACCOUNT_ID:policy/AWSLoadBalancerControllerIAMPolicy || true
4346
}
4447

4548
echo "cordon off windows nodes"
@@ -49,6 +52,23 @@ echo "fetch OIDC provider"
4952
OIDC_PROVIDER=$(echo $CLUSTER_INFO | jq -r '.cluster.identity.oidc.issuer' | sed -e "s/^https:\/\///")
5053
echo "OIDC Provider: $OIDC_PROVIDER"
5154

55+
AWS_PARTITION="aws"
56+
IAM_POLCIY_FILE="iam_policy.json"
57+
58+
if [[ $REGION == "cn-north-1" || $REGION == "cn-northwest-1" ]];then
59+
AWS_PARTITION="aws-cn"
60+
IAM_POLCIY_FILE="iam_policy_cn.json"
61+
fi
62+
63+
if [[ $REGION == "cn-north-1" ]];then
64+
IMAGE="918309763551.dkr.ecr.cn-north-1.amazonaws.com.cn/amazon/aws-load-balancer-controller"
65+
elif [[ $REGION == "cn-northwest-1" ]];then
66+
IMAGE="961992271922.dkr.ecr.cn-northwest-1.amazonaws.com.cn/amazon/aws-load-balancer-controller"
67+
else
68+
IMAGE="602401143452.dkr.ecr.us-west-2.amazonaws.com/amazon/aws-load-balancer-controller"
69+
fi
70+
71+
echo "IMAGE: $IMAGE"
5272
echo "create IAM policy document file"
5373
cat <<EOF > trust.json
5474
{
@@ -57,7 +77,7 @@ cat <<EOF > trust.json
5777
{
5878
"Effect": "Allow",
5979
"Principal": {
60-
"Federated": "arn:aws:iam::${ACCOUNT_ID}:oidc-provider/${OIDC_PROVIDER}"
80+
"Federated": "arn:${AWS_PARTITION}:iam::${ACCOUNT_ID}:oidc-provider/${OIDC_PROVIDER}"
6181
},
6282
"Action": "sts:AssumeRoleWithWebIdentity",
6383
"Condition": {
@@ -80,27 +100,24 @@ aws iam create-role --role-name $ROLE_NAME --assume-role-policy-document file://
80100
echo "creating AWSLoadbalancerController IAM Policy"
81101
aws iam create-policy \
82102
--policy-name AWSLoadBalancerControllerIAMPolicy \
83-
--policy-document file://"$SCRIPT_DIR"/../docs/install/iam_policy.json || true
103+
--policy-document file://"$SCRIPT_DIR"/../docs/install/${IAM_POLCIY_FILE} || true
84104

85105
echo "attaching AWSLoadbalancerController IAM Policy to $ROLE_NAME"
86-
aws iam attach-role-policy --policy-arn arn:aws:iam::$ACCOUNT_ID:policy/AWSLoadBalancerControllerIAMPolicy --role-name $ROLE_NAME || true
106+
aws iam attach-role-policy --policy-arn arn:${AWS_PARTITION}:iam::$ACCOUNT_ID:policy/AWSLoadBalancerControllerIAMPolicy --role-name $ROLE_NAME || true
87107

88108
echo "create service account"
89109
kubectl create serviceaccount aws-load-balancer-controller -n kube-system || true
90110

91111
echo "annotate service account with $ROLE_NAME"
92-
kubectl annotate serviceaccount -n kube-system aws-load-balancer-controller eks.amazonaws.com/role-arn=arn:aws:iam::"$ACCOUNT_ID":role/"$ROLE_NAME" --overwrite=true || true
112+
kubectl annotate serviceaccount -n kube-system aws-load-balancer-controller eks.amazonaws.com/role-arn=arn:${AWS_PARTITION}:iam::"$ACCOUNT_ID":role/"$ROLE_NAME" --overwrite=true || true
93113

94114
echo "update helm repo eks"
95115
helm repo add eks https://aws.github.io/eks-charts
96116

97117
helm repo update
98118

99-
echo "Install TargetGroupBinding CRDs"
100-
kubectl apply -k "github.com/aws/eks-charts/stable/aws-load-balancer-controller//crds?ref=master"
101-
102119
echo "Install aws-load-balancer-controller"
103-
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 --set region=$REGION --set vpcId=$VPC_ID
120+
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 --set region=$REGION --set vpcId=$VPC_ID --set image.repository=$IMAGE
104121

105122
echo_time() {
106123
date +"%D %T $*"
@@ -146,7 +163,7 @@ run_ginkgo_test
146163
# tail=-1 is added so that no logs are truncated
147164
# https://github.com/kubernetes/kubectl/issues/812
148165
echo "Fetch most recent aws-load-balancer-controller logs"
149-
kubectl logs -l app.kubernetes.io/name=aws-load-balancer-controller --container aws-load-balancer-controller --tail=-1 -n kube-system
166+
kubectl logs -l app.kubernetes.io/name=aws-load-balancer-controller --container aws-load-balancer-controller --tail=-1 -n kube-system || true
150167

151168
echo "Uncordon windows nodes"
152169
toggle_windows_scheduling "uncordon"
@@ -155,6 +172,6 @@ echo "clean up resources from current run"
155172
cleanUp
156173

157174
echo "Delete TargetGroupBinding CRDs if exists"
158-
kubectl delete -k "github.com/aws/eks-charts/stable/aws-load-balancer-controller//crds?ref=master" --timeout=10m || true
175+
kubectl delete -k "github.com/aws/eks-charts/stable/aws-load-balancer-controller//crds?ref=master" --timeout=30m || true
159176

160177
echo "Successfully finished the test suite $(($SECONDS / 60)) minutes and $(($SECONDS % 60)) seconds"

test/e2e/ingress/multi_path_backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ func (s *multiPathBackendStack) buildBackendResource(ns *corev1.Namespace, backe
316316
Containers: []corev1.Container{
317317
{
318318
Name: "app",
319-
Image: "970805265562.dkr.ecr.us-west-2.amazonaws.com/colorteller:latest",
319+
Image: utils.ColortellerImage,
320320
Ports: []corev1.ContainerPort{
321321
{
322322
ContainerPort: 8080,

test/framework/manifest/fixed_response_service_builder.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ package manifest
22

33
import (
44
"fmt"
5+
56
"github.com/aws/aws-sdk-go/aws"
67
appsv1 "k8s.io/api/apps/v1"
78
corev1 "k8s.io/api/core/v1"
89
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
910
"k8s.io/apimachinery/pkg/util/intstr"
11+
"sigs.k8s.io/aws-load-balancer-controller/test/framework/utils"
1012
)
1113

1214
// NewFixedResponseServiceBuilder constructs a builder that capable to build manifest for an HTTP service with fixed response.
@@ -93,7 +95,7 @@ func (b *fixedResponseServiceBuilder) buildDeployment(namespace string, name str
9395
Containers: []corev1.Container{
9496
{
9597
Name: "app",
96-
Image: "970805265562.dkr.ecr.us-west-2.amazonaws.com/colorteller:latest",
98+
Image: utils.ColortellerImage,
9799
Ports: []corev1.ContainerPort{
98100
{
99101
Name: b.targetPortName,

test/framework/utils/constants.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package utils
2+
3+
const (
4+
ColortellerImage = "chinmay5j/colorteller:latest"
5+
)

0 commit comments

Comments
 (0)