Skip to content

Commit 5cbf02f

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 5cbf02f

File tree

6 files changed

+79
-7
lines changed

6 files changed

+79
-7
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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,38 @@ 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+
if ! oc get "${HOST_CSV_NAME}" --output jsonpath="{.spec.install.spec.deployments[0].spec.template.spec.containers[1].env}" | grep -q "REGISTRATION_SERVICE_COMMAND"; then \
62+
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\"]"}}]'
63+
fi
64+
65+
# Reduce the registration service's replicas to 1, in order to facilitate
66+
# the port forwarding and debugging of the service.
67+
oc patch --namespace "${DEFAULT_HOST_NS}" ToolchainConfig config --type='merge' --patch='{"spec":{"host":{"registrationService":{"replicas":1}}}}'
68+
69+
# Patch the host-operator and member-operator CSVs to make them run with
70+
# Delve.
71+
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"]}]'
72+
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"]}]'
73+
4274
.PHONY: dev-deploy-e2e-local-two-members
4375
dev-deploy-e2e-local-two-members: deploy-e2e-local-to-dev-namespaces-two-members print-reg-service-link
4476

make/test.mk

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,11 @@ ifneq (${FORCED_TAG},"")
331331
$(eval FORCED_TAG_PARAM = -ft ${FORCED_TAG})
332332
endif
333333
endif
334+
ifneq (${DEBUG_MODE},"")
335+
ifneq (${DEBUG_MODE},)
336+
$(eval DEBUG_MODE_PARAM = -dm ${DEBUG_MODE})
337+
endif
338+
endif
334339
ifeq ($(DEPLOY_LATEST),true)
335340
@echo "Installing latest version of the member-operator in namespace ${MEMBER_NS}"
336341
${KSCTL_BIN_DIR}ksctl adm install-operator member --kubeconfig "$(or ${KUBECONFIG}, ${HOME}/.kube/config)" --namespace ${MEMBER_NS} ${KSCTL_INSTALL_TIMEOUT_PARAM} -y
@@ -340,7 +345,7 @@ ifeq ($(DEPLOY_LATEST),true)
340345
endif
341346
else
342347
@echo "Installing specific version of the member-operator"
343-
scripts/ci/manage-member-operator.sh -po ${PUBLISH_OPERATOR} -io ${INSTALL_OPERATOR} -mn ${MEMBER_NS} ${MEMBER_REPO_PATH_PARAM} -qn ${QUAY_NAMESPACE} -ds ${DATE_SUFFIX} ${MEMBER_NS_2_PARAM} ${FORCED_TAG_PARAM}
348+
scripts/ci/manage-member-operator.sh -po ${PUBLISH_OPERATOR} -io ${INSTALL_OPERATOR} -mn ${MEMBER_NS} ${MEMBER_REPO_PATH_PARAM} -qn ${QUAY_NAMESPACE} -ds ${DATE_SUFFIX} ${MEMBER_NS_2_PARAM} ${FORCED_TAG_PARAM} ${DEBUG_MODE_PARAM}
344349
endif
345350

346351
.PHONY: get-and-publish-host-operator
@@ -360,12 +365,17 @@ ifneq (${FORCED_TAG},"")
360365
$(eval FORCED_TAG_PARAM = -ft ${FORCED_TAG})
361366
endif
362367
endif
368+
ifneq (${DEBUG_MODE},"")
369+
ifneq (${DEBUG_MODE},)
370+
$(eval DEBUG_MODE_PARAM = -dm ${DEBUG_MODE})
371+
endif
372+
endif
363373
ifeq ($(DEPLOY_LATEST),true)
364374
@echo "Installing latest version of the host-operator"
365375
${KSCTL_BIN_DIR}ksctl adm install-operator host --kubeconfig "$(or ${KUBECONFIG}, ${HOME}/.kube/config)" --namespace ${HOST_NS} ${KSCTL_INSTALL_TIMEOUT_PARAM} -y
366376
else
367377
@echo "Installing specific version of the host-operator"
368-
scripts/ci/manage-host-operator.sh -po ${PUBLISH_OPERATOR} -io ${INSTALL_OPERATOR} -hn ${HOST_NS} ${HOST_REPO_PATH_PARAM} -ds ${DATE_SUFFIX} -qn ${QUAY_NAMESPACE} ${REG_REPO_PATH_PARAM} ${FORCED_TAG_PARAM}
378+
scripts/ci/manage-host-operator.sh -po ${PUBLISH_OPERATOR} -io ${INSTALL_OPERATOR} -hn ${HOST_NS} ${HOST_REPO_PATH_PARAM} -ds ${DATE_SUFFIX} -qn ${QUAY_NAMESPACE} ${REG_REPO_PATH_PARAM} ${FORCED_TAG_PARAM} ${DEBUG_MODE_PARAM}
369379
endif
370380

