-
Notifications
You must be signed in to change notification settings - Fork 455
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
Changes from 27 commits
6ce4191
65683a4
3c212c2
6ea6cf7
d9fdfd5
b4b54df
72a1108
e61a24e
e427ad4
230f66c
5a98cd7
6e3481b
ecbc5dd
08798f6
eade988
5ed01f0
cabf4d5
e1745f9
a32821e
1ea4350
138f0f6
75e1d8e
7751637
44be303
63bafb2
285d9f2
ee3f03e
f564aa8
c7ee0cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FROM golang:alpine AS build-env | ||
# The GOPATH in the image is /go. | ||
ADD . /go/src/github.com/kubeflow/katib | ||
WORKDIR /go/src/github.com/kubeflow/katib/cmd/manager-rest | ||
RUN go build -o vizier-manager-rest | ||
|
||
FROM alpine:3.7 | ||
WORKDIR /app | ||
COPY --from=build-env /go/src/github.com/kubeflow/katib/cmd/manager-rest/vizier-manager-rest /app/ | ||
ENTRYPOINT ["./vizier-manager-rest"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"net/http" | ||
|
||
"github.com/golang/glog" | ||
"golang.org/x/net/context" | ||
"github.com/grpc-ecosystem/grpc-gateway/runtime" | ||
"google.golang.org/grpc" | ||
|
||
gw "github.com/kubeflow/katib/pkg/api" | ||
) | ||
|
||
var ( | ||
vizierCoreEndpoint = flag.String("echo_endpoint", "vizier-core:6789", "vizier-core endpoint") | ||
) | ||
|
||
func run() error { | ||
ctx := context.Background() | ||
ctx, cancel := context.WithCancel(ctx) | ||
defer cancel() | ||
|
||
mux := runtime.NewServeMux() | ||
opts := []grpc.DialOption{grpc.WithInsecure()} | ||
// register handlers for the HTTP endpoints | ||
err := gw.RegisterManagerHandlerFromEndpoint(ctx, mux, *vizierCoreEndpoint, opts) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// proxy server listens on port 80 | ||
return http.ListenAndServe(":80", mux) | ||
} | ||
|
||
func main() { | ||
flag.Parse() | ||
defer glog.Flush() | ||
|
||
if err := run(); err != nil { | ||
glog.Fatal(err) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
## REST API | ||
|
||
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, | ||
|
||
### Create a new Study | ||
|
||
Sample JSON file (study_config.json) | ||
|
||
```json | ||
{ | ||
"name": "study1", | ||
"owner": "mayankjuneja", | ||
"optimization_type": 2, | ||
"optimization_goal": null, | ||
"parameter_configs": { | ||
"configs": [{ | ||
"name": "dropout", | ||
"parameter_type": 1, | ||
"feasible": { | ||
"max": "0.5", | ||
"min": "0.1", | ||
"list": [] | ||
} | ||
}, { | ||
"name": "activation", | ||
"parameter_type": 4, | ||
"feasible": { | ||
"max": "0", | ||
"min": "0", | ||
"list": ["tanh", "relu"] | ||
} | ||
}] | ||
}, | ||
"objective_value_name": "accuracy" | ||
} | ||
``` | ||
|
||
Request: | ||
|
||
```shell | ||
curl -X POST {HOST}/api/Manager/CreateStudy | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Write explicitly to use above json file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, missed the argument here. |
||
``` | ||
|
||
Response: | ||
|
||
```json | ||
{"study_id": "k350afb1ad0e580e"} | ||
``` | ||
|
||
### Get List of Studies | ||
|
||
Request: | ||
```shell | ||
curl -X GET {HOST}/api/Manager/GetStudyList | ||
``` | ||
|
||
Response: | ||
```json | ||
{ | ||
"study_overviews": [ | ||
{ | ||
"name": "study1", | ||
"owner": "mayankjuneja", | ||
"id": "k350afb1ad0e580e" | ||
}, | ||
{ | ||
"name": "study2", | ||
"owner": "mayankjuneja", | ||
"id": "pae3c470c9584cc4" | ||
} | ||
] | ||
} | ||
``` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
apiVersion: extensions/v1beta1 | ||
kind: Deployment | ||
metadata: | ||
name: vizier-core-rest | ||
namespace: katib | ||
labels: | ||
app: vizier | ||
component: core-rest | ||
spec: | ||
replicas: 1 | ||
template: | ||
metadata: | ||
name: vizier-core-rest | ||
labels: | ||
app: vizier | ||
component: core-rest | ||
spec: | ||
serviceAccountName: vizier-core-rest | ||
containers: | ||
- name: vizier-core-rest | ||
image: katib/vizier-core-rest | ||
command: | ||
- './vizier-manager-rest' | ||
ports: | ||
- name: api | ||
containerPort: 80 | ||
# resources: | ||
# requests: | ||
# cpu: 500m | ||
# memory: 500M | ||
# limits: | ||
# cpu: 500m | ||
# memory: 500M |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
apiVersion: extensions/v1beta1 | ||
kind: Ingress | ||
metadata: | ||
name: vizier-core-rest | ||
namespace: katib | ||
annotations: | ||
ingress.kubernetes.io/rewrite-target: / | ||
spec: | ||
rules: | ||
- host: vizier-core-rest.k-cluster.example.net | ||
http: | ||
paths: | ||
- path: / | ||
backend: | ||
serviceName: vizier-core-rest | ||
servicePort: 80 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point, thanks for catching this! |
||
apiVersion: rbac.authorization.k8s.io/v1beta1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: vizier-core-rest | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: vizier-core-rest | ||
subjects: | ||
- kind: ServiceAccount | ||
name: vizier-core-rest | ||
namespace: katib | ||
--- | ||
kind: ClusterRole | ||
apiVersion: rbac.authorization.k8s.io/v1beta1 | ||
metadata: | ||
name: vizier-core-rest | ||
rules: | ||
- apiGroups: [""] | ||
resources: ["pods", "nodes", "nodes/*", "pods/log", "pods/status", "services", "persistentvolumes", "persistentvolumes/status","persistentvolumeclaims","persistentvolumeclaims/status"] | ||
verbs: ["*"] | ||
- apiGroups: ["batch"] | ||
resources: ["jobs", "jobs/status"] | ||
verbs: ["*"] | ||
- apiGroups: ["extensions"] | ||
verbs: ["*"] | ||
resources: ["ingresses","ingresses/status","deployments","deployments/status"] | ||
- apiGroups: [""] | ||
verbs: ["*"] | ||
resources: ["services"] | ||
--- | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: vizier-core-rest | ||
namespace: katib |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: vizier-core-rest | ||
namespace: katib | ||
labels: | ||
app: vizier | ||
component: core-rest | ||
spec: | ||
type: ClusterIP | ||
ports: | ||
- port: 80 | ||
protocol: TCP | ||
name: api | ||
selector: | ||
app: vizier | ||
component: core-rest |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add this.