Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
# This script spins up a new "spin-clouddriver-sql" deployment as a copy of the current "spin-clouddriver"
# with SQL caching agent enabled. Labels are modified such that pods won't be accessible from other services.
# You'll need Spinnaker running in the namespace, kubectl, and jq installed locally.
NAMESPACE=myspinnakernamespace
CONTEXT=kubeconfigcontext
SQL_CONFIG_SECRET=spin-clouddriver-sql-secret
SQL_DEPLOY_NAME=spin-clouddriver-sql
read -r -d '' CD_SQL << 'EOF'
sql:
enabled: true
taskRepository:
enabled: true
agent:
enabledPattern: .*
cache:
enabled: true
readBatchSize: 500
writeBatchSize: 300
scheduler:
enabled: true
connectionPools:
default:
default: true
jdbcUrl: jdbc:mysql://yourdatabaseurl:3306/clouddriver # Change that!
user: clouddriver
password: mypassword # Change that!
migration:
user: clouddriver_migration
jdbcUrl: jdbc:mysql://yourdatabaseurl:3306/clouddriver # Change that!
password: mypassword # Change that!
redis:
enabled: false
cache:
enabled: false
scheduler:
enabled: false
taskRepository:
enabled: false
EOF
# Get the name of the secret mounted to /opt/spinnaker/config
SPINNAKER_CONFIG_SECRET_NAME=$(kubectl --context $CONTEXT -n $NAMESPACE get deploy spin-clouddriver -o json \
| jq -r '.spec.template.spec.containers[].volumeMounts[] | select(.mountPath == "/opt/spinnaker/config") | .name' \
| head -n 1)
# Get the actual secret and give it a different name
EXISTING_SECRET=$(kubectl --context $CONTEXT -n $NAMESPACE get secret $SPINNAKER_CONFIG_SECRET_NAME -o json \
| jq 'del(.status, .metadata.uid, .metadata.selfLink, .metadata.resourceVersion, .metadata.creationTimestamp, .metadata.generation, .metadata.annotations)' | jq ".metadata.name = \"${SQL_CONFIG_SECRET}\"" )
# Add clouddriver-sql.yml to the secret
SECRET_DATA=$(echo ${EXISTING_SECRET} | jq ".data += {\"clouddriver-sql.yml\": \"$(echo "${CD_SQL}" | base64 | tr -d '\n')\"}")
echo "Creating Kubernetes secret..."
echo ${SECRET_DATA} | kubectl --context $CONTEXT -n $NAMESPACE apply -f -
# Get current secrets mounted on CD
REPLACE=".metadata.labels.cluster = \"${SQL_DEPLOY_NAME}\" | .metadata.name = \"${SQL_DEPLOY_NAME}\" | .spec.selector.matchLabels.cluster = \"${SQL_DEPLOY_NAME}\" | .spec.template.metadata.labels.cluster=\"${SQL_DEPLOY_NAME}\" | .spec.template.spec.volumes += [{name: \"$SQL_CONFIG_SECRET\", secret: {defaultMode: 420, secretName: \"$SQL_CONFIG_SECRET\"}}] | .spec.template.spec.containers[].volumeMounts += [{mountPath: \"/opt/spinnaker/config\", name:\"$SQL_CONFIG_SECRET\"}] | (.spec.template.spec.containers[].env[] | select(.name == \"JAVA_OPTS\") | .value) += \" -Dspring.profiles.active=local,sql\""
# Make the Clouddriver Deployment manifest with the new name, labels, and volume
CD_DEPLOY=$(kubectl --context $CONTEXT -n $NAMESPACE get deploy spin-clouddriver -o json \
| jq 'del(.status, .metadata.uid, .metadata.selfLink, .metadata.resourceVersion, .metadata.creationTimestamp, .metadata.generation, .metadata.annotations, (.spec.template.spec.containers[].volumeMounts[] | select(.mountPath == "/opt/spinnaker/config")))' \
| jq "${REPLACE}")
echo "Applying Clouddriver SQL Migration Deployment..."
echo $CD_DEPLOY | kubectl -n $NAMESPACE --context $CONTEXT apply -f -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.