@@ -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.
125146function internalContainerRegistryCheck() {
@@ -1162,29 +1183,49 @@ CLEANUP_WARNINGS="false"
11621183if [ ${# DELETE_INGRESS[@]} -ne 0 ]; then
11631184 CLEANUP_WARNINGS=" true"
11641185 (( ++ BUILD_WARNING_COUNT))
1165- echo " >> Lagoon detected routes that have been removed from the .lagoon.yml or Lagoon API"
1166- echo " > If you need these routes, you should update your .lagoon.yml file and make sure the routes exist."
1167- if [ " $( featureFlag CLEANUP_REMOVED_LAGOON_ROUTES) " != enabled ]; then
1168- echo " > If you no longer need these routes, you can instruct Lagoon to remove it from the environment by setting the following variable"
1169- echo " > 'LAGOON_FEATURE_FLAG_CLEANUP_REMOVED_LAGOON_ROUTES=enabled' as a GLOBAL scoped variable to this environment or project"
1170- echo " > You should remove this variable after the deployment has been completed, otherwise future route removals will happen automatically"
1171- else
1172- echo " > 'LAGOON_FEATURE_FLAG_CLEANUP_REMOVED_LAGOON_ROUTES=enabled' is configured and the following routes will be removed."
1173- echo " > You should remove this variable if you don't want routes to be removed automatically"
1174- fi
1175- 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"
1176- for DI in ${DELETE_INGRESS[@]}
1177- do
1178- if [ " $( featureFlag CLEANUP_REMOVED_LAGOON_ROUTES) " = enabled ]; then
1186+ API_ROUTES_CLEANUP=$( internalSystemEnvVarCheck LAGOON_API_ROUTES_CLEANUP false)
1187+ if [ " $API_ROUTES_CLEANUP " == true ]; then
1188+ # to ensure consistency with the api, enforce route cleanup
1189+ # if it isn't in the api, and isn't in the .lagoon.yml file, then it shouldn't exist.
1190+ echo " >> Lagoon detected routes that have been removed from the .lagoon.yml or Lagoon API"
1191+ echo " > As this project has routes managed in the API, these routes have been cleaned up."
1192+ echo " > If you need these routes, you should add them to the API."
1193+ for DI in ${DELETE_INGRESS[@]}
1194+ do
11791195 if kubectl -n ${NAMESPACE} get ingress ${DI} & > /dev/null; then
11801196 echo " >> Removing ingress ${DI} "
11811197 cleanupCertificates " ${DI} " " false"
11821198 kubectl -n ${NAMESPACE} delete ingress ${DI}
11831199 fi
1200+ done
1201+ else
1202+ # no routes in the api we will just continue to warn
1203+ # since users may not have realised they removed a route from the .lagoon.yml
1204+ # usually this is because of a bad merge or something, and people generally aren't reading warnings anyway
1205+ echo " >> Lagoon detected routes that have been removed from the .lagoon.yml or Lagoon API"
1206+ echo " > If you need these routes, you should update your .lagoon.yml file and make sure the routes exist."
1207+ if [ " $( featureFlag CLEANUP_REMOVED_LAGOON_ROUTES) " != enabled ]; then
1208+ echo " > If you no longer need these routes, you can instruct Lagoon to remove it from the environment by setting the following variable"
1209+ echo " > 'LAGOON_FEATURE_FLAG_CLEANUP_REMOVED_LAGOON_ROUTES=enabled' as a GLOBAL scoped variable to this environment or project"
1210+ echo " > You should remove this variable after the deployment has been completed, otherwise future route removals will happen automatically"
11841211 else
1185- echo " > The route '${DI} ' would be removed"
1212+ echo " > 'LAGOON_FEATURE_FLAG_CLEANUP_REMOVED_LAGOON_ROUTES=enabled' is configured and the following routes will be removed."
1213+ echo " > You should remove this variable if you don't want routes to be removed automatically"
11861214 fi
1187- done
1215+ 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"
1216+ for DI in ${DELETE_INGRESS[@]}
1217+ do
1218+ if [ " $( featureFlag CLEANUP_REMOVED_LAGOON_ROUTES) " = enabled ]; then
1219+ if kubectl -n ${NAMESPACE} get ingress ${DI} & > /dev/null; then
1220+ echo " >> Removing ingress ${DI} "
1221+ cleanupCertificates " ${DI} " " false"
1222+ kubectl -n ${NAMESPACE} delete ingress ${DI}
1223+ fi
1224+ else
1225+ echo " > The route '${DI} ' would be removed"
1226+ fi
1227+ done
1228+ fi
11881229else
11891230 echo " No route cleanup required"
11901231fi
0 commit comments