Skip to content

Commit b390515

Browse files
committed
feature: Make targets for debugging services and operators
Adds a new Make target which triggers build in the underlying services and operators which end up building the images without any code optimizations and with Delve on them. Once pushed and deployed to the local OpenShift cluster, it patches the host operator, the member operator and the registration service to launch them with the Delve executable, which allows debugging them on port 50000 after port-forwarding to those pods. SANDBOX-1561
1 parent c4598f6 commit b390515

File tree

5 files changed

+50
-5
lines changed

5 files changed

+50
-5
lines changed

README.adoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ All e2e resources (host operator, member operator, registration-service, CRDs, e
151151
152152
* `make dev-deploy-e2e-local` - deploys the same resources as `make test-e2e-local` in dev environment but doesn't run tests.
153153
154+
* `make dev-deploy-e2e-local-debug` - deploys the same resources as `make test-e2e-local` in the local OpenShift
155+
instance, but builds the services and the operators without any code optimizations. It also ships Delve in the images,
156+
and launches those services with it, which leaves the debugger listening on port `50000`. Then, you can simply `oc
157+
port-forward ${POD} 50000:50000` and connect to them with your favorite IDE. The services that are built like that are:
158+
** The registration service.
159+
** The host operator controller manager.
160+
** The member operator controller manager.
161+
154162
* `make dev-deploy-e2e` - deploys the same resources as `make test-e2e` in dev environment but doesn't run tests.
155163
156164
* `make deploy-single-member-e2e-latest` - deploys the same resources (using the latest and greatest images of Toolchain operators) as `make test-e2e` but with only one member and doesn't run tests.

make/dev.mk

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,36 @@ setup-dev-sso:
3939
.PHONY: dev-deploy-e2e-local
4040
dev-deploy-e2e-local: deploy-e2e-local-to-dev-namespaces print-reg-service-link
4141

42+
# Builds the services' and operators' images with the debugger in it, so that
43+
# then an IDE can be connected to them. Since the targets down the line use
44+
# the default namespaces, we can use them to patch the required CRs in order
45+
# to launch the binaries with Delve.
46+
.ONESHELL:
47+
.PHONY: dev-deploy-e2e-local-debug
48+
dev-deploy-e2e-local-debug: export DEBUG_MODE=true
49+
dev-deploy-e2e-local-debug:
50+
$(MAKE) dev-deploy-e2e-local
51+
52+
# Get the CSVs for the host and member operators, in order to be able to
53+
# patch them.
54+
HOST_CSV_NAME=$$(oc get --namespace "${DEFAULT_HOST_NS}" --output name ClusterServiceVersion)
55+
MEMBER_CSV_NAME=$$(oc get --namespace ${DEFAULT_MEMBER_NS} --output name ClusterServiceVersion)
56+
57+
# Patch the host operator indicating which command the registration
58+
# service should be run with. The command simply adds an environment
59+
# variable to the operator which then makes sure that the registration
60+
# service is run with Delve, in case the user wants to connect to it.
61+
oc patch --namespace "${DEFAULT_HOST_NS}" "${HOST_CSV_NAME}" --type='json' --patch='[{"op": "add", "path": "/spec/install/spec/deployments/0/spec/template/spec/containers/1/env/-", "value": {"name": "REGISTRATION_SERVICE_COMMAND", "value": "[\"dlv\", \"--listen=:50000\", \"--headless\", \"--continue\", \"--api-version=2\", \"--accept-multiclient\", \"exec\", \"/usr/local/bin/registration-service\"]"}}]' || true
62+
63+
# Reduce the registration service's replicas to 1, in order to facilitate
64+
# the port forwarding and debugging of the service.
65+
oc patch --namespace "${DEFAULT_HOST_NS}" ToolchainConfig config --type='merge' --patch='{"spec":{"host":{"registrationService":{"replicas":1}}}}'
66+
67+
# Patch the host-operator and member-operator CSVs to make them run with
68+
# Delve.
69+
oc patch --namespace "${DEFAULT_HOST_NS}" "${HOST_CSV_NAME}" --type='json' --patch='[{"op": "replace", "path": "/spec/install/spec/deployments/0/spec/template/spec/containers/1/args", "value": []}, {"op": "replace", "path": "/spec/install/spec/deployments/0/spec/template/spec/containers/1/command", "value": ["dlv", "--listen=:50000", "--headless", "--continue", "--api-version=2", "--accept-multiclient", "exec", "/usr/local/bin/host-operator", "--", "--health-probe-bind-address=:8081", "--metrics-bind-address=127.0.0.1:8080", "--leader-elect"]}]'
70+
oc patch --namespace "${DEFAULT_MEMBER_NS}" "${MEMBER_CSV_NAME}" --type='json' --patch='[{"op": "replace", "path": "/spec/install/spec/deployments/0/spec/template/spec/containers/0/args", "value": []}, {"op": "replace", "path": "/spec/install/spec/deployments/0/spec/template/spec/containers/0/command", "value": ["dlv", "--listen=:50000", "--headless", "--continue", "--api-version=2", "--accept-multiclient", "exec", "/usr/local/bin/member-operator", "--", "--health-probe-bind-address=:8081", "--metrics-bind-address=127.0.0.1:8080", "--leader-elect"]}]'
71+
4272
.PHONY: dev-deploy-e2e-local-two-members
4373
dev-deploy-e2e-local-two-members: deploy-e2e-local-to-dev-namespaces-two-members print-reg-service-link
4474

scripts/ci/manage-host-operator.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ if [[ -n "${CI}${REG_REPO_PATH}${HOST_REPO_PATH}" ]] && [[ $(echo ${REPO_NAME} |
9696
set_tags
9797

9898
if [[ ${PUBLISH_OPERATOR} == "true" ]]; then
99-
push_image
99+
push_image "${DEBUG_MODE}"
100100
REG_SERV_IMAGE_LOC=${IMAGE_LOC}
101101
REG_REPO_PATH=${REPOSITORY_PATH}
102102
fi
@@ -108,7 +108,7 @@ if [[ -n "${CI}${REG_REPO_PATH}${HOST_REPO_PATH}" ]] && [[ $(echo ${REPO_NAME} |
108108
set_tags
109109

110110
if [[ ${PUBLISH_OPERATOR} == "true" ]]; then
111-
push_image
111+
push_image "${DEBUG_MODE}"
112112
OPERATOR_IMAGE_LOC=${IMAGE_LOC}
113113
make -C ${REPOSITORY_PATH} publish-current-bundle INDEX_IMAGE_TAG=${BUNDLE_AND_INDEX_TAG} BUNDLE_TAG=${BUNDLE_AND_INDEX_TAG} QUAY_NAMESPACE=${QUAY_NAMESPACE} OTHER_REPO_PATH=${REG_REPO_PATH} OTHER_REPO_IMAGE_LOC=${REG_SERV_IMAGE_LOC} IMAGE=${OPERATOR_IMAGE_LOC}
114114
fi

scripts/ci/manage-member-operator.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ if [[ -n "${CI}${MEMBER_REPO_PATH}" ]] && [[ $(echo ${REPO_NAME} | sed 's/"//g')
9595
set_tags
9696

9797
if [[ ${PUBLISH_OPERATOR} == "true" ]]; then
98-
push_image
98+
push_image "${DEBUG_MODE}"
9999

100100
OPERATOR_IMAGE_LOC=${IMAGE_LOC}
101101
make -C ${REPOSITORY_PATH} publish-current-bundle INDEX_IMAGE_TAG=${BUNDLE_AND_INDEX_TAG} BUNDLE_TAG=${BUNDLE_AND_INDEX_TAG} QUAY_NAMESPACE=${QUAY_NAMESPACE} IMAGE=${OPERATOR_IMAGE_LOC}

scripts/ci/manage-operator.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,18 @@ set_tags() {
4545
}
4646

4747
push_image() {
48+
# When the "${DEBUG_MODE}" argument is passed, we instruct Make to push
49+
# the "debug" images with Delve on them.
50+
if [[ $1 == "true" ]]; then
51+
DEBUG_MODE_SUFFIX="-debug"
52+
else
53+
DEBUG_MODE_SUFFIX=""
54+
fi
55+
4856
GIT_COMMIT_ID=$(git --git-dir=${REPOSITORY_PATH}/.git --work-tree=${REPOSITORY_PATH} rev-parse --short HEAD)
4957
IMAGE_LOC=quay.io/codeready-toolchain/${REPOSITORY_NAME}:${GIT_COMMIT_ID}
5058
if is_provided_or_paired; then
51-
IMAGE_BUILDER=${IMAGE_BUILDER:-"podman"}
52-
make -C ${REPOSITORY_PATH} ${IMAGE_BUILDER}-push QUAY_NAMESPACE=${QUAY_NAMESPACE} IMAGE_TAG=${TAGS}
59+
make -C ${REPOSITORY_PATH} ${IMAGE_BUILDER}-push${DEBUG_MODE_SUFFIX} QUAY_NAMESPACE=${QUAY_NAMESPACE} IMAGE_TAG=${TAGS}
5360
IMAGE_LOC=quay.io/${QUAY_NAMESPACE}/${REPOSITORY_NAME}:${TAGS}
5461
fi
5562
}

0 commit comments

Comments
 (0)