Skip to content

Commit

Permalink
Merge pull request #2582 from amazeeio/2379-helm-release-53-limit
Browse files Browse the repository at this point in the history
trim routes that are longer than 53 for usage in helm release name
  • Loading branch information
Schnitzel committed Mar 25, 2021
2 parents 3832d14 + e2d4535 commit 760e5ce
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 9 deletions.
56 changes: 48 additions & 8 deletions images/kubectl-build-deploy-dind/build-deploy-docker-compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -847,9 +847,19 @@ if [ "${ENVIRONMENT_TYPE}" == "production" ]; then
touch /kubectl-build-deploy/${ROUTE_DOMAIN}-values.yaml
echo "$ROUTE_ANNOTATIONS" | yq p - annotations > /kubectl-build-deploy/${ROUTE_DOMAIN}-values.yaml

# ${ROUTE_DOMAIN} is used as a helm release name which be max 53 characters long.
# So we need some logic to make sure it's always max 53 characters
if [[ ${#ROUTE_DOMAIN} -gt 53 ]] ; then
# Trim the route domain to 47 characters, and add an 5 character hash of the domain at the end
# this gives a total of 53 characters
INGRESS_NAME=${ROUTE_DOMAIN:0:47}-$(echo ${ROUTE_DOMAIN} | md5sum | cut -f 1 -d " " | cut -c 1-5)
else
INGRESS_NAME=${ROUTE_DOMAIN}
fi

# The very first found route is set as MAIN_CUSTOM_ROUTE
if [ -z "${MAIN_CUSTOM_ROUTE+x}" ]; then
MAIN_CUSTOM_ROUTE=$ROUTE_DOMAIN
MAIN_CUSTOM_ROUTE=$INGRESS_NAME

# if we are in production we enabled monitoring for the main custom route
if [ "${ENVIRONMENT_TYPE}" == "production" ]; then
Expand All @@ -862,7 +872,7 @@ if [ "${ENVIRONMENT_TYPE}" == "production" ]; then

cat /kubectl-build-deploy/${ROUTE_DOMAIN}-values.yaml

helm template ${ROUTE_DOMAIN} \
helm template ${INGRESS_NAME} \
/kubectl-build-deploy/helmcharts/custom-ingress \
--set host="${ROUTE_DOMAIN}" \
--set service="${ROUTE_SERVICE}" \
Expand Down Expand Up @@ -957,9 +967,19 @@ if [ "${ENVIRONMENT_TYPE}" == "production" ]; then
touch /kubectl-build-deploy/${ROUTE_DOMAIN}-values.yaml
echo "$ROUTE_ANNOTATIONS" | yq p - annotations > /kubectl-build-deploy/${ROUTE_DOMAIN}-values.yaml

# ${ROUTE_DOMAIN} is used as a helm release name which be max 53 characters long.
# So we need some logic to make sure it's always max 53 characters
if [[ ${#ROUTE_DOMAIN} -gt 53 ]] ; then
# Trim the route domain to 47 characters, and add an 5 character hash of the domain at the end
# this gives a total of 53 characters
INGRESS_NAME=${ROUTE_DOMAIN:0:47}-$(echo ${ROUTE_DOMAIN} | md5sum | cut -f 1 -d " " | cut -c 1-5)
else
INGRESS_NAME=${ROUTE_DOMAIN}
fi

# The very first found route is set as MAIN_CUSTOM_ROUTE
if [ -z "${MAIN_CUSTOM_ROUTE+x}" ]; then
MAIN_CUSTOM_ROUTE=$ROUTE_DOMAIN
MAIN_CUSTOM_ROUTE=$INGRESS_NAME

# if we are in production we enabled monitoring for the main custom route
if [ "${ENVIRONMENT_TYPE}" == "production" ]; then
Expand All @@ -972,7 +992,7 @@ if [ "${ENVIRONMENT_TYPE}" == "production" ]; then

cat /kubectl-build-deploy/${ROUTE_DOMAIN}-values.yaml

helm template ${ROUTE_DOMAIN} \
helm template ${INGRESS_NAME} \
/kubectl-build-deploy/helmcharts/custom-ingress \
--set host="${ROUTE_DOMAIN}" \
--set service="${ROUTE_SERVICE}" \
Expand Down Expand Up @@ -1069,12 +1089,22 @@ if [ -n "$(cat .lagoon.yml | shyaml keys ${PROJECT}.environments.${BRANCH//./\\.
ROUTE_FASTLY_SERVICE_WATCH=true
fi

# ${ROUTE_DOMAIN} is used as a helm release name which be max 53 characters long.
# So we need some logic to make sure it's always max 53 characters
if [[ ${#ROUTE_DOMAIN} -gt 53 ]] ; then
# Trim the route domain to 47 characters, and add an 5 character hash of the domain at the end
# this gives a total of 53 characters
INGRESS_NAME=${ROUTE_DOMAIN:0:47}-$(echo ${ROUTE_DOMAIN} | md5sum | cut -f 1 -d " " | cut -c 1-5)
else
INGRESS_NAME=${ROUTE_DOMAIN}
fi

touch /kubectl-build-deploy/${ROUTE_DOMAIN}-values.yaml
echo "$ROUTE_ANNOTATIONS" | yq p - annotations > /kubectl-build-deploy/${ROUTE_DOMAIN}-values.yaml

# The very first found route is set as MAIN_CUSTOM_ROUTE
if [ -z "${MAIN_CUSTOM_ROUTE+x}" ]; then
MAIN_CUSTOM_ROUTE=$ROUTE_DOMAIN
MAIN_CUSTOM_ROUTE=$INGRESS_NAME

# if we are in production we enabled monitoring for the main custom route
if [ "${ENVIRONMENT_TYPE}" == "production" ]; then
Expand All @@ -1087,7 +1117,7 @@ if [ -n "$(cat .lagoon.yml | shyaml keys ${PROJECT}.environments.${BRANCH//./\\.

cat /kubectl-build-deploy/${ROUTE_DOMAIN}-values.yaml

helm template ${ROUTE_DOMAIN} \
helm template ${INGRESS_NAME} \
/kubectl-build-deploy/helmcharts/custom-ingress \
--set host="${ROUTE_DOMAIN}" \
--set service="${ROUTE_SERVICE}" \
Expand Down Expand Up @@ -1179,9 +1209,19 @@ else
touch /kubectl-build-deploy/${ROUTE_DOMAIN}-values.yaml
echo "$ROUTE_ANNOTATIONS" | yq p - annotations > /kubectl-build-deploy/${ROUTE_DOMAIN}-values.yaml

# ${ROUTE_DOMAIN} is used as a helm release name which be max 53 characters long.
# So we need some logic to make sure it's always max 53 characters
if [[ ${#ROUTE_DOMAIN} -gt 53 ]] ; then
# Trim the route domain to 47 characters, and add an 5 character hash of the domain at the end
# this gives a total of 53 characters
INGRESS_NAME=${ROUTE_DOMAIN:0:47}-$(echo ${ROUTE_DOMAIN} | md5sum | cut -f 1 -d " " | cut -c 1-5)
else
INGRESS_NAME=${ROUTE_DOMAIN}
fi

# The very first found route is set as MAIN_CUSTOM_ROUTE
if [ -z "${MAIN_CUSTOM_ROUTE+x}" ]; then
MAIN_CUSTOM_ROUTE=$ROUTE_DOMAIN
MAIN_CUSTOM_ROUTE=$INGRESS_NAME

# if we are in production we enabled monitoring for the main custom route
if [ "${ENVIRONMENT_TYPE}" == "production" ]; then
Expand All @@ -1194,7 +1234,7 @@ else

cat /kubectl-build-deploy/${ROUTE_DOMAIN}-values.yaml

helm template ${ROUTE_DOMAIN} \
helm template ${INGRESS_NAME} \
/kubectl-build-deploy/helmcharts/custom-ingress \
--set host="${ROUTE_DOMAIN}" \
--set service="${ROUTE_SERVICE}" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ lagoon.sh/prNumber: {{ .Values.prNumber | quote }}
lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }}
lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }}
{{- end }}
{{- end -}}
{{- end -}}

0 comments on commit 760e5ce

Please sign in to comment.