Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add REST API using grpc gateway #142

Merged
merged 29 commits into from
Sep 21, 2018

Conversation

mayankjuneja
Copy link
Contributor

@mayankjuneja mayankjuneja commented Aug 6, 2018

Hi @YujiOshima, @jlewi,

We have been using Katib internally and one of the changes we have done is to expose core service as REST APIs (using grpc-gateway). I think this might be useful for others as well (issues #117, #118).

Side note - You might notice a lot of changes to vendor dir (these are mostly deletions). Doing a dep ensure cleaned up some of the unused packages. If there are other best practices around this, please let me know. I can also create a separate PR to clean up the unused packages.


This change is Reviewable

@vinaykakade
Copy link
Contributor

@YujiOshima - is there any advantage of checking-in the vendor folder with Katib? Checking in gopkg.lock and gopkg.toml should be sufficient. The PRs will be easier to look at that way, and any needed vendor packages can be downloaded locally based on lock/toml and without needing the vendor folder checked-in.

@YujiOshima
Copy link
Contributor

@mayankjuneja Thank you for the great contribution! I will take a look. Could you add some documents for REST?

@vinaykakade There is no exactry answer. https://github.com/golang/dep/blob/master/docs/FAQ.md#should-i-commit-my-vendor-directory
We can protect it from deletion of depending repository by including vendor folders.
the more Katib mature, the less vendored folders change.

@YujiOshima
Copy link
Contributor

/ok-to-test

@YujiOshima
Copy link
Contributor

/assign YujiOshima

@mayankjuneja
Copy link
Contributor Author

@YujiOshima sure, I will add some documentation/comments.

@@ -1 +1,3 @@
docker run -it --rm -v $PWD:$(pwd) -w $(pwd) znly/protoc --python_out=plugins=grpc:./python --go_out=plugins=grpc:. -I. api.proto
docker run -it --rm -v $PWD:$(pwd) -w $(pwd) znly/protoc --grpc-gateway_out=logtostderr=true:. -I. api.proto
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

building the grpc gateway and swagger stub files

scripts/build.sh Outdated
@@ -28,6 +28,9 @@ cd ${SCRIPT_ROOT}
echo "Building core image..."
docker build -t ${PREFIX}/vizier-core -f ${CMD_PREFIX}/manager/Dockerfile .

echo "Building REST API for core image..."
docker build -t ${PREFIX}/vizier-core-rest -f ${CMD_PREFIX}/manager_rest/Dockerfile .
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

build the image for manager REST API. it will be a separate service running in kubernetes.

@mayankjuneja
Copy link
Contributor Author

@YujiOshima I added some comments in the code and in this PR as well. Let me know if I should add more details.

pkg/api/api.proto Outdated Show resolved Hide resolved
@YujiOshima
Copy link
Contributor

@mayankjuneja

  • Please add build test for core-rest in CI.

    sed -i -e "s@image: katib\/vizier-core@image: ${REGISTRY}\/${REPO_NAME}\/vizier-core:${VERSION}@" manifests/vizier/core/deployment.yaml

  • Could you add doc to doc dir for how to use rest API with curl or other client?

Thank you!

@jlewi
Copy link
Contributor

jlewi commented Aug 20, 2018

Any update on this? Would be great to get it committed?

@mayankjuneja
Copy link
Contributor Author

@YujiOshima I did another pass and made the following changes:

  1. added more documentation (in docs folder)
  2. merged changes from master
  3. updated the build, deploy scripts.

Can you review these changes? Thanks!

@@ -0,0 +1,37 @@
---
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since core-rest does not need to manage k8s resources, the rbac looks unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, thanks for catching this!

docs/rest-api.md Outdated
For each RPC service, we define an equivalent HTTP REST API method using [grpc-gateway](https://github.com/grpc-ecosystem/grpc-gateway). The mapping between service and REST API method can be found in this [file](https://github.com/kubeflow/katib/blob/master/pkg/api/api.proto). The mapping includes the URL path, query parameters and request body. You can read more details on the supported methods and binding options at this [link](https://cloud.google.com/service-infrastructure/docs/service-management/reference/rpc/google.api#http)

## Examples
Assuming `{HOST}` as the ingress host for vizier-core-rest,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a way of using portforward.

kubectl v1.10~
$ kubectl -n katib port-forward svc/vizier-core-rest 8080:80

kubectl ~v1.9
& kubectl -n katib port-forward $(kubectl -n katib get pod -o=name | grep vizier-core-rest | sed -e "s@pods\/@@") 8080:80

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add this.

docs/rest-api.md Outdated
Request:

```shell
curl -X POST {HOST}/api/Manager/CreateStudy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write explicitly to use above json file.
curl -X POST {HOST}/api/Manager/CreateStudy -d @study_config.json

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, missed the argument here.

@YujiOshima
Copy link
Contributor

@mayankjuneja Thank for the great contribution!
Generally looks good. I checked it could work!
I commented a few points.
We can merge after fixing them.

@mayankjuneja
Copy link
Contributor Author

@YujiOshima thanks for the review! I added some changes based on your comments. Let me know if it looks good.

@YujiOshima
Copy link
Contributor

@mayankjuneja Thanks!
/lgtm
/approve

@k8s-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: YujiOshima

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@mayankjuneja
Copy link
Contributor Author

/retest

@YujiOshima
Copy link
Contributor

@mayankjuneja I think you need to remove serviceAccountName: vizier-core-rest from core-rest deployment.

@k8s-ci-robot k8s-ci-robot removed the lgtm label Sep 21, 2018
@mayankjuneja
Copy link
Contributor Author

@YujiOshima The tests passed now, can you please reapprove it?

@YujiOshima
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot merged commit 81f2b74 into kubeflow:master Sep 21, 2018
@YujiOshima
Copy link
Contributor

🎉🎉🎉🎉🎉🎉🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants