-
-
Save hexfusion/7c86b57f84b276b50d72f00166b2bd14 to your computer and use it in GitHub Desktop.
debug-etcd-operator.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
function log { | |
local msg="$1" | |
echo -e "$\033[32m$(date +'%Y-%m-%d %H:%M:%S') $1 $\033[0;39m" | |
} | |
export KUBECONFIG=$(find $HOME/clusters -name kubeconfig | fzf) | |
trap 'jobs -p | xargs kill || true; exit 0' INT TERM EXIT | |
log "Turning off CVO and etcd-operator" | |
oc scale --replicas 0 -n openshift-cluster-version deployments/cluster-version-operator || true | |
oc scale --replicas 0 -n openshift-etcd-operator deployments/etcd-operator || true | |
oc delete -n openshift-etcd-operator configmaps/openshift-cluster-etcd-operator-lock || true | |
log "Waiting for debug container to be ready" | |
(oc debug --namespace openshift-etcd-operator --container etcd-operator deployments/etcd-operator -- /usr/bin/sleep 1d) & | |
while true; do | |
oc wait --for=condition=Ready --namespace openshift-etcd-operator pod/etcd-operator-debug && break | |
done | |
(oc port-forward --namespace openshift-etcd-operator pod/etcd-operator-debug 12500) & | |
if [ ! -f "/tmp/dlv-linux" ]; then | |
log "Building delve" | |
docker run --name dlv golang:1.13.4 go get github.com/go-delve/delve/cmd/dlv | |
docker cp dlv:/go/bin/dlv /tmp/dlv-linux | |
docker rm dlv | |
fi | |
log "Copying delve to the operator container" | |
oc cp /tmp/dlv-linux openshift-etcd-operator/etcd-operator-debug:/usr/bin/dlv --container operator | |
if [ ! -f "/tmp/etcd-operator-linux-amd64" ]; then | |
log "Building operator linux binary" | |
GO_GCFLAGS='-gcflags=all="-N -l"' GOFLAGS=-mod=vendor GOOS=linux GOARCH=amd64 go build -o /tmp/etcd-operator-linux-amd64 ./cmd/cluster-etcd-operator | |
fi | |
log "Copying operator binary to operator container" | |
oc cp /tmp/etcd-operator-linux-amd64 openshift-etcd-operator/etcd-operator-debug:/usr/bin/cluster-etcd-operator-debug --container operator | |
log "Starting operator process" | |
oc exec --namespace openshift-etcd-operator etcd-operator-debug -c etcd-operator -- dlv --listen=:12500 --headless=true --api-version=2 --accept-multiclient exec /usr/bin/cluster-etcd-operator-debug -- operator --config=/var/run/configmaps/config/config.yaml -v=2 2>&1 | tee /tmp/etcd-operator.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment