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

Set resource req in all the desired pods in the wanted namespaces #408

Merged
merged 10 commits into from
Aug 15, 2024
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
6 changes: 6 additions & 0 deletions infrastructure/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion infrastructure/dpladm/bin/sync-site.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appreciate you mentioning why this is needed.

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
1 change: 1 addition & 0 deletions infrastructure/environments/dplplat01/sites.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
ITViking marked this conversation as resolved.
Show resolved Hide resolved
deploy_key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHaTkDvjLW/b2qVj8FIvtX9x3TxFFZTENn+w2CFELeoC"
<<: *webmaster-release-image-source
koge:
Expand Down
58 changes: 58 additions & 0 deletions infrastructure/task/scripts/adjust-resource-requests.sh
Original file line number Diff line number Diff line change
@@ -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"
ITViking marked this conversation as resolved.
Show resolved Hide resolved

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