Skip to content

Commit ff765ce

Browse files
committed
Fix: remove all the AmbassadorInstallations
* Cleanups were not working because we were not rermoving all the AmbassadorInstallations. * Simplify some code in the tests. Signed-off-by: Alvaro Saurin <[email protected]>
1 parent 979a804 commit ff765ce

File tree

4 files changed

+88
-68
lines changed

4 files changed

+88
-68
lines changed

.travis.yml

+47-26
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,17 @@ install:
2828

2929
jobs:
3030
include:
31+
#####################################################
3132
# stage 1: lint, build and unit-tests
33+
#####################################################
3234
- stage: Build, lint and unit tests
3335
name: "Build, lint and unit tests"
3436
script: make ci/check-format-gen ci/lint ci/build ci/test
3537

38+
#####################################################
3639
# stage 2: end-to-end tests in multiple clouds
40+
#####################################################
41+
3742
# see the ci/infra/providers/CREDENTIALS.md for details on the credentials
3843
- stage: End-to-end tests
3944
name: "e2e tests in Google Cloud (GKE)"
@@ -55,22 +60,21 @@ jobs:
5560
env: CLUSTER_PROVIDER="k3d"
5661
script: make ci/cluster-setup ci/e2e
5762

63+
#####################################################
5864
# stage 3: publish artifacts
65+
#####################################################
5966
- stage: Publish artifacts
67+
name: "Publish artifacts to GitHub"
6068
if: tag IS present
61-
name: "Publish artifacts"
6269
env:
6370
- AMB_OPER_TAG="$TRAVIS_TAG"
64-
65-
# generate all the artifacts that will be published by the "deploy"
66-
before_deploy:
67-
- make ci/release
68-
- make ci/cluster-setup
69-
70-
# ... and then publish those artifacts, docs, push images, etc.
7171
deploy:
72+
- provider: script
73+
on:
74+
all_branches: true
75+
script: make ci/release
7276
# publish YAMLs to GitHub releases
73-
# make ci/release should have left everything in build/artifacts/*
77+
# `make ci/release` should have left everything in build/artifacts/*
7478
- provider: releases
7579
on:
7680
all_branches: true
@@ -80,46 +84,63 @@ jobs:
8084
file: build/artifacts/*
8185
skip_cleanup: true
8286

87+
- name: "Publish image to Docker.io"
88+
if: tag IS present
89+
env:
90+
- AMB_OPER_TAG="$TRAVIS_TAG"
91+
- REL_REGISTRY="docker.io/datawire"
92+
deploy:
8393
# publish images to Docker.io
8494
# NOTE: make sure DOCKER_USERNAME/DOCKER_PASSWORD have values for a bot
8595
- provider: script
8696
on:
8797
all_branches: true
88-
env:
89-
- REL_REGISTRY="docker.io/datawire"
90-
script: make ci/publish-image
91-
skip_cleanup: true
98+
script: make ci/release ci/publish-image
9299

100+
- name: "Publish images to Quay.io"
101+
if: tag IS present
102+
env:
103+
- AMB_OPER_TAG="$TRAVIS_TAG"
104+
- DOCKER_USERNAME="$QUAY_USERNAME"
105+
- DOCKER_PASSWORD="$QUAY_PASSWORD"
106+
- REL_REGISTRY="quay.io/datawire"
107+
deploy:
93108
# publish images to Quay.io
94109
# NOTE: make sure DOCKER_USERNAME/DOCKER_PASSWORD have values for a bot
95110
# (from https://quay.io/repository/datawire/ambassador-operator?tab=settings)
96111
- provider: script
97112
on:
98113
all_branches: true
99-
env:
100-
- DOCKER_USERNAME="$QUAY_USERNAME"
101-
- DOCKER_PASSWORD="$QUAY_PASSWORD"
102-
- REL_REGISTRY="quay.io/datawire"
103-
script: make ci/publish-image
104-
skip_cleanup: true
114+
script: make ci/release ci/publish-image
105115

106-
# publish the image to Azure
116+
- name: "Publish images to Azure ACR"
117+
if: tag IS present
118+
env:
119+
- AMB_OPER_TAG="$TRAVIS_TAG"
120+
- CLUSTER_REGISTRY="datawire"
121+
- CLUSTER_PROVIDER="azure"
122+
- AZ_RES_GRP="DefaultResourceGroup-EUS"
123+
deploy:
107124
- provider: script
108125
on:
109126
all_branches: true
110127
env:
111-
- CLUSTER_REGISTRY="datawire"
112-
- CLUSTER_PROVIDER="azure"
113-
- AZ_RES_GRP="DefaultResourceGroup-EUS"
114-
script: make ci/publish-image-cloud/azure
115-
skip_cleanup: true
128+
script: make ci/cluster-setup ci/release ci/publish-image-cloud/azure
116129

130+
- name: "Publish Helm Chart"
131+
if: tag IS present
132+
env:
133+
- AMB_OPER_TAG="$TRAVIS_TAG"
134+
- DOCKER_USERNAME="$QUAY_USERNAME"
135+
- DOCKER_PASSWORD="$QUAY_PASSWORD"
136+
- REL_REGISTRY="quay.io/datawire"
137+
deploy:
117138
# publish helm chart
118139
# NOTE: needs AWS_ACCESS_KEY_ID, AWS_BUCKET and AWS_SECRET_ACCESS_KEY (from keybase)
119140
- provider: script
120141
on:
121142
all_branches: true
122-
script: make ci/publish-chart
143+
script: make ci/cluster-setup ci/publish-chart
123144

124145
after_success:
125146
- make ci/after-success

ci/common.sh

+39-40
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ wait_until() {
111111
local start_time=$(timestamp)
112112
info "Waiting for $@"
113113
until timeout_from $start_time || eval "$@"; do
114-
info "... still waiting"
114+
info "... still waiting for condition"
115115
sleep 1
116116
done
117117
! timeout_from $start_time
@@ -267,42 +267,30 @@ get_amb_addr() {
267267
fi
268268
}
269269

270+
check_amb_has_addr() {
271+
test -n "$(get_amb_addr $@)"
272+
}
273+
270274
# wait_amb_addr <KUBECTL_ARGS...>
271275
# wait untils Ambassador has an address
272276
wait_amb_addr() {
273-
i=0
274-
timeout=$DEF_WAIT_TIMEOUT
275-
until [ -n "$(get_amb_addr $@)" ] || [ $i -ge $timeout ]; do
276-
info "waiting for Ambassador to have an IP ($i secs elapsed)"
277-
i=$((i + 1))
278-
sleep 1
279-
done
280-
281-
if [ $i -ge $timeout ]; then
277+
wait_until check_amb_has_addr $@ || {
282278
warn "Timeout waiting for Ambassador's IP. Current services:"
283279
kubectl get services $@
284-
warn "Ambassador did not get an IP after $timeout seconds"
280+
warn "Ambassador IP address: $(get_amb_addr $@)"
285281
return 1
286-
fi
282+
}
287283
}
288284

289285
# wait_not_amb_addr <KUBECTL_ARGS...>
290286
# wait untils Ambassador does not have an address
291287
wait_not_amb_addr() {
292-
i=0
293-
timeout=$DEF_WAIT_TIMEOUT
294-
until [ -z "$(get_amb_addr $@)" ] || [ $i -ge $timeout ]; do
295-
info "waiting for Ambassador to have an IP ($i secs elapsed)"
296-
i=$((i + 1))
297-
sleep 1
298-
done
299-
300-
if [ $i -ge $timeout ]; then
301-
warn "Timeout waiting for Ambassador not not have an IP. Current services:"
288+
wait_until "! check_amb_has_addr $@" || {
289+
warn "Timeout waiting for Ambassador to NOT have an IP. Current services:"
302290
kubectl get services $@
303-
warn "Ambassador had an IP after $timeout seconds"
291+
warn "Ambassador IP address: $(get_amb_addr $@)"
304292
return 1
305-
fi
293+
}
306294
}
307295

308296
# kubectl_apply_host
@@ -989,12 +977,15 @@ kube_check_resource_empty() {
989977
# amb_inst_delete <KUBECTL_ARGS...>
990978
# delete an `AmbassadorInstallation`
991979
amb_inst_delete() {
992-
info "Removing the AmbassadorInstallation"
993-
kubectl delete $@ --wait=true --ignore-not-found=true --timeout=60s \
994-
ambassadorinstallations "${AMB_INSTALLATION_NAME}" ||
995-
return 1
996-
wait_missing "$@ ambassadorinstallations ${AMB_INSTALLATION_NAME}" || return 1
997-
passed "... AmbassadorInstallation removed."
980+
lst=$(kubectl get $@ ambassadorinstallations --no-headers -o custom-columns=":metadata.name" 2>/dev/null)
981+
info "Removing all the AmbassadorInstallations: $lst"
982+
for k in $lst; do
983+
kubectl delete $KUBECTL_DELETE_ARGS $@ ambassadorinstallations "$k" || return 1
984+
wait_missing "$@ ambassadorinstallations $k" || return 1
985+
passed "... AmbassadorInstallation $k removed."
986+
done
987+
info "Current list of AmbassadorInstallations: " && kubectl get $@ ambassadorinstallations 2>/dev/null
988+
return 0
998989
}
999990

1000991
amb_inst_describe() {
@@ -1038,21 +1029,28 @@ oper_uninstall() {
10381029

10391030
amb_inst_delete -n "$namespace" || {
10401031
oper_logs_dump -n "$namespace"
1041-
abort "could not remove AmbassadorInstallation in namespace $namespace"
1032+
abort "could not remove AmbassadorInstallations in namespace $namespace"
10421033
}
1043-
sleep 5
10441034

1045-
info "Removing the operator"
1035+
info "Removing the operator..."
10461036
cat_setting_image "$TOP_DIR/deploy/operator.yaml" | kubectl delete $KUBECTL_DELETE_ARGS -n "$namespace" -f -
1047-
kubectl delete -n "$namespace" $KUBECTL_DELETE_ARGS -f "$TOP_DIR/deploy/role_binding.yaml"
1048-
kubectl delete -n "$namespace" $KUBECTL_DELETE_ARGS -f "$TOP_DIR/deploy/role.yaml"
1049-
kubectl delete -n "$namespace" $KUBECTL_DELETE_ARGS -f "$TOP_DIR/deploy/service_account.yaml"
1050-
kubectl delete -n "$namespace" $KUBECTL_DELETE_ARGS -f $CRDS
1037+
for f in $CRDS "$TOP_DIR/deploy/role_binding.yaml" "$TOP_DIR/deploy/role.yaml" "$TOP_DIR/deploy/service_account.yaml"; do
1038+
info "... removing $f"
1039+
kubectl delete -n "$namespace" $KUBECTL_DELETE_ARGS -f $f || {
1040+
oper_logs_dump -n "$namespace"
1041+
abort "could not delete $f"
1042+
}
1043+
done
10511044

1045+
# note: it is important have deleted all the AmbassadorInstallations at this point,
1046+
# otherwise the removal of the namespace will fail
10521047
info "Removing namespace $namespace..."
1053-
kubectl delete namespace $KUBECTL_DELETE_ARGS "$namespace" &&
1054-
wait_namespace_missing "$namespace" || abort "namespace $namespace still present"
1055-
1048+
kubectl delete namespace $KUBECTL_DELETE_ARGS "$namespace" || abort "could not delete namespace $namespace"
1049+
wait_namespace_missing "$namespace" || {
1050+
oper_logs_dump -n "$namespace"
1051+
kubectl get all -n "$namespace"
1052+
abort "namespace $namespace still present"
1053+
}
10561054
passed "... namespace $namespace removed."
10571055
}
10581056

@@ -1120,6 +1118,7 @@ oper_install_helm() {
11201118
}
11211119

11221120
oper_logs_dump() {
1121+
kubectl logs $@ deployment/"$AMB_OPER_DEPLOY" --previous
11231122
kubectl logs $@ deployment/"$AMB_OPER_DEPLOY"
11241123
}
11251124

tests/e2e/tests/01-install-uninstall.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ amb_inst_check_success -n "$TEST_NAMESPACE" || {
113113
}
114114

115115
info "Checking we can remove Ambassador when the AmbassadorInstallation is deleted"
116-
amb_inst_delete -n "$TEST_NAMESPACE" || failed "could not remove AmbassadorInstallation"
116+
amb_inst_delete -n "$TEST_NAMESPACE" || failed "could not remove AmbassadorInstallations"
117117

118118
sleep 5
119119

tests/e2e/tests/04-helm-install-uninstall.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ amb_inst_check_success -n "$TEST_NAMESPACE" || failed "Success not found in Amba
7777
}
7878

7979
info "Checking we can remove Ambassador when the AmbassadorInstallation is deleted"
80-
amb_inst_delete -n "$TEST_NAMESPACE" || failed "could not remove AmbassadorInstallation"
80+
amb_inst_delete -n "$TEST_NAMESPACE" || failed "could not remove the AmbassadorInstallations"
8181

8282
sleep 5
8383

0 commit comments

Comments
 (0)