forked from stolostron/console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·82 lines (67 loc) · 2.77 KB
/
setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# Copyright Contributors to the Open Cluster Management project
#!/usr/bin/env bash
echo > ./backend/.env
echo PORT="${BACKEND_PORT:-4000}" >> ./backend/.env
echo NODE_ENV=development >> ./backend/.env
CLUSTER_API_URL=`oc get infrastructure cluster -o jsonpath={.status.apiServerURL}`
echo CLUSTER_API_URL=$CLUSTER_API_URL >> ./backend/.env
OAUTH2_CLIENT_ID=console-dev
echo OAUTH2_CLIENT_ID=$OAUTH2_CLIENT_ID >> ./backend/.env
OAUTH2_CLIENT_SECRET=console-dev-secret
echo OAUTH2_CLIENT_SECRET=$OAUTH2_CLIENT_SECRET >> ./backend/.env
OAUTH2_REDIRECT_URL=https://localhost:3000/multicloud/login/callback
echo OAUTH2_REDIRECT_URL=$OAUTH2_REDIRECT_URL >> ./backend/.env
FRONTEND_URL=https://localhost:3000
echo FRONTEND_URL=$FRONTEND_URL >> ./backend/.env
INSTALLATION_NAMESPACE=`oc get multiclusterhub -A -o jsonpath='{.items[0].metadata.namespace}' || true`
INSTALLATION_NAMESPACE_MCE=`oc get multiclusterengine -A -o jsonpath='{.items[0].spec.targetNamespace}'`
SA=$(oc get serviceaccounts -n $INSTALLATION_NAMESPACE_MCE console-mce -o jsonpath='{.metadata.name}')
SA_SECRET=$(oc get secrets -n $INSTALLATION_NAMESPACE_MCE -o json | jq -r "[.items[] | select(.metadata.annotations[\"kubernetes.io/service-account.name\"] == \"$SA\" and .type == \"kubernetes.io/service-account-token\")][0].metadata.name // \"\"")
if [[ -z "$SA_SECRET" ]]; then
oc apply -f - << EOF
apiVersion: v1
kind: Secret
metadata:
name: console-mce-token
namespace: $INSTALLATION_NAMESPACE_MCE
annotations:
kubernetes.io/service-account.name: $SA
type: kubernetes.io/service-account-token
EOF
SA_SECRET="console-mce-token"
fi
SA_TOKEN=`oc get secret -n $INSTALLATION_NAMESPACE_MCE ${SA_SECRET} -o="jsonpath={.data.token}" | base64 -d`
CA_CERT=`oc get secret -n $INSTALLATION_NAMESPACE_MCE ${SA_SECRET} -o="jsonpath={.data.ca\.crt}"`
SERVICE_CA_CERT=`oc get secret -n $INSTALLATION_NAMESPACE_MCE ${SA_SECRET} -o="jsonpath={.data.service-ca\.crt}"`
echo TOKEN=$SA_TOKEN >> ./backend/.env
echo CA_CERT=$CA_CERT >> ./backend/.env
echo SERVICE_CA_CERT=$SERVICE_CA_CERT >> ./backend/.env
oc apply -f - << EOF
apiVersion: oauth.openshift.io/v1
grantMethod: auto
kind: OAuthClient
metadata:
name: console-dev
redirectURIs:
- $OAUTH2_REDIRECT_URL
secret: console-dev-secret
EOF
# Create route to the search-api service on the target cluster.
if [[ -n "$INSTALLATION_NAMESPACE" ]]; then
oc apply -f - << EOF
apiVersion: route.openshift.io/v1
kind: Route
metadata:
name: search-api
namespace: $INSTALLATION_NAMESPACE
spec:
to:
kind: Service
name: search-search-api
tls:
termination: reencrypt
insecureEdgeTerminationPolicy: Redirect
EOF
SEARCH_API_URL=https://$(oc get route search-api -n $INSTALLATION_NAMESPACE -o="jsonpath={.status.ingress[0].host}")
echo SEARCH_API_URL=$SEARCH_API_URL >> ./backend/.env
fi