From 5647209b5dbcf86e3805c14584af64b15218e549 Mon Sep 17 00:00:00 2001 From: Philip Date: Thu, 11 Jul 2024 14:29:37 +0200 Subject: [PATCH 01/10] support having different versions on WM's and standard libs --- infrastructure/dpladm/bin/sync-site.sh | 16 +++++++++++++++- infrastructure/environments/dplplat01/sites.yaml | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/infrastructure/dpladm/bin/sync-site.sh b/infrastructure/dpladm/bin/sync-site.sh index 1f74e3e0..3cb7b8a9 100755 --- a/infrastructure/dpladm/bin/sync-site.sh +++ b/infrastructure/dpladm/bin/sync-site.sh @@ -34,6 +34,19 @@ function getSiteDplCmsRelease { return } + +function getWebmasterDplCmsRelease { + local wmRelease + wmRelease=$(yq eval ".sites.${1}.webmaster-cms-version" "${2}") + if [[ "${wmRelease}" == "null" ]]; then + echo "" + return + fi + + echo "${wmRelease}" + return +} + function getSiteReleaseImageRepository { local repository repository=$(yq eval ".sites.${1}.releaseImageRepository" "${2}") @@ -138,6 +151,7 @@ primaryDomain=$(getSitePrimaryDomain "${SITE}" "${SITES_CONFIG}") secondaryDomains=$(getSiteSecondaryDomains "${SITE}" "${SITES_CONFIG}") autogenerateRoutes=$(getSiteAutogenerateRoutes "${SITE}" "${SITES_CONFIG}") releaseTag=$(getSiteDplCmsRelease "${SITE}" "${SITES_CONFIG}") +wmReleaseTag=$(getWebmasterDplCmsRelease "${SITE}" "${SITES_CONFIG}") siteImageRepository=$(getSiteReleaseImageRepository "${SITE}" "${SITES_CONFIG}" || exit 1) failOnErr $? "${siteImageRepository}" siteReleaseImageName=$(getSiteReleaseImageName "${SITE}" "${SITES_CONFIG}") @@ -150,5 +164,5 @@ set -o errexit syncEnvRepo "${SITE}" "${releaseTag}" "${BRANCH}" "${siteImageRepository}" "${siteReleaseImageName}" "${importTranslationsCron}" "${autogenerateRoutes}" "${primaryDomain}" "${secondaryDomains}" if [ "${plan}" = "webmaster" ] && [ "${BRANCH}" = "main" ]; then - syncEnvRepo "${SITE}" "${releaseTag}" "moduletest" "${siteImageRepository}" "${siteReleaseImageName}" "${importTranslationsCron}" "${autogenerateRoutes}" "${primaryDomain}" "${secondaryDomains}" + syncEnvRepo "${SITE}" "${wmReleaseTag}" "moduletest" "${siteImageRepository}" "${siteReleaseImageName}" "${importTranslationsCron}" "${autogenerateRoutes}" "${primaryDomain}" "${secondaryDomains}" fi diff --git a/infrastructure/environments/dplplat01/sites.yaml b/infrastructure/environments/dplplat01/sites.yaml index 8082c173..d161e57f 100644 --- a/infrastructure/environments/dplplat01/sites.yaml +++ b/infrastructure/environments/dplplat01/sites.yaml @@ -445,6 +445,7 @@ sites: - nginx.main.kobenhavn.dplplat01.dpl.reload.dk - varnish.main.kobenhavn.dplplat01.dpl.reload.dk plan: webmaster + webmaster-cms-version: 2024.27.1 deploy_key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHaTkDvjLW/b2qVj8FIvtX9x3TxFFZTENn+w2CFELeoC" <<: *webmaster-release-image-source koge: From 70e98224d3df7a018090ae70e05fa6323d7a0812 Mon Sep 17 00:00:00 2001 From: Philip Date: Thu, 11 Jul 2024 14:49:47 +0200 Subject: [PATCH 02/10] patch cli's req --- .../dpladm/env-repo-template/standard/.lagoon.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/infrastructure/dpladm/env-repo-template/standard/.lagoon.yml b/infrastructure/dpladm/env-repo-template/standard/.lagoon.yml index 41aa3d2d..d34a11df 100644 --- a/infrastructure/dpladm/env-repo-template/standard/.lagoon.yml +++ b/infrastructure/dpladm/env-repo-template/standard/.lagoon.yml @@ -56,7 +56,13 @@ tasks: name: Import config translations command: drush dpl_po:import-remote-config-po da https://danskernesdigitalebibliotek.github.io/dpl-cms/translations/da.config.po service: cli - + - run: + name: Set Pod resource requests and limits + command: | + set -e; + echo "setting resource requests for cli" + kubernetes patch deployment cli -n ${LAGOON_PROJECT_NAME} -p '{"spec":{"template":{"spec":{"containers":[{"name":"cli","resources":{"requests":{"memory":"20Mi"}}}]}}}' + service: cli environments: main: $ENABLE_ROUTES From ed62758dc1aba241a27403830e3f323d913067c6 Mon Sep 17 00:00:00 2001 From: Philip Date: Thu, 11 Jul 2024 14:50:31 +0200 Subject: [PATCH 03/10] install kubectl, so we can have the cli box patch the pods with resource req --- .../dpladm/env-repo-template/standard/lagoon/cli.dockerfile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/infrastructure/dpladm/env-repo-template/standard/lagoon/cli.dockerfile b/infrastructure/dpladm/env-repo-template/standard/lagoon/cli.dockerfile index d85509c5..815fa15b 100644 --- a/infrastructure/dpladm/env-repo-template/standard/lagoon/cli.dockerfile +++ b/infrastructure/dpladm/env-repo-template/standard/lagoon/cli.dockerfile @@ -7,6 +7,11 @@ FROM uselagoon/php-8.1-cli-drupal:${LAGOON_IMAGES_RELEASE_TAG} COPY --from=release /app /app RUN mkdir -p -v -m775 /app/web/sites/default/files +# install kubectl - we need as long as we cant set the resource request +RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl +RUN chmod +x ./kubectl +RUN mv ./kubectl /usr/local/bin + # Define where the Drupal Root is located ENV WEBROOT=web From 3626597da6ada18089c4edd168ea8fec633e6941 Mon Sep 17 00:00:00 2001 From: Philip Date: Tue, 16 Jul 2024 10:45:38 +0200 Subject: [PATCH 04/10] add task that will run the bash script --- infrastructure/Taskfile.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/infrastructure/Taskfile.yml b/infrastructure/Taskfile.yml index 2e0196df..23fe00d1 100644 --- a/infrastructure/Taskfile.yml +++ b/infrastructure/Taskfile.yml @@ -205,6 +205,12 @@ tasks: - sh: "[ ! -z {{.AZURE_SUBSCRIPTION_ID}} ]" msg: "Env variable AZURE_SUBSCRIPTION_ID is not set or empty." + cluster:adjust:resource-request: + deps: [cluster:auth, lagoon:cli:config] + desc: "Adjust resource requests for a every pod inside a library namespace" + cmds: + - task/scripts/adjust-resource-requests.sh + support:provision:cert-manager: deps: [cluster:auth] summary: Set the DIFF environment variable to any value to switch to diffing instead of an actual upgrade. From b74e4882c5d6ba5d4224bb490a8ef3b1e0a49ace Mon Sep 17 00:00:00 2001 From: Philip Date: Tue, 16 Jul 2024 10:46:06 +0200 Subject: [PATCH 05/10] add script that will patch the resource request for the desired pods --- .../task/scripts/adjust-resource-requests.sh | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 infrastructure/task/scripts/adjust-resource-requests.sh diff --git a/infrastructure/task/scripts/adjust-resource-requests.sh b/infrastructure/task/scripts/adjust-resource-requests.sh new file mode 100755 index 00000000..8bbf0d81 --- /dev/null +++ b/infrastructure/task/scripts/adjust-resource-requests.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash +# +# Lagoon doesn't allow us to set the resource request which results in kubernetes not +# being able to adjust it's workloades properly. +# This script allows us to do that, though in an imperfect way. +# The Script should be obsolote when a vertical pod autoscaler is in place. + +# Namespace +NAMESPACES_RAW=$(kubectl get ns -o jsonpath='{.items[*].metadata.name}') +NAMESPACES=($NAMESPACES_RAW) + +SYSTEM_NAMESPACES=( + "calico-system" + "cert-manager" + "default" + "dpl-cms-develop" + "grafana" + "harbor" + "ingress-nginx" + "k8up" + "kube-node-lease" + "kube-public" + "kube-system" + "kuma-monitoring" + "lagoon" + "lagoon-core" + "loki" + "minio" + "prometheus" + "promtail" + "tigera-operator" +) + +echo "Adjusting resource requests in the cluster" +for NS in "${NAMESPACES[@]}"; do + # Skip system namespaces - those we have enough controll over + if [[ " ${SYSTEM_NAMESPACES[@]} " =~ " ${NS} " ]]; then + continue + fi + echo "## $NS ##" + # Pod to be adjusted + DEPLOYMENTS=("cli" "nginx" "varnish" "redis") + + # Desired memory request + MEMORY_REQUEST="150Mi" + + for DEPLOYMENT in "${DEPLOYMENTS[@]}"; do + # Patch the deployments resource request + kubectl patch deployments.apps -n $NS $DEPLOYMENT --type="json" -p='[ + { + "op": "replace", + "path": "/spec/template/spec/containers/0/resources/requests/memory", + "value": "'"$MEMORY_REQUEST"'" + } + ]' + done +done From 081ddcf334903ae87ab50cc397d7dcf8f3c922f3 Mon Sep 17 00:00:00 2001 From: Philip Date: Tue, 16 Jul 2024 11:18:57 +0200 Subject: [PATCH 06/10] remove this postrollout task as it doesn't work --- .../dpladm/env-repo-template/standard/.lagoon.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/infrastructure/dpladm/env-repo-template/standard/.lagoon.yml b/infrastructure/dpladm/env-repo-template/standard/.lagoon.yml index d34a11df..41aa3d2d 100644 --- a/infrastructure/dpladm/env-repo-template/standard/.lagoon.yml +++ b/infrastructure/dpladm/env-repo-template/standard/.lagoon.yml @@ -56,13 +56,7 @@ tasks: name: Import config translations command: drush dpl_po:import-remote-config-po da https://danskernesdigitalebibliotek.github.io/dpl-cms/translations/da.config.po service: cli - - run: - name: Set Pod resource requests and limits - command: | - set -e; - echo "setting resource requests for cli" - kubernetes patch deployment cli -n ${LAGOON_PROJECT_NAME} -p '{"spec":{"template":{"spec":{"containers":[{"name":"cli","resources":{"requests":{"memory":"20Mi"}}}]}}}' - service: cli + environments: main: $ENABLE_ROUTES From f413c7db24053dc740ea38ba2737bdfea709b4b7 Mon Sep 17 00:00:00 2001 From: Philip Date: Tue, 16 Jul 2024 14:43:51 +0200 Subject: [PATCH 07/10] fix shellcheck stuff --- infrastructure/task/scripts/adjust-resource-requests.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/infrastructure/task/scripts/adjust-resource-requests.sh b/infrastructure/task/scripts/adjust-resource-requests.sh index 8bbf0d81..237d2780 100755 --- a/infrastructure/task/scripts/adjust-resource-requests.sh +++ b/infrastructure/task/scripts/adjust-resource-requests.sh @@ -7,7 +7,7 @@ # Namespace NAMESPACES_RAW=$(kubectl get ns -o jsonpath='{.items[*].metadata.name}') -NAMESPACES=($NAMESPACES_RAW) +NAMESPACES=("$NAMESPACES_RAW") SYSTEM_NAMESPACES=( "calico-system" @@ -34,7 +34,7 @@ SYSTEM_NAMESPACES=( echo "Adjusting resource requests in the cluster" for NS in "${NAMESPACES[@]}"; do # Skip system namespaces - those we have enough controll over - if [[ " ${SYSTEM_NAMESPACES[@]} " =~ " ${NS} " ]]; then + if [[ " ${SYSTEM_NAMESPACES[*]} " =~ " ${NS} " ]]; then continue fi echo "## $NS ##" @@ -46,7 +46,7 @@ for NS in "${NAMESPACES[@]}"; do for DEPLOYMENT in "${DEPLOYMENTS[@]}"; do # Patch the deployments resource request - kubectl patch deployments.apps -n $NS $DEPLOYMENT --type="json" -p='[ + kubectl patch deployments.apps -n "$NS" "$DEPLOYMENT" --type="json" -p='[ { "op": "replace", "path": "/spec/template/spec/containers/0/resources/requests/memory", From 17aa31416071c88ef63a32c946aaa304cf88dc90 Mon Sep 17 00:00:00 2001 From: Philip Date: Tue, 16 Jul 2024 15:22:56 +0200 Subject: [PATCH 08/10] more shellcheck stuff --- infrastructure/task/scripts/adjust-resource-requests.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/infrastructure/task/scripts/adjust-resource-requests.sh b/infrastructure/task/scripts/adjust-resource-requests.sh index 237d2780..8d30e66f 100755 --- a/infrastructure/task/scripts/adjust-resource-requests.sh +++ b/infrastructure/task/scripts/adjust-resource-requests.sh @@ -7,7 +7,7 @@ # Namespace NAMESPACES_RAW=$(kubectl get ns -o jsonpath='{.items[*].metadata.name}') -NAMESPACES=("$NAMESPACES_RAW") +NAMESPACES=($NAMESPACES_RAW) SYSTEM_NAMESPACES=( "calico-system" @@ -34,7 +34,7 @@ SYSTEM_NAMESPACES=( echo "Adjusting resource requests in the cluster" for NS in "${NAMESPACES[@]}"; do # Skip system namespaces - those we have enough controll over - if [[ " ${SYSTEM_NAMESPACES[*]} " =~ " ${NS} " ]]; then + if [[ " ${SYSTEM_NAMESPACES[*]} " =~ ${NS} ]]; then continue fi echo "## $NS ##" From c9b3ce22bab03f55b3a80355a557de51413f87fd Mon Sep 17 00:00:00 2001 From: Philip Date: Tue, 16 Jul 2024 15:29:57 +0200 Subject: [PATCH 09/10] ignore this --- infrastructure/task/scripts/adjust-resource-requests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/infrastructure/task/scripts/adjust-resource-requests.sh b/infrastructure/task/scripts/adjust-resource-requests.sh index 8d30e66f..447b938d 100755 --- a/infrastructure/task/scripts/adjust-resource-requests.sh +++ b/infrastructure/task/scripts/adjust-resource-requests.sh @@ -7,6 +7,7 @@ # Namespace NAMESPACES_RAW=$(kubectl get ns -o jsonpath='{.items[*].metadata.name}') +# shellcheck disable=SC2206 NAMESPACES=($NAMESPACES_RAW) SYSTEM_NAMESPACES=( From dd31a75910ec3a561a6be445eff17915a64f15e7 Mon Sep 17 00:00:00 2001 From: Philip Date: Thu, 15 Aug 2024 14:05:18 +0200 Subject: [PATCH 10/10] remove unused function --- infrastructure/dpladm/bin/sync-site.sh | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/infrastructure/dpladm/bin/sync-site.sh b/infrastructure/dpladm/bin/sync-site.sh index 3cb7b8a9..124afa5f 100755 --- a/infrastructure/dpladm/bin/sync-site.sh +++ b/infrastructure/dpladm/bin/sync-site.sh @@ -34,19 +34,6 @@ function getSiteDplCmsRelease { return } - -function getWebmasterDplCmsRelease { - local wmRelease - wmRelease=$(yq eval ".sites.${1}.webmaster-cms-version" "${2}") - if [[ "${wmRelease}" == "null" ]]; then - echo "" - return - fi - - echo "${wmRelease}" - return -} - function getSiteReleaseImageRepository { local repository repository=$(yq eval ".sites.${1}.releaseImageRepository" "${2}")