371381
###########################################################

scripts/ci/manage-host-operator.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ user_help () {
1111
echo "-rr, --reg-repo-path Path to the registation service repo"
1212
echo "-ds, --date-suffix Date suffix to be added to some resources that are created"
1313
echo "-ft, --forced-tag Forces a tag to be set to all built images. In the case deployment the tag is used for index image in the created CatalogSource"
14+
echo "-dm, --debug-mode Builds and pushes the operator to quay, including a Delve debugger to be able to launch the operator with it"
1415
echo "-h, --help To show this help text"
1516
echo ""
1617
exit 0
@@ -68,6 +69,11 @@ read_arguments() {
6869
FORCED_TAG=$1
6970
shift
7071
;;
72+
-dm|--debug-mode)
73+
shift
74+
DEBUG_MODE=$1
75+
shift
76+
;;
7177
*)
7278
echo "$1 is not a recognized flag!" >> /dev/stderr
7379
user_help
@@ -96,7 +102,7 @@ if [[ -n "${CI}${REG_REPO_PATH}${HOST_REPO_PATH}" ]] && [[ $(echo ${REPO_NAME} |
96102
set_tags
97103

98104
if [[ ${PUBLISH_OPERATOR} == "true" ]]; then
99-
push_image
105+
push_image "${DEBUG_MODE}"
100106
REG_SERV_IMAGE_LOC=${IMAGE_LOC}
101107
REG_REPO_PATH=${REPOSITORY_PATH}
102108
fi
@@ -108,7 +114,7 @@ if [[ -n "${CI}${REG_REPO_PATH}${HOST_REPO_PATH}" ]] && [[ $(echo ${REPO_NAME} |
108114
set_tags
109115

110116
if [[ ${PUBLISH_OPERATOR} == "true" ]]; then
111-
push_image
117+
push_image "${DEBUG_MODE}"
112118
OPERATOR_IMAGE_LOC=${IMAGE_LOC}
113119
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}
114120
fi

scripts/ci/manage-member-operator.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ user_help () {
1111
echo "-mr, --member-repo-path Path to the member operator repo"
1212
echo "-ds, --date-suffix Date suffix to be added to some resources that are created"
1313
echo "-ft, --forced-tag Forces a tag to be set to all built images. In the case deployment the tag is used for index image in the created CatalogSource"
14+
echo "-dm, --debug-mode Builds and pushes the operator to quay, including a Delve debugger to be able to launch the operator with it"
1415
echo "-h, --help To show this help text"
1516
echo ""
1617
exit 0
@@ -67,6 +68,11 @@ read_arguments() {
6768
FORCED_TAG=$1
6869
shift
6970
;;
71+
-dm|--debug-mode)
72+
shift
73+
DEBUG_MODE=$1
74+
shift
75+
;;
7076
*)
7177
echo "$1 is not a recognized flag!" >> /dev/stderr
7278
user_help
@@ -95,7 +101,7 @@ if [[ -n "${CI}${MEMBER_REPO_PATH}" ]] && [[ $(echo ${REPO_NAME} | sed 's/"//g')
95101
set_tags
96102

97103
if [[ ${PUBLISH_OPERATOR} == "true" ]]; then
98-
push_image
104+
push_image "${DEBUG_MODE}"
99105

100106
OPERATOR_IMAGE_LOC=${IMAGE_LOC}
101107
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: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,21 @@ 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+
56+
# Set a default image builder in case none has been specified.
57+
IMAGE_BUILDER="${IMAGE_BUILDER:-podman}"
58+
4859
GIT_COMMIT_ID=$(git --git-dir=${REPOSITORY_PATH}/.git --work-tree=${REPOSITORY_PATH} rev-parse --short HEAD)
4960
IMAGE_LOC=quay.io/codeready-toolchain/${REPOSITORY_NAME}:${GIT_COMMIT_ID}
5061
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}
62+
make -C ${REPOSITORY_PATH} ${IMAGE_BUILDER}-push${DEBUG_MODE_SUFFIX} QUAY_NAMESPACE=${QUAY_NAMESPACE} IMAGE_TAG=${TAGS}
5363
IMAGE_LOC=quay.io/${QUAY_NAMESPACE}/${REPOSITORY_NAME}:${TAGS}
5464
fi
5565
}

0 commit comments

Comments
 (0)