Skip to content

Commit b866aab

Browse files
committed
refactor: always remove routes if there are any api defined routes
1 parent 200002e commit b866aab

File tree

1 file changed

+57
-16
lines changed

1 file changed

+57
-16
lines changed

legacy/build-deploy-docker-compose.sh

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,27 @@ function buildEnvVarCheck() {
120120
echo "$2"
121121
}
122122

123+
# Checks for a internal_system scoped env var from Lagoon API. All env vars
124+
# are consolidated into the environment, project env-vars are only checked for
125+
# backwards compatibility.
126+
function internalSystemEnvVarCheck() {
127+
# check for argument
128+
[ "$1" ] || return
129+
130+
local flagVar
131+
132+
flagVar="$1"
133+
# check Lagoon environment variables
134+
flagValue=$(jq -r '.[] | select(.scope == "internal_system") | select(.name == "'"$flagVar"'") | .value' <<< "$LAGOON_ENVIRONMENT_VARIABLES")
135+
[ "$flagValue" ] && echo "$flagValue" && return
136+
# check Lagoon project variables
137+
flagValue=$(jq -r '.[] | select(.scope == "internal_system") | select(.name == "'"$flagVar"'") | .value' <<< "$LAGOON_PROJECT_VARIABLES")
138+
[ "$flagValue" ] && echo "$flagValue" && return
139+
140+
echo "$2"
141+
}
142+
143+
123144
# Checks for a internal_container_registry scoped env var. These are set in
124145
# lagoon-remote.
125146
function internalContainerRegistryCheck() {
@@ -1182,29 +1203,49 @@ CLEANUP_WARNINGS="false"
11821203
if [ ${#DELETE_INGRESS[@]} -ne 0 ]; then
11831204
CLEANUP_WARNINGS="true"
11841205
((++BUILD_WARNING_COUNT))
1185-
echo ">> Lagoon detected routes that have been removed from the .lagoon.yml or Lagoon API"
1186-
echo "> If you need these routes, you should update your .lagoon.yml file and make sure the routes exist."
1187-
if [ "$(featureFlag CLEANUP_REMOVED_LAGOON_ROUTES)" != enabled ]; then
1188-
echo "> If you no longer need these routes, you can instruct Lagoon to remove it from the environment by setting the following variable"
1189-
echo "> 'LAGOON_FEATURE_FLAG_CLEANUP_REMOVED_LAGOON_ROUTES=enabled' as a GLOBAL scoped variable to this environment or project"
1190-
echo "> You should remove this variable after the deployment has been completed, otherwise future route removals will happen automatically"
1191-
else
1192-
echo "> 'LAGOON_FEATURE_FLAG_CLEANUP_REMOVED_LAGOON_ROUTES=enabled' is configured and the following routes will be removed."
1193-
echo "> You should remove this variable if you don't want routes to be removed automatically"
1194-
fi
1195-
echo "> Future releases of Lagoon may remove routes automatically, you should ensure that your routes are up always up to date if you see this warning"
1196-
for DI in ${DELETE_INGRESS[@]}
1197-
do
1198-
if [ "$(featureFlag CLEANUP_REMOVED_LAGOON_ROUTES)" = enabled ]; then
1206+
API_ROUTES_CLEANUP=$(internalSystemEnvVarCheck LAGOON_API_ROUTES_CLEANUP false)
1207+
if [ "$API_ROUTES_CLEANUP" == true ]; then
1208+
# to ensure consistency with the api, enforce route cleanup
1209+
# if it isn't in the api, and isn't in the .lagoon.yml file, then it shouldn't exist.
1210+
echo ">> Lagoon detected routes that have been removed from the .lagoon.yml or Lagoon API"
1211+
echo "> As this project has routes managed in the API, these routes have been cleaned up."
1212+
echo "> If you need these routes, you should add them to the API."
1213+
for DI in ${DELETE_INGRESS[@]}
1214+
do
11991215
if kubectl -n ${NAMESPACE} get ingress ${DI} &> /dev/null; then
12001216
echo ">> Removing ingress ${DI}"
12011217
cleanupCertificates "${DI}" "false"
12021218
kubectl -n ${NAMESPACE} delete ingress ${DI}
12031219
fi
1220+
done
1221+
else
1222+
# no routes in the api we will just continue to warn
1223+
# since users may not have realised they removed a route from the .lagoon.yml
1224+
# usually this is because of a bad merge or something, and people generally aren't reading warnings anyway
1225+
echo ">> Lagoon detected routes that have been removed from the .lagoon.yml or Lagoon API"
1226+
echo "> If you need these routes, you should update your .lagoon.yml file and make sure the routes exist."
1227+
if [ "$(featureFlag CLEANUP_REMOVED_LAGOON_ROUTES)" != enabled ]; then
1228+
echo "> If you no longer need these routes, you can instruct Lagoon to remove it from the environment by setting the following variable"
1229+
echo "> 'LAGOON_FEATURE_FLAG_CLEANUP_REMOVED_LAGOON_ROUTES=enabled' as a GLOBAL scoped variable to this environment or project"
1230+
echo "> You should remove this variable after the deployment has been completed, otherwise future route removals will happen automatically"
12041231
else
1205-
echo "> The route '${DI}' would be removed"
1232+
echo "> 'LAGOON_FEATURE_FLAG_CLEANUP_REMOVED_LAGOON_ROUTES=enabled' is configured and the following routes will be removed."
1233+
echo "> You should remove this variable if you don't want routes to be removed automatically"
12061234
fi
1207-
done
1235+
echo "> Future releases of Lagoon may remove routes automatically, you should ensure that your routes are up always up to date if you see this warning"
1236+
for DI in ${DELETE_INGRESS[@]}
1237+
do
1238+
if [ "$(featureFlag CLEANUP_REMOVED_LAGOON_ROUTES)" = enabled ]; then
1239+
if kubectl -n ${NAMESPACE} get ingress ${DI} &> /dev/null; then
1240+
echo ">> Removing ingress ${DI}"
1241+
cleanupCertificates "${DI}" "false"
1242+
kubectl -n ${NAMESPACE} delete ingress ${DI}
1243+
fi
1244+
else
1245+
echo "> The route '${DI}' would be removed"
1246+
fi
1247+
done
1248+
fi
12081249
else
12091250
echo "No route cleanup required"
12101251
fi

0 commit comments

Comments
 (0)