Skip to content

Commit

Permalink
Rename Redis Cache take 2 (#1526)
Browse files Browse the repository at this point in the history
* remove old clusters

* handle prod special case

* dont update redis passwords on migrate for web console
  • Loading branch information
Richard87 authored Dec 5, 2024
1 parent 5d0de7e commit c8de095
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 58 deletions.
43 changes: 10 additions & 33 deletions scripts/migrate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,11 @@ fi
# echo "ERROR: The create redis cache script is not found or it is not executable in path $CREATE_REDIS_CACHE_SCRIPT" >&2
# fi

UPDATE_REDIS_CACHE_SECRET_SCRIPT="$WORKDIR_PATH/redis/update_redis_cache_for_console.sh"
if ! [[ -x "$UPDATE_REDIS_CACHE_SECRET_SCRIPT" ]]; then
# Print to stderror
echo "ERROR: The update redis cache script is not found or it is not executable in path $UPDATE_REDIS_CACHE_SECRET_SCRIPT" >&2
fi
# UPDATE_REDIS_CACHE_SECRET_SCRIPT="$WORKDIR_PATH/redis/update_redis_cache_for_console.sh"
# if ! [[ -x "$UPDATE_REDIS_CACHE_SECRET_SCRIPT" ]]; then
# # Print to stderror
# echo "ERROR: The update redis cache script is not found or it is not executable in path $UPDATE_REDIS_CACHE_SECRET_SCRIPT" >&2
# fi

RADIX_API_ENV_VAR_SCRIPT="$WORKDIR_PATH/update_env_vars_for_radix_api.sh"
if ! [[ -x "$RADIX_API_ENV_VAR_SCRIPT" ]]; then
Expand Down Expand Up @@ -726,34 +726,11 @@ printf "\n%s► Execute %s%s\n" "${grn}" "$UPDATE_NETWORKPOLICY_CANARY_SECRET_SC
wait # wait for subshell to finish
echo ""

# update_redis_cache=true
# if [[ $USER_PROMPT == true ]]; then
# while true; do
# read -r -p "Update Redis Caches for Console? (Y/n) " yn
# case $yn in
# [Yy]*) break ;;
# [Nn]*)
# update_redis_cache=false
# exit 0
# ;;
# *) echo "Please answer yes or no." ;;
# esac
# done
# echo ""
# fi

# Wait for redis caches to be created.
printf "\nWaiting for redis caches to be created..."
while [[ $(az redis show --resource-group "$AZ_RESOURCE_GROUP_CLUSTERS" --name "$DEST_CLUSTER"-qa --query provisioningState -otsv 2>&1) != "Succeeded" && $(az redis show --resource-group "$AZ_RESOURCE_GROUP_CLUSTERS" --name "$DEST_CLUSTER"-prod --query provisioningState -otsv 2>&1) != "Succeeded" ]]; do
printf "."
sleep 5
done
printf " Done\n."

printf "%s► Execute %s (RADIX_WEB_CONSOLE_ENV=qa)%s\n" "${grn}" "$UPDATE_REDIS_CACHE_SECRET_SCRIPT" "${normal}"
RADIX_ZONE_ENV="$RADIX_ZONE_ENV" AUTH_PROXY_COMPONENT="$AUTH_PROXY_COMPONENT" CLUSTER_NAME="$DEST_CLUSTER" RADIX_WEB_CONSOLE_ENV="qa" USER_PROMPT="false" source "$UPDATE_REDIS_CACHE_SECRET_SCRIPT"
printf "%s► Execute %s (RADIX_WEB_CONSOLE_ENV=prod)%s\n" "${grn}" "$UPDATE_REDIS_CACHE_SECRET_SCRIPT" "${normal}"
RADIX_ZONE_ENV="$RADIX_ZONE_ENV" AUTH_PROXY_COMPONENT="$AUTH_PROXY_COMPONENT" CLUSTER_NAME="$DEST_CLUSTER" RADIX_WEB_CONSOLE_ENV="prod" USER_PROMPT="false" source "$UPDATE_REDIS_CACHE_SECRET_SCRIPT"
# Set up secret and hostname for Redis Cache in Web Console
# printf "%s► Execute %s (RADIX_WEB_CONSOLE_ENV=qa)%s\n" "${grn}" "$UPDATE_REDIS_CACHE_SECRET_SCRIPT" "${normal}"
# RADIX_ZONE_ENV="$RADIX_ZONE_ENV" AUTH_PROXY_COMPONENT="$AUTH_PROXY_COMPONENT" CLUSTER_NAME="$DEST_CLUSTER" RADIX_WEB_CONSOLE_ENV="qa" USER_PROMPT="false" source "$UPDATE_REDIS_CACHE_SECRET_SCRIPT"
# printf "%s► Execute %s (RADIX_WEB_CONSOLE_ENV=prod)%s\n" "${grn}" "$UPDATE_REDIS_CACHE_SECRET_SCRIPT" "${normal}"
# RADIX_ZONE_ENV="$RADIX_ZONE_ENV" AUTH_PROXY_COMPONENT="$AUTH_PROXY_COMPONENT" CLUSTER_NAME="$DEST_CLUSTER" RADIX_WEB_CONSOLE_ENV="prod" USER_PROMPT="false" source "$UPDATE_REDIS_CACHE_SECRET_SCRIPT"


# if [[ $update_redis_cache == true ]]; then
Expand Down
14 changes: 11 additions & 3 deletions scripts/redis/update_redis_cache_for_console.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,22 @@ verify_cluster_access
#######################################################################################

function updateRedisCacheConfiguration() {
REDIS_CACHE_NAME="redis-${RADIX_ZONE}-${RADIX_WEB_CONSOLE_ENV}"
if [[ $RADIX_ZONE == "prod" ]]; then
# TODO: Remove special case for platform
REDIS_CACHE_NAME="radix-platform-${RADIX_WEB_CONSOLE_ENV}"
REDIS_RESOURCE_GROUP="clusters-platform"
else
REDIS_CACHE_NAME="radix-${RADIX_ZONE}-${RADIX_WEB_CONSOLE_ENV}"
REDIS_RESOURCE_GROUP="${AZ_RESOURCE_GROUP_CLUSTERS}"
fi

echo "Updating Web Console in ${RADIX_WEB_CONSOLE_ENV} with Redis Cache ${REDIS_CACHE_NAME}..."
REDIS_CACHE_INSTANCE=$(az redis show --resource-group "${AZ_RESOURCE_GROUP_CLUSTERS}" --name "${REDIS_CACHE_NAME}" 2>/dev/null)
REDIS_CACHE_INSTANCE=$(az redis show --resource-group "${REDIS_RESOURCE_GROUP}" --name "${REDIS_CACHE_NAME}" 2>/dev/null)

WEB_CONSOLE_NAMESPACE="radix-web-console-${RADIX_WEB_CONSOLE_ENV}"
WEB_CONSOLE_AUTH_SECRET_NAME=$(kubectl get secret -l radix-component="${AUTH_PROXY_COMPONENT}" --namespace "${WEB_CONSOLE_NAMESPACE}" --output json | jq -r .items[0].metadata.name)
OAUTH2_PROXY_REDIS_CONNECTION_URL="rediss://"$(jq -r '"\(.hostName):\(.sslPort)"' <<< ${REDIS_CACHE_INSTANCE})
OAUTH2_PROXY_REDIS_PASSWORD=$(az redis list-keys --resource-group "${AZ_RESOURCE_GROUP_CLUSTERS}" --name "${REDIS_CACHE_NAME}" | jq -r .primaryKey)
OAUTH2_PROXY_REDIS_PASSWORD=$(az redis list-keys --resource-group "${REDIS_RESOURCE_GROUP}" --name "${REDIS_CACHE_NAME}" | jq -r .primaryKey)
REDIS_ENV_FILE="redis_secret_${REDIS_CACHE_NAME}.env"

echo "OAUTH2_PROXY_REDIS_CONNECTION_URL=${OAUTH2_PROXY_REDIS_CONNECTION_URL}" >> "${REDIS_ENV_FILE}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,5 @@ module "rediscache" {
rg_name = module.config.cluster_resource_group
vnet_resource_group = module.config.vnet_resource_group
sku_name = "Standard"
location = module.config.location
}
8 changes: 0 additions & 8 deletions terraform/subscriptions/s940/c2/pre-clusters/redis.tf

This file was deleted.

7 changes: 0 additions & 7 deletions terraform/subscriptions/s940/prod/pre-clusters/redis.tf

This file was deleted.

7 changes: 0 additions & 7 deletions terraform/subscriptions/s941/playground/pre-clusters/redis.tf

This file was deleted.

0 comments on commit c8de095

Please sign in to comment.