Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fastly configuration to autogenerated routes if enabled #2883

Merged
merged 3 commits into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 100 additions & 46 deletions images/kubectl-build-deploy-dind/build-deploy-docker-compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ fi


##############################################
### CREATE OPENSHIFT SERVICES, ROUTES and SERVICEBROKERS
### CONFIGURE SERVICES, AUTOGENERATED ROUTES AND DBAAS CONFIG
##############################################

YAML_FOLDER="/kubectl-build-deploy/lagoon/services-routes"
Expand Down Expand Up @@ -607,51 +607,6 @@ LAGOON_PR_NUMBER=${PR_NUMBER}\n\
" >> /kubectl-build-deploy/values.env
fi

for SERVICE_TYPES_ENTRY in "${SERVICE_TYPES[@]}"
do
echo "=== BEGIN route processing for service ${SERVICE_TYPES_ENTRY} ==="
IFS=':' read -ra SERVICE_TYPES_ENTRY_SPLIT <<< "$SERVICE_TYPES_ENTRY"

TEMPLATE_PARAMETERS=()

SERVICE_NAME=${SERVICE_TYPES_ENTRY_SPLIT[0]}
SERVICE_TYPE=${SERVICE_TYPES_ENTRY_SPLIT[1]}

touch /kubectl-build-deploy/${SERVICE_NAME}-values.yaml

HELM_SERVICE_TEMPLATE="templates/service.yaml"
if [ -f /kubectl-build-deploy/helmcharts/${SERVICE_TYPE}/$HELM_SERVICE_TEMPLATE ]; then
cat /kubectl-build-deploy/values.yaml
helm template ${SERVICE_NAME} /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} -s $HELM_SERVICE_TEMPLATE -f /kubectl-build-deploy/values.yaml "${HELM_ARGUMENTS[@]}" > $YAML_FOLDER/${SERVICE_NAME}.yaml
fi

if [ $ROUTES_AUTOGENERATE_ENABLED == "true" ]; then
HELM_INGRESS_TEMPLATE="templates/ingress.yaml"
if [ -f /kubectl-build-deploy/helmcharts/${SERVICE_TYPE}/$HELM_INGRESS_TEMPLATE ]; then

# The very first generated route is set as MAIN_GENERATED_ROUTE
if [ -z "${MAIN_GENERATED_ROUTE+x}" ]; then
MAIN_GENERATED_ROUTE=$SERVICE_NAME
fi

helm template ${SERVICE_NAME} /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} -s $HELM_INGRESS_TEMPLATE -f /kubectl-build-deploy/values.yaml "${HELM_ARGUMENTS[@]}" > $YAML_FOLDER/${SERVICE_NAME}.yaml
fi
fi

HELM_DBAAS_TEMPLATE="templates/dbaas.yaml"
if [ -f /kubectl-build-deploy/helmcharts/${SERVICE_TYPE}/$HELM_DBAAS_TEMPLATE ]; then
# Load the requested class and plan for this service
DBAAS_ENVIRONMENT="${MAP_SERVICE_NAME_TO_DBAAS_ENVIRONMENT["${SERVICE_NAME}"]}"
yq write -i -- /kubectl-build-deploy/${SERVICE_NAME}-values.yaml 'environment' $DBAAS_ENVIRONMENT
helm template ${SERVICE_NAME} /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} -s $HELM_DBAAS_TEMPLATE -f /kubectl-build-deploy/values.yaml -f /kubectl-build-deploy/${SERVICE_NAME}-values.yaml "${HELM_ARGUMENTS[@]}" > $YAML_FOLDER/${SERVICE_NAME}.yaml
DBAAS+=("${SERVICE_NAME}:${SERVICE_TYPE}")
fi

done

TEMPLATE_PARAMETERS=()


##############################################
### CUSTOM FASTLY API SECRETS .lagoon.yml
##############################################
Expand Down Expand Up @@ -782,6 +737,101 @@ if [ ! -z "$LAGOON_ENVIRONMENT_VARIABLES" ]; then
fi
set -x

##############################################
### CREATE SERVICES, AUTOGENERATED ROUTES AND DBAAS CONFIG
##############################################

