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. diff --git a/infrastructure/dpladm/bin/sync-site.sh b/infrastructure/dpladm/bin/sync-site.sh index 1f74e3e0..124afa5f 100755 --- a/infrastructure/dpladm/bin/sync-site.sh +++ b/infrastructure/dpladm/bin/sync-site.sh @@ -138,6 +138,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 +151,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/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 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: diff --git a/infrastructure/task/scripts/adjust-resource-requests.sh b/infrastructure/task/scripts/adjust-resource-requests.sh new file mode 100755 index 00000000..447b938d --- /dev/null +++ b/infrastructure/task/scripts/adjust-resource-requests.sh @@ -0,0 +1,58 @@ +#!/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}') +# shellcheck disable=SC2206 +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