Skip to content

Commit

Permalink
[UI] Simplify start server script and fix local cluster name endpoint (
Browse files Browse the repository at this point in the history
…kubeflow#2836)

* Simplify start server script and fix local cluster name endpoint

* Simplify start-proxy-standalone.sh
  • Loading branch information
Bobgy authored and rui5i committed Jan 16, 2020
1 parent 29bee99 commit cb47713
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 29 deletions.
11 changes: 11 additions & 0 deletions frontend/server/handlers/gke-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' } },
Expand All @@ -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' },
});
Expand Down
19 changes: 2 additions & 17 deletions frontend/start-proxy-standalone-and-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
14 changes: 2 additions & 12 deletions frontend/start-proxy-standalone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cb47713

Please sign in to comment.