Skip to content

Commit 586ffaf

Browse files
Merge pull request #858 from camilamacedo86/ISSUE_785
fix(run_console_loca): Fix command and improve output message
2 parents e200f20 + 1b768e8 commit 586ffaf

File tree

3 files changed

+61
-22
lines changed

3 files changed

+61
-22
lines changed

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,12 @@ endif
195195
ifeq ($(quickstart), true)
196196
./scripts/package_quickstart.sh deploy/$(target)/manifests/$(ver) deploy/$(target)/quickstart/olm.yaml
197197
endif
198+
199+
##########################
200+
# OLM - Commands #
201+
##########################
202+
203+
.PHONY: run-console-local
204+
run-console-local:
205+
@echo Running script to run the OLM console locally:
206+
. ./scripts/run_console_local.sh

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Use the OpenShift admin console (compatible with upstream Kubernetes) to interac
114114
Ensure `kubectl` is pointing at a cluster and run:
115115

116116
```shell
117-
$ ./scripts/run_console_local.sh
117+
$ make run-console-local
118118
```
119119

120120
Then visit `http://localhost:9000` to view the console.

scripts/run_console_local.sh

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,51 @@
1-
#!/usr/bin/env bash
2-
3-
secretname=$(kubectl get serviceaccount default --namespace=kube-system -o jsonpath='{.secrets[0].name}')
4-
endpoint=$(kubectl config view -o json | jq '{myctx: .["current-context"], ctxs: .contexts[], clusters: .clusters[]}' | jq 'select(.myctx == .ctxs.name)' | jq 'select(.ctxs.context.cluster == .clusters.name)' | jq '.clusters.cluster.server' -r)
5-
6-
args="--net=host"
7-
if [[ $OSTYPE == darwin* ]] || [[ "$(< /proc/version)" == *@(Microsoft|WSL)* ]]; then
8-
args="-p 9000:9000"
9-
fi
10-
11-
docker pull quay.io/openshift/origin-console:latest
12-
13-
echo "Using $endpoint"
14-
docker run -it $args \
15-
-e BRIDGE_USER_AUTH="disabled" \
16-
-e BRIDGE_K8S_MODE="off-cluster" \
17-
-e BRIDGE_K8S_MODE_OFF_CLUSTER_ENDPOINT=$endpoint \
18-
-e BRIDGE_K8S_MODE_OFF_CLUSTER_SKIP_VERIFY_TLS=true \
19-
-e BRIDGE_K8S_AUTH="bearer-token" \
20-
-e BRIDGE_K8S_AUTH_BEARER_TOKEN=$(kubectl get secret "$secretname" --namespace=kube-system -o template --template='{{.data.token}}' | base64 --decode) \
21-
quay.io/openshift/origin-console:latest
1+
#!/bin/bash
2+
3+
# Colors definition
4+
readonly RED=$(tput setaf 1)
5+
readonly RESET=$(tput sgr0)
6+
readonly BLUE=$(tput setaf 2)
7+
8+
# Add port as 9000:9000 as arg when the SO is MacOS or Win
9+
add_host_port_arg (){
10+
args="--net=host"
11+
if [[ "$OSTYPE" == "darwin"* ]] || [[ "$(< /proc/version)" == *"@(Microsoft|WSL)"* ]]; then
12+
args="-p 9000:9000"
13+
fi
14+
}
15+
16+
pull_ocp_console_image (){
17+
docker pull quay.io/openshift/origin-console:latest
18+
}
19+
20+
run_docker_console (){
21+
secretname=$(kubectl get serviceaccount default --namespace=kube-system -o jsonpath='{.secrets[0].name}')
22+
endpoint=$(kubectl config view -o json | jq '{myctx: .["current-context"], ctxs: .contexts[], clusters: .clusters[]}' | jq 'select(.myctx == .ctxs.name)' | jq 'select(.ctxs.context.cluster == .clusters.name)' | jq '.clusters.cluster.server' -r)
23+
24+
echo -e "Using $endpoint"
25+
command -v docker run -it $args \
26+
-e BRIDGE_USER_AUTH="disabled" \
27+
-e BRIDGE_K8S_MODE="off-cluster" \
28+
-e BRIDGE_K8S_MODE_OFF_CLUSTER_ENDPOINT=$endpoint \
29+
-e BRIDGE_K8S_MODE_OFF_CLUSTER_SKIP_VERIFY_TLS=true \
30+
-e BRIDGE_K8S_AUTH="bearer-token" \
31+
-e BRIDGE_K8S_AUTH_BEARER_TOKEN=$(kubectl get secret "$secretname" --namespace=kube-system -o template --template='{{.data.token}}' | base64 --decode) \
32+
quay.io/openshift/origin-console:latest &> /dev/null
33+
34+
docker_exists=${?}; if [[ ${docker_exists} -ne 0 ]]; then
35+
echo -e "${BLUE}The OLM is accessible via web console at:${RESET}"
36+
echo -e "${BLUE}https://localhost:9000/${RESET}"
37+
else
38+
echo -e "${RED}Unable to run the console locally. May this port is in usage already. ${RESET}"
39+
echo -e "${RED}Check if the OLM is not accessible via web console at: https://localhost:9000/. ${RESET}"
40+
exit 1
41+
fi
42+
43+
}
44+
45+
46+
# Calling the functions
47+
add_host_port_arg
48+
pull_ocp_console_image
49+
run_docker_console
50+
51+

0 commit comments

Comments
 (0)