From 57db4b459f8922c1a5d620b4e9d9f99619db798f Mon Sep 17 00:00:00 2001 From: Oleksandr Andriienko Date: Fri, 9 Oct 2020 10:01:04 +0300 Subject: [PATCH] Fix debugger for openshift cluster. Signed-off-by: Oleksandr Andriienko --- .vscode/launch.json | 1 + .vscode/tasks.json | 3 +-- local-debug.sh | 25 +++++++++++++++++++------ pkg/util/util.go | 8 ++++++-- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index c0d233d8e2..fcae49c702 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -174,6 +174,7 @@ "CHE_POSTGRES_SECRET": "che-postgres-secret", "CHE_SERVER_TRUST_STORE_CONFIGMAP_NAME": "ca-certs" }, + "envFile": "/tmp/che-operator-debug.env", "cwd": "${workspaceFolder}", "args": [ "--defaults-path", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index e6088c562d..97960cbfdd 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -26,7 +26,6 @@ "reveal": "always" }, "group": "build" - } + } ] } - diff --git a/local-debug.sh b/local-debug.sh index ac4d0f6806..5303ef21fc 100755 --- a/local-debug.sh +++ b/local-debug.sh @@ -12,11 +12,6 @@ set -e -if [ $# -ne 1 ]; then - echo -e "Wrong number of parameters.\nUsage: ./loca-debug.sh \n" - exit 1 -fi - command -v delv >/dev/null 2>&1 || { echo "operator-sdk is not installed. Aborting."; exit 1; } command -v operator-sdk >/dev/null 2>&1 || { echo -e $RED"operator-sdk is not installed. Aborting."$NC; exit 1; } @@ -28,8 +23,26 @@ set +e kubectl create namespace $CHE_NAMESPACE set -e +CR="${1}" +if [ -z "${CR}" ]; then + CR="./deploy/crds/org_v1_che_cr.yaml" + echo "[INFO] First argument is an empty. Set up default CR file: ${CR}" +fi + kubectl apply -f deploy/crds/org_v1_che_crd.yaml -kubectl apply -f $1 -n $CHE_NAMESPACE +kubectl apply -f "${CR}" -n $CHE_NAMESPACE cp templates/keycloak_provision /tmp/keycloak_provision +cp templates/oauth_provision /tmp/oauth_provision + +ENV_FILE=/tmp/che-operator-debug.env +rm -rf "${ENV_FILE}" +touch "${ENV_FILE}" +CLUSTER_API_URL=$(oc whoami --show-server=true) || true +if [ -n "${CLUSTER_API_URL}" ]; then + echo "CLUSTER_API_URL='${CLUSTER_API_URL}'" > "${ENV_FILE}" + echo "[INFO] Set up cluster api url: ${CLUSTER_API_URL}" +fi + +echo "[WARN] Make sure that your CR contains valid ingress domain!" operator-sdk up local --namespace=${CHE_NAMESPACE} --enable-delve diff --git a/pkg/util/util.go b/pkg/util/util.go index 97259ab592..795b2bf1a8 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -190,11 +190,15 @@ func IsTestMode() (isTesting bool) { } func GetClusterPublicHostname(isOpenShift4 bool) (hostname string, err error) { + // Could be set for debug scripts. + CLUSTER_API_URL := os.Getenv("CLUSTER_API_URL") + if CLUSTER_API_URL != "" { + return CLUSTER_API_URL, nil + } if isOpenShift4 { return getClusterPublicHostnameForOpenshiftV4() - } else { - return getClusterPublicHostnameForOpenshiftV3() } + return getClusterPublicHostnameForOpenshiftV3() } // getClusterPublicHostnameForOpenshiftV3 is a hacky way to get OpenShift API public DNS/IP