Skip to content

Commit d4a50d8

Browse files
authored
chore: fix debug operator (#2017)
* chore: Fix debugging on OpenShift Signed-off-by: Anatolii Bazko <[email protected]>
1 parent 6d33703 commit d4a50d8

File tree

1 file changed

+79
-54
lines changed

1 file changed

+79
-54
lines changed

Makefile

Lines changed: 79 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@
1111
# Red Hat, Inc. - initial API and implementation
1212
#
1313

14-
# VERSION defines the project version for the bundle.
15-
# Update this value when you upgrade the version of your project.
16-
# To re-generate a bundle for another specific version without changing the standard setup, you can:
17-
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
18-
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
19-
VERSION ?= 1.0.2
20-
2114
ifeq (,$(shell which kubectl)$(shell which oc))
2215
$(error oc or kubectl is required to proceed)
2316
endif
@@ -41,12 +34,6 @@ ifndef VERBOSE
4134
MAKEFLAGS += --silent
4235
endif
4336

44-
ifeq ($(shell $(K8S_CLI) api-resources --api-group='route.openshift.io' 2>&1 | grep -o routes),routes)
45-
PLATFORM := openshift
46-
else
47-
PLATFORM := kubernetes
48-
endif
49-
5037
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
5138

5239
# go-get-tool will 'go get' any package $2 and install it to $1.
@@ -72,18 +59,6 @@ VSCODE_ENV_FILE=$(INTERNAL_TMP_DIR)/vscode.env
7259

7360
DEPLOYMENT_DIR=$(PROJECT_DIR)/deploy/deployment
7461

75-
ifneq (,$(shell $(K8S_CLI) get checluster -A 2>/dev/null))
76-
ECLIPSE_CHE_NAMESPACE := $(shell $(K8S_CLI) get checluster -A -o "jsonpath={.items[0].metadata.namespace}")
77-
else
78-
ECLIPSE_CHE_NAMESPACE ?= "eclipse-che"
79-
endif
80-
81-
ifneq (,$(shell $(K8S_CLI) get pod -l app.kubernetes.io/component=che-operator -A 2>/dev/null))
82-
OPERATOR_NAMESPACE := $(shell $(K8S_CLI) get pod -l app.kubernetes.io/component=che-operator -A -o "jsonpath={.items[0].metadata.namespace}")
83-
else
84-
OPERATOR_NAMESPACE ?= "eclipse-che"
85-
endif
86-
8762
ECLIPSE_CHE_PACKAGE_NAME=eclipse-che
8863

8964
CHECLUSTER_CR_PATH="$(PROJECT_DIR)/config/samples/org_v2_checluster.yaml"
@@ -218,7 +193,7 @@ update-helmcharts: ## Update Helm Charts based on deployment resources
218193

219194
CRDS_SAMPLES=""
220195
for CRD_SAMPLE in "$${CRDS_SAMPLES_FILES[@]}"; do
221-
CRD_SAMPLE=$$(cat $${CRD_SAMPLE} | yq -rY ". | (.metadata.namespace = \"$(ECLIPSE_CHE_NAMESPACE)\") | [.]")
196+
CRD_SAMPLE=$$(cat $${CRD_SAMPLE} | yq -rY ". | (.metadata.namespace = \"eclipse-che\") | [.]")
222197
CRDS_SAMPLES=$${CRDS_SAMPLES}$${CRD_SAMPLE}$$'\n'
223198
done
224199

@@ -331,6 +306,8 @@ license: download-addlicense ## Add license to the files
331306

332307
# Generates environment files used by bash and vscode
333308
genenerate-env:
309+
OPERATOR_NAMESPACE=$$($(MAKE) get_operator_namespace)
310+
334311
mkdir -p $(INTERNAL_TMP_DIR)
335312
cat $(CONFIG_MANAGER) \
336313
| yq -r \
@@ -342,7 +319,7 @@ genenerate-env:
342319
| sed 's|"|\\"|g' \
343320
| sed -E 's|(.*)=(.*)|\1="\2"|g' \
344321
> $(BASH_ENV_FILE)
345-
echo "export WATCH_NAMESPACE=$(ECLIPSE_CHE_NAMESPACE)" >> $(BASH_ENV_FILE)
322+
echo "export WATCH_NAMESPACE=$${OPERATOR_NAMESPACE}" >> $(BASH_ENV_FILE)
346323
echo "[INFO] Created $(BASH_ENV_FILE)"
347324

348325
cat $(CONFIG_MANAGER) \
@@ -355,27 +332,43 @@ genenerate-env:
355332
| sed 's|"|\\"|g' \
356333
| sed -E 's|(.*)=(.*)|\1="\2"|g' \
357334
> $(VSCODE_ENV_FILE)
358-
echo "WATCH_NAMESPACE=$(ECLIPSE_CHE_NAMESPACE)" >> $(VSCODE_ENV_FILE)
335+
echo "WATCH_NAMESPACE=$${OPERATOR_NAMESPACE}" >> $(VSCODE_ENV_FILE)
359336
echo "[INFO] Created $(VSCODE_ENV_FILE)"
360337

361338
cat $(BASH_ENV_FILE)
362339

363340
install-che-operands: SHELL := /bin/bash
364341
install-che-operands: generate manifests download-kustomize download-gateway-resources copy-editors-definitions
365-
echo "[INFO] Running on $(PLATFORM)"
366-
if [[ ! "$$($(K8S_CLI) get checluster eclipse-che -n $(ECLIPSE_CHE_NAMESPACE) || false )" ]]; then
367-
[[ $(PLATFORM) == "kubernetes" ]] && $(MAKE) install-certmgr
368-
$(MAKE) install-devworkspace CHANNEL="next"
369-
$(KUSTOMIZE) build config/$(PLATFORM) | $(K8S_CLI) apply --server-side -f -
370-
$(MAKE) wait-pod-running SELECTOR="app.kubernetes.io/component=che-operator" NAMESPACE=$(ECLIPSE_CHE_NAMESPACE)
342+
PLATFORM=$$($(MAKE) get_platform)
343+
344+
if [[ "$$($(K8S_CLI) get crd | grep "cert-manager.io" | wc -l)" == "0" ]]; then
345+
[[ $${PLATFORM} == "kubernetes" ]] && $(MAKE) install-certmgr
346+
else
347+
echo "[INFO] cert-manager is already installed"
371348
fi
372349

373-
$(K8S_CLI) scale deploy che-operator -n $(OPERATOR_NAMESPACE) --replicas=0
350+
if [[ "$$($(K8S_CLI) get crd | grep "controller.devfile.io" | wc -l)" == "0" ]]; then
351+
$(MAKE) install-devworkspace CHANNEL="next" OPERATOR_NAMESPACE="openshift-operators"
352+
else
353+
echo "[INFO] DevWorkspace operator is already installed"
354+
fi
374355

375-
# Disable Webhooks since che operator pod is scaled down
376-
$(K8S_CLI) delete validatingwebhookconfiguration org.eclipse.che
377-
$(K8S_CLI) delete mutatingwebhookconfiguration org.eclipse.che
378-
$(K8S_CLI) patch crd checlusters.org.eclipse.che --patch '{"spec": {"conversion": null}}' --type=merge
356+
if [[ "$$($(K8S_CLI) get crd | grep "checlusters.org.eclipse.che" | wc -l)" == "0" ]]; then
357+
$(KUSTOMIZE) build config/$${PLATFORM} | $(K8S_CLI) apply --server-side -f -
358+
else
359+
echo "[INFO] Che operator is already installed"
360+
fi
361+
362+
OPERATOR_NAMESPACE=$$($(MAKE) get_operator_namespace)
363+
$(K8S_CLI) scale deploy che-operator -n "$${OPERATOR_NAMESPACE}" --replicas=0
364+
365+
# Delete Webhooks since che operator pod is scaled down
366+
# It allows creating/updating CheCluster custom resource
367+
if [[ ! "$(DELETE_WEBHOOKS)" == "false" ]]; then
368+
$(K8S_CLI) delete validatingwebhookconfiguration org.eclipse.che
369+
$(K8S_CLI) delete mutatingwebhookconfiguration org.eclipse.che
370+
$(K8S_CLI) patch crd checlusters.org.eclipse.che --patch '{"spec": {"conversion": null}}' --type=merge
371+
fi
379372

380373
$(MAKE) store_tls_cert
381374
$(MAKE) create-checluster-cr
@@ -400,9 +393,42 @@ download-gateway-resources:
400393

401394
# Store `che-operator-webhook-server-cert` secret locally
402395
store_tls_cert:
396+
OPERATOR_NAMESPACE=$$($(MAKE) get_operator_namespace)
397+
403398
mkdir -p /tmp/k8s-webhook-server/serving-certs/
404-
$(K8S_CLI) get secret che-operator-service-cert -n $(OPERATOR_NAMESPACE) -o json | jq -r '.data["tls.crt"]' | base64 -d > /tmp/k8s-webhook-server/serving-certs/tls.crt
405-
$(K8S_CLI) get secret che-operator-service-cert -n $(OPERATOR_NAMESPACE) -o json | jq -r '.data["tls.key"]' | base64 -d > /tmp/k8s-webhook-server/serving-certs/tls.key
399+
$(K8S_CLI) get secret che-operator-service-cert -n $${OPERATOR_NAMESPACE} -o json | jq -r '.data["tls.crt"]' | base64 -d > /tmp/k8s-webhook-server/serving-certs/tls.crt
400+
$(K8S_CLI) get secret che-operator-service-cert -n $${OPERATOR_NAMESPACE} -o json | jq -r '.data["tls.key"]' | base64 -d > /tmp/k8s-webhook-server/serving-certs/tls.key
401+
402+
get_operator_namespace: SHELL := /bin/bash
403+
get_operator_namespace:
404+
PLATFORM=$$($(MAKE) get_platform)
405+
if [[ $$($(K8S_CLI) get deployments.apps -l app.kubernetes.io/component=che-operator -A -o go-template='{{len .items}}') == 0 ]]; then
406+
if [[ "$${PLATFORM}" == "kubernetes" ]]; then
407+
echo "eclipse-che"
408+
else
409+
echo "openshift-operators"
410+
fi
411+
else
412+
echo $$($(K8S_CLI) get deployments.apps -l app.kubernetes.io/component=che-operator -A -o "jsonpath={.items[0].metadata.namespace}")
413+
fi
414+
415+
get_che_namespace: SHELL := /bin/bash
416+
get_che_namespace:
417+
if [[ $$($(K8S_CLI) get checluster -A -o go-template='{{len .items}}') == 0 ]]; then
418+
echo "eclipse-che"
419+
else
420+
echo $$($(K8S_CLI) get checluster -A -o "jsonpath={.items[0].metadata.namespace}")
421+
fi
422+
423+
get_platform: SHELL := /bin/bash
424+
get_platform:
425+
if [[ "$$($(K8S_CLI) api-resources --api-group='route.openshift.io' --no-headers | wc -l)" == "0" ]]; then
426+
echo "kubernetes"
427+
else
428+
echo "openshift"
429+
fi
430+
431+
406432

407433
##@ OLM catalog
408434

@@ -754,7 +780,7 @@ approve-installplan: ## Approves install plan
754780

755781
create-namespace: SHELL := /bin/bash
756782
create-namespace: ## Creates namespace
757-
[[ -z "$(NAMESPACE)" ]] && DEFINED_NAMESPACE=$(ECLIPSE_CHE_NAMESPACE) || DEFINED_NAMESPACE=$(NAMESPACE)
783+
[[ -z "$(NAMESPACE)" ]] && DEFINED_NAMESPACE="eclipse-che" || DEFINED_NAMESPACE=$(NAMESPACE)
758784
$(K8S_CLI) create namespace $${DEFINED_NAMESPACE} || true
759785

760786
wait-pod-running: SHELL := /bin/bash
@@ -776,10 +802,12 @@ install-certmgr: ## Install Cert Manager v1.7.1
776802

777803
install-devworkspace: SHELL := /bin/bash
778804
install-devworkspace: ## Install Dev Workspace operator, available channels: next, fast
805+
PLATFORM=$$($(MAKE) get_platform)
806+
779807
[[ -z "$(CHANNEL)" ]] && { echo [ERROR] CHANNEL not defined; exit 1; }
780808
[[ -z "$(OPERATOR_NAMESPACE)" ]] && DEFINED_OPERATOR_NAMESPACE="openshift-operators" || DEFINED_OPERATOR_NAMESPACE=$(OPERATOR_NAMESPACE)
781809

782-
if [[ $(PLATFORM) == "kubernetes" ]]; then
810+
if [[ $${PLATFORM} == "kubernetes" ]]; then
783811
$(MAKE) create-namespace NAMESPACE="devworkspace-controller"
784812
if [[ $(CHANNEL) == "fast" ]]; then
785813
rm -rf /tmp/dwo
@@ -817,33 +845,30 @@ wait-devworkspace-running: ## Wait until Dev Workspace operator is up and runnin
817845
$(MAKE) wait-pod-running SELECTOR="app.kubernetes.io/name=devworkspace-controller" NAMESPACE=$(NAMESPACE)
818846
$(MAKE) wait-pod-running SELECTOR="app.kubernetes.io/name=devworkspace-webhook-server" NAMESPACE=$(NAMESPACE)
819847

820-
setup-checluster: create-namespace create-checluster-crd create-checluster-cr ## Setup CheCluster (creates namespace, CRD and CheCluster CR)
821-
822848
create-checluster-crd: SHELL := /bin/bash
823849
create-checluster-crd: ## Creates CheCluster Custom Resource Definition
824-
if [[ $(PLATFORM) == "kubernetes" ]]; then
825-
$(MAKE) install-certmgr
826-
$(K8S_CLI) apply -f $(DEPLOYMENT_DIR)/$(PLATFORM)/objects/che-operator-selfsigned-issuer.Issuer.yaml
827-
$(K8S_CLI) apply -f $(DEPLOYMENT_DIR)/$(PLATFORM)/objects/che-operator-serving-cert.Certificate.yaml
828-
fi
829-
$(K8S_CLI) apply -f $(DEPLOYMENT_DIR)/$(PLATFORM)/objects/checlusters.org.eclipse.che.CustomResourceDefinition.yaml
850+
PLATFORM=$$($(MAKE) get_platform)
851+
$(K8S_CLI) apply --server-side -f $(DEPLOYMENT_DIR)/$${PLATFORM}/objects/checlusters.org.eclipse.che.CustomResourceDefinition.yaml
830852

831853
create-checluster-cr: SHELL := /bin/bash
832854
create-checluster-cr: ## Creates CheCluster Custom Resource V2
833-
if [[ "$$($(K8S_CLI) get checluster eclipse-che -n $(ECLIPSE_CHE_NAMESPACE) || false )" ]]; then
855+
PLATFORM=$$($(MAKE) get_platform)
856+
ECLIPSE_CHE_NAMESPACE=$$($(MAKE) get_che_namespace)
857+
858+
if [[ "$$($(K8S_CLI) get checluster eclipse-che -n $${ECLIPSE_CHE_NAMESPACE} || false )" ]]; then
834859
echo "[INFO] CheCluster already exists."
835860
else
836861
CHECLUSTER_CR_2_APPLY=/tmp/checluster_cr.yaml
837862
cp $(CHECLUSTER_CR_PATH) $${CHECLUSTER_CR_2_APPLY}
838863

839864
# Update networking.domain field with an actual value
840-
if [[ $(PLATFORM) == "kubernetes" ]]; then
865+
if [[ $${PLATFORM} == "kubernetes" ]]; then
841866
# kubectl does not have `whoami` command
842867
CLUSTER_API_URL=$$(oc whoami --show-server=true) || true;
843868
CLUSTER_DOMAIN=$$(echo $${CLUSTER_API_URL} | sed -E 's/https:\/\/(.*):.*/\1/g')
844869
yq -riY '.spec.networking.domain = "'$${CLUSTER_DOMAIN}'.nip.io"' $${CHECLUSTER_CR_2_APPLY}
845870
fi
846-
$(K8S_CLI) apply -f $${CHECLUSTER_CR_2_APPLY} -n $(ECLIPSE_CHE_NAMESPACE)
871+
$(K8S_CLI) apply -f $${CHECLUSTER_CR_2_APPLY} -n $${ECLIPSE_CHE_NAMESPACE}
847872
fi
848873

849874
wait-eclipseche-version: SHELL := /bin/bash

0 commit comments

Comments
 (0)