Skip to content

Commit

Permalink
fix: scale keycloak sts to zero if deployed in ha mode (#1010)
Browse files Browse the repository at this point in the history
## Description


## Related Issue
Fixes #1009 

## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Other (security config, docs update, etc)

## Checklist before merging

- [x] Test, docs, adr added or updated as needed
- [ ] [Contributor
Guide](https://github.com/defenseunicorns/uds-template-capability/blob/main/CONTRIBUTING.md)
followed
  • Loading branch information
noahpb authored Nov 14, 2024
1 parent 498a2c5 commit 9bae9b3
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/keycloak/common/zarf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,44 @@ components:
localPath: ../chart
actions:
onDeploy:
before:
- description: Scale down previous Keycloak pods if in HA Mode
mute: true
cmd: |
set +e
# Check if Keycloak is installed
KEYCLOAK_INSTALLED=$(zarf tools kubectl get sts -n keycloak keycloak > /dev/null 2>&1; echo $?)
echo "KEYCLOAK_INSTALLED: $KEYCLOAK_INSTALLED" # Check the value
# Check if Keycloak is not yet on the latest version
KEYCLOAK_IS_LATEST=$(zarf tools kubectl get sts -n keycloak -l helm.sh/chart=keycloak-26.0.5 -ojsonpath='{.items[].metadata.name}' > /dev/null 2>&1; echo $?)
echo "KEYCLOAK_IS_LATEST: $KEYCLOAK_IS_LATEST" # Check the value
# Check if Keycloak is in HA mode
KEYCLOAK_IS_HA=$(zarf tools kubectl get hpa keycloak -n keycloak > /dev/null 2>&1; echo $?)
echo "KEYCLOAK_IS_HA: $KEYCLOAK_IS_HA" # Check the value
# If Keycloak is installed but not the latest, check if HA is enabled, then delete HPA and scale down
if [ "${KEYCLOAK_INSTALLED}" -eq 0 ] && [ "${KEYCLOAK_IS_LATEST}" -ne 0 ]; then
if [ "${KEYCLOAK_IS_HA}" -eq 0 ]; then
echo "Keycloak is installed and not on the latest version. Scaling down..."
zarf tools kubectl delete hpa keycloak -n keycloak
zarf tools kubectl scale statefulsets keycloak -n keycloak --replicas=1
export KEYCLOAK_IS_HA=true
else
echo "Keycloak is not deployed in HA mode, skipping scale down."
fi
else
echo "Keycloak 26.0.5 is already installed, skipping scale down."
fi
after:
- description: Validate Keycloak Pods
wait:
cluster:
kind: Pod
name: app.kubernetes.io/name=keycloak
condition: Ready
namespace: keycloak
- description: Validate Keycloak Package
maxTotalSeconds: 300
wait:
Expand Down

0 comments on commit 9bae9b3

Please sign in to comment.