From cb47713b9e3b991f9c425b517f692793c034e67a Mon Sep 17 00:00:00 2001 From: "Yuan (Bob) Gong" Date: Tue, 14 Jan 2020 12:51:10 +0800 Subject: [PATCH] [UI] Simplify start server script and fix local cluster name endpoint (#2836) * Simplify start server script and fix local cluster name endpoint * Simplify start-proxy-standalone.sh --- frontend/server/handlers/gke-metadata.ts | 11 +++++++++++ frontend/start-proxy-standalone-and-server.sh | 19 ++----------------- frontend/start-proxy-standalone.sh | 14 ++------------ 3 files changed, 15 insertions(+), 29 deletions(-) diff --git a/frontend/server/handlers/gke-metadata.ts b/frontend/server/handlers/gke-metadata.ts index 171f24d9b42a..b4abde5c4074 100644 --- a/frontend/server/handlers/gke-metadata.ts +++ b/frontend/server/handlers/gke-metadata.ts @@ -12,9 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. import { Handler } from 'express'; +import * as k8sHelper from '../k8s-helper'; import fetch from 'node-fetch'; export const clusterNameHandler: Handler = async (_, res) => { + if (!k8sHelper.isInCluster) { + res.status(500).send('Not running in Kubernetes cluster.'); + return; + } + const response = await fetch( 'http://metadata/computeMetadata/v1/instance/attributes/cluster-name', { headers: { 'Metadata-Flavor': 'Google' } }, @@ -23,6 +29,11 @@ export const clusterNameHandler: Handler = async (_, res) => { }; export const projectIdHandler: Handler = async (_, res) => { + if (!k8sHelper.isInCluster) { + res.status(500).send('Not running in Kubernetes cluster.'); + return; + } + const response = await fetch('http://metadata/computeMetadata/v1/project/project-id', { headers: { 'Metadata-Flavor': 'Google' }, }); diff --git a/frontend/start-proxy-standalone-and-server.sh b/frontend/start-proxy-standalone-and-server.sh index 5c82b1b16deb..f8bbad352e8c 100755 --- a/frontend/start-proxy-standalone-and-server.sh +++ b/frontend/start-proxy-standalone-and-server.sh @@ -16,21 +16,6 @@ trap clean_up EXIT SIGINT SIGTERM echo "Preparing dev env for KFP frontend" -echo "Detecting api server pod names..." -METADATA_ENVOY_POD=($(kubectl get pods -n $NAMESPACE -l component=metadata-envoy -o=custom-columns=:.metadata.name --no-headers)) -if [ -z "$METADATA_ENVOY_POD" ]; then - echo "Couldn't get metadata envoy pod in namespace $NAMESPACE, double check the cluster your kubectl talks to." - exit 1 -fi -echo "Metadata envoy pod is $METADATA_ENVOY_POD" - -PIPELINE_API_POD=($(kubectl get pods -n $NAMESPACE -l app=ml-pipeline -o=custom-columns=:.metadata.name --no-headers)) -if [ -z "$PIPELINE_API_POD" ]; then - echo "Couldn't get pipeline api pod in namespace $NAMESPACE, double check the cluster your kubectl talks to." - exit 1 -fi -echo "Ml pipeline PIPELINE_API api pod is $PIPELINE_API_POD" - echo "Compiling node server..." pushd server npm run build @@ -46,6 +31,6 @@ popd # localhost:9090 port forwards to metadata_envoy pod. echo "Starting to port forward backend apis..." -kubectl port-forward -n $NAMESPACE $METADATA_ENVOY_POD 9090:9090 & -kubectl port-forward -n $NAMESPACE $PIPELINE_API_POD 3002:8888 & +kubectl port-forward -n $NAMESPACE svc/metadata-envoy-service 9090:9090 & +kubectl port-forward -n $NAMESPACE svc/ml-pipeline 3002:8888 & ML_PIPELINE_SERVICE_PORT=3002 npm run mock:server 3001 diff --git a/frontend/start-proxy-standalone.sh b/frontend/start-proxy-standalone.sh index 9be68140ddc9..066fc95435be 100755 --- a/frontend/start-proxy-standalone.sh +++ b/frontend/start-proxy-standalone.sh @@ -9,19 +9,9 @@ cat << EOF This script helps set up a dev env for client side UI only. It uses a real KFP standalone deployment for api requests. What this does: -1. It detects pipeline ui pod name in a KFP standalone deployment. -2. Port forward pipeline ui pod to localhost:3001 (Pipeline UI dev env is configured to redirect all api requests to localhost:3001) +* Port forward pipeline ui service to localhost:3001 (Pipeline UI dev env is configured to redirect all api requests to localhost:3001) =============================================================================== EOF -echo "Detecting pipeline ui pod name..." -PIPELINE_UI_POD=($(kubectl get pods -n $NAMESPACE -l app=ml-pipeline-ui -o=custom-columns=:.metadata.name --no-headers)) -if [ -z "$PIPELINE_UI_POD" ]; then - echo "Couldn't get pipeline ui pod in namespace '$NAMESPACE', double check the cluster your kubectl talks to and your namespace is correct." - echo "Namespace can be configured by setting env variable NAMESPACE. e.g. '$ NAMESPACE=kfp npm run start:proxy-standalone'" - exit 1 -fi -echo "Pipeline UI pod is $PIPELINE_UI_POD" - echo "Starting to port forward frontend server in a KFP standalone deployment to respond to apis..." -kubectl port-forward -n $NAMESPACE $PIPELINE_UI_POD 3001:3000 +kubectl port-forward -n $NAMESPACE svc/ml-pipeline-ui 3001:80