Created
September 21, 2021 19:35
-
-
Save hexfusion/3f14da6071777de525e9fa6f73520825 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env bash | |
set -euox pipefail | |
GO_VERSION=1.16.3 | |
PORT=8181 | |
function log { | |
local msg="$1" | |
echo -e "$\033[32m$(date +'%Y-%m-%d %H:%M:%S') $1 $\033[0;39m" | |
} | |
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 $PORT) & | |
if [ ! -f "/tmp/dlv-linux-${GO_VERSION}" ]; then | |
log "Building delve" | |
docker run --mount type=bind,source=/tmp,target=/tmp --name dlv golang:${GO_VERSION} go get github.com/go-delve/delve/cmd/dlv | |
docker cp dlv:/go/bin/dlv /tmp/dlv-linux-${GO_VERSION} | |
docker rm dlv | |
fi | |
log "Copying delve to the operator container" | |
oc cp /tmp/dlv-linux-${GO_VERSION} openshift-etcd-operator/etcd-operator-debug:/usr/bin/dlv --container etcd-operator | |
log "Remove old operator binary" | |
rm -f /tmp/etcd-operator-linux-amd64 | |
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 etcd-operator | |
log "Starting operator process" | |
oc exec --namespace openshift-etcd-operator etcd-operator-debug -c etcd-operator -- dlv --listen=:$PORT --log --headless=true --api-version=2 --accept-multiclient exec /usr/bin/cluster-etcd-operator-debug -- operator --config=/var/run/configmaps/config/config.yaml -v=2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment