Skip to content

Instantly share code, notes, and snippets.

@mdrakiburrahman
Last active December 5, 2022 15:27
Show Gist options
  • Save mdrakiburrahman/73d231f9df3ac8bc7a28c4c7b9c2f239 to your computer and use it in GitHub Desktop.
Save mdrakiburrahman/73d231f9df3ac8bc7a28c4c7b9c2f239 to your computer and use it in GitHub Desktop.
Script to run to apply and clean up chaos Mesh workflow
##########################################################
# APPLY
##########################################################
# Apply workflow
#
kubectl apply -f sqlinstance-ha.yaml
# Get primary
#
kubectl get pods -l=role.ag.mssql.microsoft.com/chaos-bc-chaos-bc=primary -n ns1669830131581917320
# Get secondary
#
kubectl get pods -l=role.ag.mssql.microsoft.com/chaos-bc-chaos-bc=secondary -n ns1669830131581917320
# Tail orchestrator logs
#
kubectl exec -i -n ns1669830131581917320 chaos-bc-ha-0 -c arc-ha-orchestrator -- tail -f /var/log/arc-ha-orchestrator/ha-supervisor-stdout.log -n +1
##########################################################
# CLEANUP
##########################################################
# Delete workflow
#
kubectl delete -f sqlinstance-ha.yaml
# Delete Chaos CRs
#
export DATA_CONTROLLER_NAMESPACE='ns1669830131581917320'
chaosCrds=$(kubectl get crd | grep 'chaos-mesh.org' | awk '{print $1}')
export workflowCrd='workflows.chaos-mesh.org'
workflowCrs=$(kubectl get ${workflowCrd} -n ${DATA_CONTROLLER_NAMESPACE} -o jsonpath='{.items[*].metadata.name}')
for i in ${workflowCrs[@]}; do
echo "$(timestamp) | INFO | 🧹 Cleaning up ${DATA_CONTROLLER_NAMESPACE}/${workflowCrd} ${i}"
kubectl patch ${workflowCrd}/${i} -n ${DATA_CONTROLLER_NAMESPACE} -p '{"metadata":{"finalizers":[]}}' --type=merge
kubectl delete ${workflowCrd}/${i} -n ${DATA_CONTROLLER_NAMESPACE}
done
for crd in ${chaosCrds[@]}; do
echo "$(timestamp) | INFO | Getting all custom resources for ${crd}"
crs=$(kubectl get ${crd} -n ${DATA_CONTROLLER_NAMESPACE} -o jsonpath='{.items[*].metadata.name}')
for i in ${crs[@]}; do
echo "$(timestamp) | INFO | 🧹 Cleaning up ${DATA_CONTROLLER_NAMESPACE}/${crd} ${i}"
kubectl patch ${crd}/${i} -n ${DATA_CONTROLLER_NAMESPACE} -p '{"metadata":{"finalizers":[]}}' --type=merge
kubectl delete ${crd}/${i} -n ${DATA_CONTROLLER_NAMESPACE}
done
done
# Delete all Arc SQL MI pods, to remove residue IOchaos from toda, which is cached
#
# See: https://github.com/chaos-mesh/toda#notes
#
kubectl delete pods -l=app.kubernetes.io/instance=chaos-bc -n ns1669830131581917320 --grace-period=0 --force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment