Commit 50c75e9c authored by Vivek Ojha's avatar Vivek Ojha
Browse files

Keda upgrade from 1.5 to 2

parent abba805a
......@@ -71,7 +71,7 @@ pgbouncer:
# Specify KEDA configuration
#
keda:
version_2_enabled: false
version_2_enabled: true
################################################################################
# Specify the airflow configuration
......
{{- $isEnabled := .Values.airflow.isDataPartitionDeployment | default false -}}
{{- $isEnabled := .Values.keda.version_2_enabled | default false -}}
apiVersion: apps/v1
kind: Deployment
metadata:
......@@ -41,20 +41,6 @@ spec:
secretKeyRef:
name: airflow
key: storage-connection
---
{{- if $isEnabled }}
apiVersion: keda.sh/v1alpha1
{{- else }}
apiVersion: keda.k8s.io/v1alpha1
{{- end }}
kind: TriggerAuthentication
metadata:
name: azure-queue-auth
spec:
podIdentity:
provider: azure
---
kind: ScaledObject
metadata:
......@@ -73,9 +59,10 @@ spec:
triggers:
- type: azure-queue
metadata:
# Required
queueName: airflowlogqueue
# Optional
queueLength: "5" # default 5
authenticationRef:
name: azure-queue-auth # authenticationRef would need either podIdentity or define a connection parameter
\ No newline at end of file
{{- if $isEnabled }}
connectionFromEnv: AzureWebJobsStorage
{{- else }}
connection: AzureWebJobsStorage
{{- end }}
\ No newline at end of file
## Upgade keda version from 1.5 to 2.x
We've used feature flag to upgrade keda version from 1.5 to 2.x osdu infra on azure.
A user can follow following steps to upgrade keda version -
1. We've set keda_v2_enabled field in feature_flag variable in service resource to false.
It represents that currently osdu infra is currently using 1.5 version.
2. If using flux, reduce replica count to 0 for flux deployment until step 4. (use command - kubectl edit deployment flux -n flux)
3. Either run it or follow the steps in this script - infra/scripts/keda_upgrade_and_host_encryption.sh.
This script requires some inputs. Feel free to edit the script as per requirement.
4. Override keda_v2_enabled field to true.
Service deployment steps for manual users -
1. We've added a variable named (keda.version_2_enabled: false) in Values.yaml for following files in helm-charts-azure repo-
- osdu-airflow/values.yaml
- osdu-azure/osdu-core_services/values.yaml
- osdu-azure/osdu-ingest_enrich/values.yaml
2. Override (keda.version_2_enabled: false) value to true.
3. Make the deployment.
Service deployment steps for automated pipeline users -
1. We've added a variable named (keda.version_2_enabled: false) in Values.yaml in indexer-queue repo.
2. Override (keda.version_2_enabled: false) value here to true.
3. Make the deployment
#!/usr/bin/env bash
read -p "ARM_TENANT_ID: " tenantId
read -p "ARM_CLIENT_SECRET: " servicePrincipalKey
read -p "ARM_CLIENT_ID: " servicePrincipalId
read -p "ARM_SUBSCRIPTION_ID: " ARM_SUBSCRIPTION_ID
read -p "Remote State Account(Service Resource): " TF_VAR_remote_state_account
read -p "Remote State Container(Service Resource): " TF_VAR_remote_state_container
read -p "Azure Resource Group with AKS Cluster(Service Resource): " myResourceGroup
read -p "AKS Cluster(Service Resource): " myAKSCluster
read -p "ARM Access Key: " storageAccountArmAccessKey
read -p "Terraform workspace for central resources: " centralResourceTerraformWorkspace
read -p "Gitops Branch: " gitopsBranch
read -p "Gitops ssh url: " gitopsSshUrl
read -p "Gitops path: " gitopsPath
read -p "Gitops ssh public key file: " sshPublicKeyFile
read -p "Gitops ssh key file: " gitopsSshKeyFile
read -p "Terraform workspace name: " tfWorkspaceName
read -p "Resource Group Location: " resourceGroupLocation
read -p "Git Repo link with feature flag for keda v2 present.(Script assumes that repo name is infra-azure-provisioning. You can edit it if its something else): " gitRepo
read -p "Repo branch name with feature flag for keda v2 present. This branch should be in sync with your current infra setup: " repoBranch
read -p "Automated Pipeline deployment (only yes is accepted as true. Any other input will be treated as manual deployment): " automatedDeployment
read -p "Application namespace (Leave empty for default value - osdu. You'll need to edit this script if applications are running in different namespaces): " namespace
export TF_VERSION="0.14.4"
export TF_VAR_gitops_ssh_url="$gitopsSshUrl"
export TF_VAR_gitops_path="$gitopsPath"
export TF_VAR_gitops_branch="$gitopsBranch"
export TF_VAR_ssh_public_key_file="$sshPublicKeyFile"
export TF_VAR_gitops_ssh_key_file="$gitopsSshKeyFile"
export TF_WORKSPACE="$tfWorkspaceName"
export TF_VAR_remote_state_account="$TF_VAR_remote_state_account"
export TF_VAR_remote_state_container="$TF_VAR_remote_state_container"
export TF_VAR_resource_group_location="$resourceGroupLocation"
function enableFlux {
echo "Enabling flux"
kubectl patch deployment flux -p '{"spec":{"replicas": 1}}' -n flux
}
function disableFlux {
echo "Disabling flux"
kubectl patch deployment flux -p '{"spec":{"replicas": 0}}' -n flux
}
trap enableFlux EXIT
echo "Script Started"
if [ ! "$namespace" ]; then
echo "Assigning default namespace: osdu"
namespace=osdu
fi
echo "Namespace: $namespace"
function terraformVersionCheck() {
if [[ $(which terraform) && $(terraform --version | head -n1 | cut -d" " -f2 | cut -c 2\-) == $TF_VERSION ]]; then
echo "Terraform version check completed"
else
TF_ZIP_TARGET="https://releases.hashicorp.com/terraform/$TF_VERSION/terraform_${TF_VERSION}_linux_amd64.zip"
echo "Info: installing $TF_VERSION, target: $TF_ZIP_TARGET"
wget $TF_ZIP_TARGET -q
unzip -q "terraform_${TF_VERSION}_linux_amd64.zip"
sudo mv terraform /usr/local/bin
rm *.zip
fi
terraform -version
# Assert that jq is available, and install if it's not
command -v jq >/dev/null 2>&1 || {
echo >&2 "Installing jq"
sudo apt install -y jq
}
}
#terraformVersionCheck
#echo "Terraform verion check complete"
echo "Logging in to az cli"
az login --service-principal -u "$servicePrincipalId" --password="$servicePrincipalKey" --tenant "$tenantId"
echo "Login successful"
az aks get-credentials --resource-group="$myResourceGroup" --name="$myAKSCluster"
#echo "Credential fetch successful"
az account set --subscription "$ARM_SUBSCRIPTION_ID"
echo "Subscription set to $ARM_SUBSCRIPTION_ID"
export ARM_TENANT_ID=$tenantId
export ARM_CLIENT_SECRET=$servicePrincipalKey
export ARM_CLIENT_ID=$servicePrincipalId
export ARM_SUBSCRIPTION_ID="$ARM_SUBSCRIPTION_ID"
export TF_VAR_central_resources_workspace_name="$centralResourceTerraformWorkspace"
export ARM_ACCESS_KEY="$storageAccountArmAccessKey"
disableFlux
echo "Deleting existing scaled objects"
NEXT_WAIT_TIME=0
until [ $NEXT_WAIT_TIME -eq 5 ] || timeout 3 kubectl delete scaledobjects.keda.k8s.io --all; do
sleep $(( NEXT_WAIT_TIME++ ))
done
[ "$NEXT_WAIT_TIME" -lt 5 ]
echo "Deleting existing trigger authentications"
NEXT_WAIT_TIME=0
until [ $NEXT_WAIT_TIME -eq 5 ] || timeout 3 kubectl delete triggerauthentications.keda.k8s.io --all; do
sleep $(( NEXT_WAIT_TIME++ ))
done
[ "$NEXT_WAIT_TIME" -lt 5 ]
#set -euo pipefail
echo "Uninstalling Keda v1"
helm uninstall -n keda keda
echo "Deleting Keda v1 CRDs"
NEXT_WAIT_TIME=0
until [ $NEXT_WAIT_TIME -eq 5 ] || timeout 3 kubectl delete crd scaledobjects.keda.k8s.io --ignore-not-found=true; do
kubectl patch crd/scaledobjects.keda.k8s.io -p '{"metadata":{"finalizers":[]}}' --type=merge
sleep $(( NEXT_WAIT_TIME++ ))
done
[ "$NEXT_WAIT_TIME" -lt 5 ]
NEXT_WAIT_TIME=0
until [ $NEXT_WAIT_TIME -eq 5 ] || timeout 3 kubectl delete crd triggerauthentications.keda.k8s.io --ignore-not-found=true; do
kubectl patch crd/triggerauthentications.keda.k8s.io -p '{"metadata":{"finalizers":[]}}' --type=merge
sleep $(( NEXT_WAIT_TIME++ ))
done
[ "$NEXT_WAIT_TIME" -lt 5 ]
set -euo pipefail
echo "terraform applying with keda version updated to 2.2.0"
git clone --branch $repoBranch $gitRepo
# Assuming repo name is infra-azure-provisioning. If its not, edit the repo name in below command and cd into service_resources.
cd infra-azure-provisioning/infra/templates/osdu-r3-mvp/service_resources
echo "keda_v2_enabled = true" >> override.tfvars
terraform init -upgrade -backend-config "storage_account_name=$TF_VAR_remote_state_account" -backend-config "container_name=$TF_VAR_remote_state_container"
terraform state rm helm_release.keda
echo "Terraform applying"
terraform apply -var-file override.tfvars
\ No newline at end of file
......@@ -20,7 +20,7 @@ locals {
helm_keda_name = "keda"
helm_keda_ns = "keda"
helm_keda_repo = "https://kedacore.github.io/charts"
helm_keda_version = "1.5.0"
helm_keda_version = var.keda_v2_enabled == true ? "2.2.0" : "1.5.0"
}
resource "kubernetes_namespace" "keda" {
......
......@@ -28,6 +28,8 @@ feature_flag = {
autoscaling = false
}
keda_v2_enabled = false
prefix = "osdu-mvp"
resource_tags = {
......
......@@ -73,6 +73,9 @@ feature_flag = {
autoscaling = false
}
# Feature flag for keda v2
keda_v2_enabled = false
# cosmos DB SQL collections
cosmos_sql_collections = [
{
......
......@@ -35,7 +35,6 @@ variable "feature_flag" {
flux = bool
sa_lock = bool
autoscaling = bool
})
default = {
osdu_namespace = true
......@@ -45,6 +44,12 @@ variable "feature_flag" {
}
}
variable "keda_v2_enabled" {
description = "Feature flag for kuda v2. Needs to be true if keda v2 is installed else false"
type = bool
default = false
}
variable "randomization_level" {
description = "Number of additional random characters to include in resource names to insulate against unexpected resource name collisions."
type = number
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment