From 08611891f37eb5264a1d46657915a9b3dadfa84b Mon Sep 17 00:00:00 2001 From: Anatolii Bazko Date: Wed, 30 Jul 2025 11:06:39 +0200 Subject: [PATCH 1/3] chore: Fix debuging on opeshift Signed-off-by: Anatolii Bazko --- Makefile | 101 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 59 insertions(+), 42 deletions(-) diff --git a/Makefile b/Makefile index 1d7618711f..b21db16b57 100644 --- a/Makefile +++ b/Makefile @@ -11,13 +11,6 @@ # Red Hat, Inc. - initial API and implementation # -# VERSION defines the project version for the bundle. -# Update this value when you upgrade the version of your project. -# To re-generate a bundle for another specific version without changing the standard setup, you can: -# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2) -# - use environment variables to overwrite this value (e.g export VERSION=0.0.2) -VERSION ?= 1.0.2 - ifeq (,$(shell which kubectl)$(shell which oc)) $(error oc or kubectl is required to proceed) endif @@ -41,12 +34,6 @@ ifndef VERBOSE MAKEFLAGS += --silent endif -ifeq ($(shell $(K8S_CLI) api-resources --api-group='route.openshift.io' 2>&1 | grep -o routes),routes) - PLATFORM := openshift -else - PLATFORM := kubernetes -endif - PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST)))) # go-get-tool will 'go get' any package $2 and install it to $1. @@ -78,12 +65,6 @@ else ECLIPSE_CHE_NAMESPACE ?= "eclipse-che" endif -ifneq (,$(shell $(K8S_CLI) get pod -l app.kubernetes.io/component=che-operator -A 2>/dev/null)) - OPERATOR_NAMESPACE := $(shell $(K8S_CLI) get pod -l app.kubernetes.io/component=che-operator -A -o "jsonpath={.items[0].metadata.namespace}") -else - OPERATOR_NAMESPACE ?= "eclipse-che" -endif - ECLIPSE_CHE_PACKAGE_NAME=eclipse-che CHECLUSTER_CR_PATH="$(PROJECT_DIR)/config/samples/org_v2_checluster.yaml" @@ -362,20 +343,36 @@ genenerate-env: install-che-operands: SHELL := /bin/bash install-che-operands: generate manifests download-kustomize download-gateway-resources copy-editors-definitions - echo "[INFO] Running on $(PLATFORM)" - if [[ ! "$$($(K8S_CLI) get checluster eclipse-che -n $(ECLIPSE_CHE_NAMESPACE) || false )" ]]; then - [[ $(PLATFORM) == "kubernetes" ]] && $(MAKE) install-certmgr - $(MAKE) install-devworkspace CHANNEL="next" - $(KUSTOMIZE) build config/$(PLATFORM) | $(K8S_CLI) apply --server-side -f - - $(MAKE) wait-pod-running SELECTOR="app.kubernetes.io/component=che-operator" NAMESPACE=$(ECLIPSE_CHE_NAMESPACE) + PLATFORM=$$($(MAKE) get_platform) + + if [[ "$$($(K8S_CLI) get crd | grep "cert-manager.io" | wc -l)" == "0" ]]; then + [[ $${PLATFORM} == "kubernetes" ]] && $(MAKE) install-certmgr + else + echo "[INFO] cert-manager is already installed" fi - $(K8S_CLI) scale deploy che-operator -n $(OPERATOR_NAMESPACE) --replicas=0 + if [[ "$$($(K8S_CLI) get crd | grep "controller.devfile.io" | wc -l)" == "0" ]]; then + $(MAKE) install-devworkspace CHANNEL="next" OPERATOR_NAMESPACE="openshift-operators" + else + echo "[INFO] DevWorkspace operator is already installed" + fi + + if [[ "$$($(K8S_CLI) get crd | grep "checlusters.org.eclipse.che" | wc -l)" == "0" ]]; then + $(KUSTOMIZE) build config/$${PLATFORM} | $(K8S_CLI) apply --server-side -f - + else + echo "[INFO] Che operator is already installed" + fi - # Disable Webhooks since che operator pod is scaled down - $(K8S_CLI) delete validatingwebhookconfiguration org.eclipse.che - $(K8S_CLI) delete mutatingwebhookconfiguration org.eclipse.che - $(K8S_CLI) patch crd checlusters.org.eclipse.che --patch '{"spec": {"conversion": null}}' --type=merge + OPERATOR_NAMESPACE=$$($(MAKE) get_operator_namespace) + $(K8S_CLI) scale deploy che-operator -n "$${OPERATOR_NAMESPACE}" --replicas=0 + + # Delete Webhooks since che operator pod is scaled down + # It allows creating/updating CheCluster custom resource + if [[ ! "$$($(K8S_CLI) get checluster eclipse-che -n $(ECLIPSE_CHE_NAMESPACE) || false )" ]] || [[ ! "$(DELETE_WEBHOOKS)" == "true" ]]; then + $(K8S_CLI) delete validatingwebhookconfiguration org.eclipse.che + $(K8S_CLI) delete mutatingwebhookconfiguration org.eclipse.che + $(K8S_CLI) patch crd checlusters.org.eclipse.che --patch '{"spec": {"conversion": null}}' --type=merge + fi $(MAKE) store_tls_cert $(MAKE) create-checluster-cr @@ -400,9 +397,32 @@ download-gateway-resources: # Store `che-operator-webhook-server-cert` secret locally store_tls_cert: + OPERATOR_NAMESPACE=$$($(MAKE) get_operator_namespace) + mkdir -p /tmp/k8s-webhook-server/serving-certs/ - $(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 - $(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 + $(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 + $(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 + +get_operator_namespace: SHELL := /bin/bash +get_operator_namespace: + PLATFORM=$$($(MAKE) get_platform) + if [[ $$($(K8S_CLI) get deployments.apps -l app.kubernetes.io/component=che-operator -A -o go-template='{{len .items}}') == 0 ]]; then + if [[ "$${PLATFORM}" == "kubernetes" ]]; then + echo "eclipse-che" + else + echo "openshift-operators" + fi + else + echo $$($(K8S_CLI) get deployments.apps -l app.kubernetes.io/component=che-operator -A -o "jsonpath={.items[0].metadata.namespace}") + fi + +get_platform: SHELL := /bin/bash +get_platform: + if [[ "$$($(K8S_CLI) api-resources --api-group='route.openshift.io' --no-headers | wc -l)" == "0" ]]; then + echo "kubernetes" + else + echo "openshift" + fi ##@ OLM catalog @@ -776,10 +796,12 @@ install-certmgr: ## Install Cert Manager v1.7.1 install-devworkspace: SHELL := /bin/bash install-devworkspace: ## Install Dev Workspace operator, available channels: next, fast + PLATFORM=$$($(MAKE) get_platform) + [[ -z "$(CHANNEL)" ]] && { echo [ERROR] CHANNEL not defined; exit 1; } [[ -z "$(OPERATOR_NAMESPACE)" ]] && DEFINED_OPERATOR_NAMESPACE="openshift-operators" || DEFINED_OPERATOR_NAMESPACE=$(OPERATOR_NAMESPACE) - if [[ $(PLATFORM) == "kubernetes" ]]; then + if [[ $${PLATFORM} == "kubernetes" ]]; then $(MAKE) create-namespace NAMESPACE="devworkspace-controller" if [[ $(CHANNEL) == "fast" ]]; then rm -rf /tmp/dwo @@ -817,19 +839,14 @@ wait-devworkspace-running: ## Wait until Dev Workspace operator is up and runnin $(MAKE) wait-pod-running SELECTOR="app.kubernetes.io/name=devworkspace-controller" NAMESPACE=$(NAMESPACE) $(MAKE) wait-pod-running SELECTOR="app.kubernetes.io/name=devworkspace-webhook-server" NAMESPACE=$(NAMESPACE) -setup-checluster: create-namespace create-checluster-crd create-checluster-cr ## Setup CheCluster (creates namespace, CRD and CheCluster CR) - create-checluster-crd: SHELL := /bin/bash create-checluster-crd: ## Creates CheCluster Custom Resource Definition - if [[ $(PLATFORM) == "kubernetes" ]]; then - $(MAKE) install-certmgr - $(K8S_CLI) apply -f $(DEPLOYMENT_DIR)/$(PLATFORM)/objects/che-operator-selfsigned-issuer.Issuer.yaml - $(K8S_CLI) apply -f $(DEPLOYMENT_DIR)/$(PLATFORM)/objects/che-operator-serving-cert.Certificate.yaml - fi - $(K8S_CLI) apply -f $(DEPLOYMENT_DIR)/$(PLATFORM)/objects/checlusters.org.eclipse.che.CustomResourceDefinition.yaml + PLATFORM=$$($(MAKE) get_platform) + $(K8S_CLI) apply --server-side -f $(DEPLOYMENT_DIR)/$${PLATFORM}/objects/checlusters.org.eclipse.che.CustomResourceDefinition.yaml create-checluster-cr: SHELL := /bin/bash create-checluster-cr: ## Creates CheCluster Custom Resource V2 + PLATFORM=$$($(MAKE) get_platform) if [[ "$$($(K8S_CLI) get checluster eclipse-che -n $(ECLIPSE_CHE_NAMESPACE) || false )" ]]; then echo "[INFO] CheCluster already exists." else @@ -837,7 +854,7 @@ create-checluster-cr: ## Creates CheCluster Custom Resource V2 cp $(CHECLUSTER_CR_PATH) $${CHECLUSTER_CR_2_APPLY} # Update networking.domain field with an actual value - if [[ $(PLATFORM) == "kubernetes" ]]; then + if [[ $${PLATFORM} == "kubernetes" ]]; then # kubectl does not have `whoami` command CLUSTER_API_URL=$$(oc whoami --show-server=true) || true; CLUSTER_DOMAIN=$$(echo $${CLUSTER_API_URL} | sed -E 's/https:\/\/(.*):.*/\1/g') From 045964cc0b5ae5827bf9fe7cfd0056c79366dbdf Mon Sep 17 00:00:00 2001 From: Anatolii Bazko Date: Wed, 30 Jul 2025 12:14:48 +0200 Subject: [PATCH 2/3] chore: Fix debuging Signed-off-by: Anatolii Bazko --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b21db16b57..f3f6fa29ef 100644 --- a/Makefile +++ b/Makefile @@ -368,7 +368,7 @@ install-che-operands: generate manifests download-kustomize download-gateway-res # Delete Webhooks since che operator pod is scaled down # It allows creating/updating CheCluster custom resource - if [[ ! "$$($(K8S_CLI) get checluster eclipse-che -n $(ECLIPSE_CHE_NAMESPACE) || false )" ]] || [[ ! "$(DELETE_WEBHOOKS)" == "true" ]]; then + if [[ ! "$(DELETE_WEBHOOKS)" == "false" ]]; then $(K8S_CLI) delete validatingwebhookconfiguration org.eclipse.che $(K8S_CLI) delete mutatingwebhookconfiguration org.eclipse.che $(K8S_CLI) patch crd checlusters.org.eclipse.che --patch '{"spec": {"conversion": null}}' --type=merge From f16e01cc93e10d45d7fef6177a677b178c71863e Mon Sep 17 00:00:00 2001 From: Anatolii Bazko Date: Wed, 30 Jul 2025 12:31:45 +0200 Subject: [PATCH 3/3] chore: Fix debuging Signed-off-by: Anatolii Bazko --- Makefile | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index f3f6fa29ef..d419c3e270 100644 --- a/Makefile +++ b/Makefile @@ -59,12 +59,6 @@ VSCODE_ENV_FILE=$(INTERNAL_TMP_DIR)/vscode.env DEPLOYMENT_DIR=$(PROJECT_DIR)/deploy/deployment -ifneq (,$(shell $(K8S_CLI) get checluster -A 2>/dev/null)) - ECLIPSE_CHE_NAMESPACE := $(shell $(K8S_CLI) get checluster -A -o "jsonpath={.items[0].metadata.namespace}") -else - ECLIPSE_CHE_NAMESPACE ?= "eclipse-che" -endif - ECLIPSE_CHE_PACKAGE_NAME=eclipse-che CHECLUSTER_CR_PATH="$(PROJECT_DIR)/config/samples/org_v2_checluster.yaml" @@ -199,7 +193,7 @@ update-helmcharts: ## Update Helm Charts based on deployment resources CRDS_SAMPLES="" for CRD_SAMPLE in "$${CRDS_SAMPLES_FILES[@]}"; do - CRD_SAMPLE=$$(cat $${CRD_SAMPLE} | yq -rY ". | (.metadata.namespace = \"$(ECLIPSE_CHE_NAMESPACE)\") | [.]") + CRD_SAMPLE=$$(cat $${CRD_SAMPLE} | yq -rY ". | (.metadata.namespace = \"eclipse-che\") | [.]") CRDS_SAMPLES=$${CRDS_SAMPLES}$${CRD_SAMPLE}$$'\n' done @@ -312,6 +306,8 @@ license: download-addlicense ## Add license to the files # Generates environment files used by bash and vscode genenerate-env: + OPERATOR_NAMESPACE=$$($(MAKE) get_operator_namespace) + mkdir -p $(INTERNAL_TMP_DIR) cat $(CONFIG_MANAGER) \ | yq -r \ @@ -323,7 +319,7 @@ genenerate-env: | sed 's|"|\\"|g' \ | sed -E 's|(.*)=(.*)|\1="\2"|g' \ > $(BASH_ENV_FILE) - echo "export WATCH_NAMESPACE=$(ECLIPSE_CHE_NAMESPACE)" >> $(BASH_ENV_FILE) + echo "export WATCH_NAMESPACE=$${OPERATOR_NAMESPACE}" >> $(BASH_ENV_FILE) echo "[INFO] Created $(BASH_ENV_FILE)" cat $(CONFIG_MANAGER) \ @@ -336,7 +332,7 @@ genenerate-env: | sed 's|"|\\"|g' \ | sed -E 's|(.*)=(.*)|\1="\2"|g' \ > $(VSCODE_ENV_FILE) - echo "WATCH_NAMESPACE=$(ECLIPSE_CHE_NAMESPACE)" >> $(VSCODE_ENV_FILE) + echo "WATCH_NAMESPACE=$${OPERATOR_NAMESPACE}" >> $(VSCODE_ENV_FILE) echo "[INFO] Created $(VSCODE_ENV_FILE)" cat $(BASH_ENV_FILE) @@ -416,6 +412,14 @@ get_operator_namespace: echo $$($(K8S_CLI) get deployments.apps -l app.kubernetes.io/component=che-operator -A -o "jsonpath={.items[0].metadata.namespace}") fi +get_che_namespace: SHELL := /bin/bash +get_che_namespace: + if [[ $$($(K8S_CLI) get checluster -A -o go-template='{{len .items}}') == 0 ]]; then + echo "eclipse-che" + else + echo $$($(K8S_CLI) get checluster -A -o "jsonpath={.items[0].metadata.namespace}") + fi + get_platform: SHELL := /bin/bash get_platform: if [[ "$$($(K8S_CLI) api-resources --api-group='route.openshift.io' --no-headers | wc -l)" == "0" ]]; then @@ -424,6 +428,8 @@ get_platform: echo "openshift" fi + + ##@ OLM catalog .PHONY: bundle @@ -774,7 +780,7 @@ approve-installplan: ## Approves install plan create-namespace: SHELL := /bin/bash create-namespace: ## Creates namespace - [[ -z "$(NAMESPACE)" ]] && DEFINED_NAMESPACE=$(ECLIPSE_CHE_NAMESPACE) || DEFINED_NAMESPACE=$(NAMESPACE) + [[ -z "$(NAMESPACE)" ]] && DEFINED_NAMESPACE="eclipse-che" || DEFINED_NAMESPACE=$(NAMESPACE) $(K8S_CLI) create namespace $${DEFINED_NAMESPACE} || true wait-pod-running: SHELL := /bin/bash @@ -847,7 +853,9 @@ create-checluster-crd: ## Creates CheCluster Custom Resource Definition create-checluster-cr: SHELL := /bin/bash create-checluster-cr: ## Creates CheCluster Custom Resource V2 PLATFORM=$$($(MAKE) get_platform) - if [[ "$$($(K8S_CLI) get checluster eclipse-che -n $(ECLIPSE_CHE_NAMESPACE) || false )" ]]; then + ECLIPSE_CHE_NAMESPACE=$$($(MAKE) get_che_namespace) + + if [[ "$$($(K8S_CLI) get checluster eclipse-che -n $${ECLIPSE_CHE_NAMESPACE} || false )" ]]; then echo "[INFO] CheCluster already exists." else CHECLUSTER_CR_2_APPLY=/tmp/checluster_cr.yaml @@ -860,7 +868,7 @@ create-checluster-cr: ## Creates CheCluster Custom Resource V2 CLUSTER_DOMAIN=$$(echo $${CLUSTER_API_URL} | sed -E 's/https:\/\/(.*):.*/\1/g') yq -riY '.spec.networking.domain = "'$${CLUSTER_DOMAIN}'.nip.io"' $${CHECLUSTER_CR_2_APPLY} fi - $(K8S_CLI) apply -f $${CHECLUSTER_CR_2_APPLY} -n $(ECLIPSE_CHE_NAMESPACE) + $(K8S_CLI) apply -f $${CHECLUSTER_CR_2_APPLY} -n $${ECLIPSE_CHE_NAMESPACE} fi wait-eclipseche-version: SHELL := /bin/bash