for SERVICE_TYPES_ENTRY in "${SERVICE_TYPES[@]}"
do
echo "=== BEGIN route processing for service ${SERVICE_TYPES_ENTRY} ==="
IFS=':' read -ra SERVICE_TYPES_ENTRY_SPLIT <<< "$SERVICE_TYPES_ENTRY"

TEMPLATE_PARAMETERS=()

SERVICE_NAME=${SERVICE_TYPES_ENTRY_SPLIT[0]}
SERVICE_TYPE=${SERVICE_TYPES_ENTRY_SPLIT[1]}

touch /kubectl-build-deploy/${SERVICE_NAME}-values.yaml

HELM_SERVICE_TEMPLATE="templates/service.yaml"
if [ -f /kubectl-build-deploy/helmcharts/${SERVICE_TYPE}/$HELM_SERVICE_TEMPLATE ]; then
cat /kubectl-build-deploy/values.yaml
helm template ${SERVICE_NAME} /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} -s $HELM_SERVICE_TEMPLATE -f /kubectl-build-deploy/values.yaml "${HELM_ARGUMENTS[@]}" > $YAML_FOLDER/${SERVICE_NAME}.yaml
fi

if [ $ROUTES_AUTOGENERATE_ENABLED == "true" ]; then
HELM_INGRESS_TEMPLATE="templates/ingress.yaml"
if [ -f /kubectl-build-deploy/helmcharts/${SERVICE_TYPE}/$HELM_INGRESS_TEMPLATE ]; then

# The very first generated route is set as MAIN_GENERATED_ROUTE
if [ -z "${MAIN_GENERATED_ROUTE+x}" ]; then
MAIN_GENERATED_ROUTE=$SERVICE_NAME
fi


