Skip to content

Commit 73139f6

Browse files
oliviassssjohngmyers
authored andcommitted
remove unnecessary cleanup in prow script (kubernetes-sigs#3387)
* remove unnecessary cleanup in prow script * add test id for controller policy name * move delete CRD step into the cleanup func
1 parent 0cc7aa0 commit 73139f6

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

scripts/run-e2e-test.sh

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,30 @@ function toggle_windows_scheduling(){
2929
TEST_ID=$(date +%s)
3030
echo "TEST_ID: $TEST_ID"
3131
ROLE_NAME="aws-load-balancer-controller-$TEST_ID"
32+
POLICY_NAME="AWSLoadBalancerControllerIAMPolicy-$TEST_ID"
3233

3334
function cleanUp(){
34-
# Need to recreae aws-load-balancer controller if we are updating SA
35-
echo "delete aws-load-balancer-controller if exists"
36-
helm delete aws-load-balancer-controller -n kube-system --timeout=10m || true
35+
echo "delete serviceaccount"
36+
kubectl delete serviceaccount aws-load-balancer-controller -n kube-system --timeout 60s || true
3737

38-
echo "delete service account if exists"
39-
kubectl delete serviceaccount aws-load-balancer-controller -n kube-system --timeout 10m || true
40-
41-
# IAM role and polcies are AWS Account specific, so need to clean them up if any from previous run
42-
echo "detach IAM policy if it exists"
43-
aws iam detach-role-policy --role-name $ROLE_NAME --policy-arn arn:${AWS_PARTITION}:iam::$ACCOUNT_ID:policy/AWSLoadBalancerControllerIAMPolicy || true
38+
echo "detach IAM policy"
39+
aws iam detach-role-policy --role-name $ROLE_NAME --policy-arn arn:${AWS_PARTITION}:iam::$ACCOUNT_ID:policy/$POLICY_NAME || true
4440

4541
# wait for 10 sec to complete detaching of IAM policy
4642
sleep 10
4743

48-
echo "delete $ROLE_NAME if it exists"
44+
echo "delete $ROLE_NAME"
4945
aws iam delete-role --role-name $ROLE_NAME || true
5046

51-
# Need to do this as last step
52-
echo "delete AWSLoadBalancerControllerIAMPolicy if it exists"
53-
aws iam delete-policy --policy-arn arn:${AWS_PARTITION}:iam::$ACCOUNT_ID:policy/AWSLoadBalancerControllerIAMPolicy || true
47+
echo "delete $POLICY_NAME"
48+
aws iam delete-policy --policy-arn arn:${AWS_PARTITION}:iam::$ACCOUNT_ID:policy/$POLICY_NAME || true
49+
50+
echo "Delete CRDs if exists"
51+
if [[ $ADC_REGIONS == *"$REGION"* ]]; then
52+
kubectl delete -k "../helm/aws-load-balancer-controller/crds" --timeout=30s || true
53+
else
54+
kubectl delete -k "github.com/aws/eks-charts/stable/aws-load-balancer-controller//crds?ref=master" --timeout=30s || true
55+
fi
5456
}
5557

5658
echo "cordon off windows nodes"
@@ -104,19 +106,16 @@ cat <<EOF > trust.json
104106
}
105107
EOF
106108

107-
echo "cleanup any stale resources from previous run"
108-
cleanUp
109-
110109
echo "create Role with above policy document"
111110
aws iam create-role --role-name $ROLE_NAME --assume-role-policy-document file://trust.json --description "IAM Role to be used by aws-load-balancer-controller SA" || true
112111

113112
echo "creating AWSLoadbalancerController IAM Policy"
114113
aws iam create-policy \
115-
--policy-name AWSLoadBalancerControllerIAMPolicy \
114+
--policy-name $POLICY_NAME \
116115
--policy-document file://"$SCRIPT_DIR"/../docs/install/${IAM_POLCIY_FILE} || true
117116

118117
echo "attaching AWSLoadBalancerController IAM Policy to $ROLE_NAME"
119-
aws iam attach-role-policy --policy-arn arn:${AWS_PARTITION}:iam::$ACCOUNT_ID:policy/AWSLoadBalancerControllerIAMPolicy --role-name $ROLE_NAME || true
118+
aws iam attach-role-policy --policy-arn arn:${AWS_PARTITION}:iam::$ACCOUNT_ID:policy/$POLICY_NAME --role-name $ROLE_NAME || true
120119

121120
echo "create service account"
122121
kubectl create serviceaccount aws-load-balancer-controller -n kube-system || true
@@ -217,15 +216,15 @@ kubectl logs -l app.kubernetes.io/name=aws-load-balancer-controller --container
217216
echo "Uncordon windows nodes"
218217
toggle_windows_scheduling "uncordon"
219218

220-
echo "clean up resources from current run"
221-
cleanUp
222-
223-
echo "Delete CRDs if exists"
219+
echo "uninstalling aws load balancer controller"
224220
if [[ $ADC_REGIONS == *"$REGION"* ]]; then
225-
kubectl delete -k "../helm/aws-load-balancer-controller/crds" --timeout=30m || true
221+
kubectl delete -f $controller_yaml --timeout=60s || true
222+
kubectl delete -f $cert_manager_yaml --timeout=60s || true
226223
else
227-
kubectl delete -k "github.com/aws/eks-charts/stable/aws-load-balancer-controller//crds?ref=master" --timeout=30m || true
224+
helm uninstall aws-load-balancer-controller -n kube-system --timeout=60s || true
228225
fi
226+
echo "clean up resources from current run"
227+
cleanUp
229228

230229
if [[ "$TEST_RESULT" == fail ]]; then
231230
echo "e2e tests failed."

0 commit comments

Comments
 (0)