ROUTE_FASTLY_SERVICE_WATCH=false
# if the builddeploy controller is injecting a featureflag value, load it in
if [ -z $LAGOON_FASTLY_AUTOGENERATED_FEATURE_FLAG ]; then
LAGOON_FASTLY_AUTOGENERATED=$LAGOON_FASTLY_AUTOGENERATED_FEATURE_FLAG
fi
# if the lagoon api has an envvar override, use it instead
if [ ! -z "$LAGOON_PROJECT_VARIABLES" ]; then
LAGOON_FASTLY_AUTOGENERATED=($(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_FASTLY_AUTOGENERATED") | "\(.value)"'))
fi
if [ ! -z "$LAGOON_ENVIRONMENT_VARIABLES" ]; then
TEMP_LAGOON_FASTLY_AUTOGENERATED=($(echo $LAGOON_ENVIRONMENT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_FASTLY_AUTOGENERATED") | "\(.value)"'))
if [ ! -z $TEMP_LAGOON_FASTLY_AUTOGENERATED ]; then
LAGOON_FASTLY_AUTOGENERATED=$TEMP_LAGOON_FASTLY_AUTOGENERATED
fi
fi
# Create the fastly values required
FASTLY_ARGS=()
# if the feature is enabled, then do what is required to generated the labels/annotations etc
if [ ! -z $LAGOON_FASTLY_AUTOGENERATED ] && [ $LAGOON_FASTLY_AUTOGENERATED = 'enabled' ]; then
# work out if there are any lagoon api variable overrides for the annotations that are being added
. /kubectl-build-deploy/scripts/exec-fastly-annotations.sh
# if we get any other populated service id overrides in any of the steps in exec-fastly-annotations.sh
# make it available to the ingress creation here by overriding what may be defined in the lagoon.yml
# `LAGOON_FASTLY_SERVICE_ID` is created in the exec-fastly-annotations.sh script
if [ ! -z "$LAGOON_FASTLY_SERVICE_ID" ]; then
ROUTE_FASTLY_SERVICE_ID=$LAGOON_FASTLY_SERVICE_ID
ROUTE_FASTLY_SERVICE_WATCH=$LAGOON_FASTLY_SERVICE_WATCH
if [ ! -z $LAGOON_FASTLY_SERVICE_API_SECRET ]; then
ROUTE_FASTLY_SERVICE_API_SECRET=$LAGOON_FASTLY_SERVICE_API_SECRET
fi
fi
if [ ! -z "$ROUTE_FASTLY_SERVICE_ID" ]; then
FASTLY_ARGS+=(--set fastly.serviceId=${ROUTE_FASTLY_SERVICE_ID})
if [ ! -z "$ROUTE_FASTLY_SERVICE_API_SECRET" ]; then
if contains $FASTLY_API_SECRETS "${FASTLY_API_SECRET_PREFIX}${ROUTE_FASTLY_SERVICE_API_SECRET}"; then
FASTLY_ARGS+=(--set fastly.apiSecretName=${FASTLY_API_SECRET_PREFIX}${ROUTE_FASTLY_SERVICE_API_SECRET})
else
echo "$ROUTE_FASTLY_SERVICE_API_SECRET requested, but not found in .lagoon.yml file"; exit 1;
fi
fi
ROUTE_FASTLY_SERVICE_WATCH=true
fi
fi
# finally template the autogenerated route
helm template ${SERVICE_NAME} /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} \
-s $HELM_INGRESS_TEMPLATE \
"${FASTLY_ARGS[@]}" --set fastly.watch="${ROUTE_FASTLY_SERVICE_WATCH}" \
-f /kubectl-build-deploy/values.yaml "${HELM_ARGUMENTS[@]}" > $YAML_FOLDER/${SERVICE_NAME}.yaml
fi
fi

HELM_DBAAS_TEMPLATE="templates/dbaas.yaml"
if [ -f /kubectl-build-deploy/helmcharts/${SERVICE_TYPE}/$HELM_DBAAS_TEMPLATE ]; then
# Load the requested class and plan for this service
DBAAS_ENVIRONMENT="${MAP_SERVICE_NAME_TO_DBAAS_ENVIRONMENT["${SERVICE_NAME}"]}"
yq write -i -- /kubectl-build-deploy/${SERVICE_NAME}-values.yaml 'environment' $DBAAS_ENVIRONMENT
helm template ${SERVICE_NAME} /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} -s $HELM_DBAAS_TEMPLATE -f /kubectl-build-deploy/values.yaml -f /kubectl-build-deploy/${SERVICE_NAME}-values.yaml "${HELM_ARGUMENTS[@]}" > $YAML_FOLDER/${SERVICE_NAME}.yaml
DBAAS+=("${SERVICE_NAME}:${SERVICE_TYPE}")
fi
done

TEMPLATE_PARAMETERS=()

##############################################
### CUSTOM ROUTES FROM .lagoon.yml
##############################################
Expand Down Expand Up @@ -836,6 +886,7 @@ if [ "${ENVIRONMENT_TYPE}" == "production" ]; then
. /kubectl-build-deploy/scripts/exec-fastly-annotations.sh
# if we get any other populated service id overrides in any of the steps in exec-fastly-annotations.sh
# make it available to the ingress creation here by overriding what may be defined in the lagoon.yml
# `LAGOON_FASTLY_SERVICE_ID` is created in the exec-fastly-annotations.sh script
if [ ! -z "$LAGOON_FASTLY_SERVICE_ID" ]; then
ROUTE_FASTLY_SERVICE_ID=$LAGOON_FASTLY_SERVICE_ID
ROUTE_FASTLY_SERVICE_WATCH=$LAGOON_FASTLY_SERVICE_WATCH
Expand Down Expand Up @@ -955,6 +1006,7 @@ if [ "${ENVIRONMENT_TYPE}" == "production" ]; then
. /kubectl-build-deploy/scripts/exec-fastly-annotations.sh
# if we get any other populated service id overrides in any of the steps in exec-fastly-annotations.sh
# make it available to the ingress creation here by overriding what may be defined in the lagoon.yml
# `LAGOON_FASTLY_SERVICE_ID` is created in the exec-fastly-annotations.sh script
if [ ! -z "$LAGOON_FASTLY_SERVICE_ID" ]; then
ROUTE_FASTLY_SERVICE_ID=$LAGOON_FASTLY_SERVICE_ID
ROUTE_FASTLY_SERVICE_WATCH=$LAGOON_FASTLY_SERVICE_WATCH
Expand Down Expand Up @@ -1081,6 +1133,7 @@ if [ -n "$(cat .lagoon.yml | shyaml keys ${PROJECT}.environments.${BRANCH//./\\.
. /kubectl-build-deploy/scripts/exec-fastly-annotations.sh
# if we get any other populated service id overrides in any of the steps in exec-fastly-annotations.sh
# make it available to the ingress creation here by overriding what may be defined in the lagoon.yml
# `LAGOON_FASTLY_SERVICE_ID` is created in the exec-fastly-annotations.sh script
if [ ! -z "$LAGOON_FASTLY_SERVICE_ID" ]; then
ROUTE_FASTLY_SERVICE_ID=$LAGOON_FASTLY_SERVICE_ID
ROUTE_FASTLY_SERVICE_WATCH=$LAGOON_FASTLY_SERVICE_WATCH
Expand Down Expand Up @@ -1199,6 +1252,7 @@ else
. /kubectl-build-deploy/scripts/exec-fastly-annotations.sh
# if we get any other populated service id overrides in any of the steps in exec-fastly-annotations.sh
# make it available to the ingress creation here by overriding what may be defined in the lagoon.yml
# `LAGOON_FASTLY_SERVICE_ID` is created in the exec-fastly-annotations.sh script
if [ ! -z "$LAGOON_FASTLY_SERVICE_ID" ]; then
ROUTE_FASTLY_SERVICE_ID=$LAGOON_FASTLY_SERVICE_ID
ROUTE_FASTLY_SERVICE_WATCH=$LAGOON_FASTLY_SERVICE_WATCH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ metadata:
ingress.kubernetes.io/ssl-redirect: "true"
{{- end }}
kubernetes.io/tls-acme: "true"
# use a specific fastly service
{{- if .Values.fastly.serviceId }}
fastly.amazee.io/service-id: "{{ .Values.fastly.serviceId }}"
{{- end }}
fastly.amazee.io/watch: "{{ .Values.fastly.watch }}"
# use a custom secret for this ingress (customer supplied fastly integration)
{{- if .Values.fastly.apiSecretName }}
fastly.amazee.io/api-secret-name: "{{ .Values.fastly.apiSecretName }}"
{{- end }}
{{- include "kibana.annotations" . | nindent 4 }}
spec:
tls:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ service:
type: ClusterIP
port: 5601

## example fastly block
fastly:
watch: false
# serviceId: ''
# apiSecretName: ''

ingress:
enabled: false
annotations: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ metadata:
nginx.ingress.kubernetes.io/server-snippet: |-
add_header X-Robots-Tag "noindex, nofollow";
kubernetes.io/tls-acme: "true"
# use a specific fastly service
{{- if .Values.fastly.serviceId }}
fastly.amazee.io/service-id: "{{ .Values.fastly.serviceId }}"
{{- end }}
fastly.amazee.io/watch: "{{ .Values.fastly.watch }}"
# use a custom secret for this ingress (customer supplied fastly integration)
{{- if .Values.fastly.apiSecretName }}
fastly.amazee.io/api-secret-name: "{{ .Values.fastly.apiSecretName }}"
{{- end }}
{{- include "nginx-php-persistent.annotations" . | nindent 4 }}
spec:
tls:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ service:
type: ClusterIP
port: 8080

## example fastly block
fastly:
watch: false
# serviceId: ''
# apiSecretName: ''

resources:
nginx:
# limits:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ metadata:
nginx.ingress.kubernetes.io/server-snippet: |-
add_header X-Robots-Tag "noindex, nofollow";
kubernetes.io/tls-acme: "true"
# use a specific fastly service
{{- if .Values.fastly.serviceId }}
fastly.amazee.io/service-id: "{{ .Values.fastly.serviceId }}"
{{- end }}
fastly.amazee.io/watch: "{{ .Values.fastly.watch }}"
# use a custom secret for this ingress (customer supplied fastly integration)
{{- if .Values.fastly.apiSecretName }}
fastly.amazee.io/api-secret-name: "{{ .Values.fastly.apiSecretName }}"
{{- end }}
{{- include "nginx-php.annotations" . | nindent 4 }}
spec:
tls:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ service:
type: ClusterIP
port: 8080

## example fastly block
fastly:
watch: false
# serviceId: ''
# apiSecretName: ''

resources:
nginx:
# limits:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ metadata:
nginx.ingress.kubernetes.io/server-snippet: |-
add_header X-Robots-Tag "noindex, nofollow";
kubernetes.io/tls-acme: "true"
# use a specific fastly service
{{- if .Values.fastly.serviceId }}
fastly.amazee.io/service-id: "{{ .Values.fastly.serviceId }}"
{{- end }}
fastly.amazee.io/watch: "{{ .Values.fastly.watch }}"
# use a custom secret for this ingress (customer supplied fastly integration)
{{- if .Values.fastly.apiSecretName }}
fastly.amazee.io/api-secret-name: "{{ .Values.fastly.apiSecretName }}"
{{- end }}
{{- include "nginx.annotations" . | nindent 4 }}
spec:
tls:
Expand Down
6 changes: 6 additions & 0 deletions images/kubectl-build-deploy-dind/helmcharts/nginx/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ service:
type: ClusterIP
port: 8080

## example fastly block
fastly:
watch: false
# serviceId: ''
# apiSecretName: ''

ingress:
enabled: false
annotations: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ metadata:
nginx.ingress.kubernetes.io/server-snippet: |-
add_header X-Robots-Tag "noindex, nofollow";
kubernetes.io/tls-acme: "true"
# use a specific fastly service
{{- if .Values.fastly.serviceId }}
fastly.amazee.io/service-id: "{{ .Values.fastly.serviceId }}"
{{- end }}
fastly.amazee.io/watch: "{{ .Values.fastly.watch }}"
# use a custom secret for this ingress (customer supplied fastly integration)
{{- if .Values.fastly.apiSecretName }}
fastly.amazee.io/api-secret-name: "{{ .Values.fastly.apiSecretName }}"
{{- end }}
{{- include "node-persistent.annotations" . | nindent 4 }}
spec:
tls:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ service:
type: ClusterIP
port: 3000

## example fastly block
fastly:
watch: false
# serviceId: ''
# apiSecretName: ''

resources:
# limits:
# cpu: 100m
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ metadata:
nginx.ingress.kubernetes.io/server-snippet: |-
add_header X-Robots-Tag "noindex, nofollow";
kubernetes.io/tls-acme: "true"
# use a specific fastly service
{{- if .Values.fastly.serviceId }}
fastly.amazee.io/service-id: "{{ .Values.fastly.serviceId }}"
{{- end }}
fastly.amazee.io/watch: "{{ .Values.fastly.watch }}"
# use a custom secret for this ingress (customer supplied fastly integration)
{{- if .Values.fastly.apiSecretName }}
fastly.amazee.io/api-secret-name: "{{ .Values.fastly.apiSecretName }}"
{{- end }}
{{- include "node.annotations" . | nindent 4 }}
spec:
tls:
Expand Down
6 changes: 6 additions & 0 deletions images/kubectl-build-deploy-dind/helmcharts/node/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ service:
type: ClusterIP
port: 3000

## example fastly block
fastly:
watch: false
# serviceId: ''
# apiSecretName: ''

resources:
# limits:
# cpu: 100m
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ metadata:
nginx.ingress.kubernetes.io/server-snippet: |-
add_header X-Robots-Tag "noindex, nofollow";
kubernetes.io/tls-acme: "true"
# use a specific fastly service
{{- if .Values.fastly.serviceId }}
fastly.amazee.io/service-id: "{{ .Values.fastly.serviceId }}"
{{- end }}
fastly.amazee.io/watch: "{{ .Values.fastly.watch }}"
# use a custom secret for this ingress (customer supplied fastly integration)
{{- if .Values.fastly.apiSecretName }}
fastly.amazee.io/api-secret-name: "{{ .Values.fastly.apiSecretName }}"
{{- end }}
{{- include "python.annotations" . | nindent 4 }}
spec:
tls:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ service:
type: ClusterIP
port: 8800

## example fastly block
fastly:
watch: false
# serviceId: ''
# apiSecretName: ''

resources:
# limits:
# cpu: 100m
Expand Down
Loading