Skip to content

Latest commit

 

History

History
87 lines (64 loc) · 2.9 KB

user_guide.md

File metadata and controls

87 lines (64 loc) · 2.9 KB

Generate/Update Client Libraries

Clone repos

We maintain the client library and generator in different repositories and to generate libraries, first ensure all the repos are cloned to local. The recommended structure is shown as follow:

.
├── gen
│   ├── openapi
│   └── ...
└── tfjob-java-client
    ├── client
    ├── kubernetes
    ├── examples
    ├── util
    ├── pom.xml
    ├── settings
    └── ...

Clone the gen repo and tfjob-java-client repo from github:

$ export ${CLIENT_GEN_ROOT}=kubeflow-client
$ mkdir ${CLIENT_GEN_ROOT}
$ cd ${CLIENT_GEN_ROOT}
$ git clone https://github.com/kubeflow-incubator/gen.git
$ git clone https://github.com/kubeflow-incubator/tfjob-java-client.git

The gen folder contains some common generator scripts, and codes will be generated to the kubernetes folder at the root of client repo. The file named settings contains all settings, and overwrite it according to your configurations.

Generate library

There are four steps to generate client libraries.

1. generate go model

First we should generate a model from go type definitions. This model can be found at openapi_generated.go and it's generated by the script hack/update-codegen.sh. So if you modified any kubeflow go models, just run update-codegen.sh:

$ cd ${GOPATH}/src/github.com/kubeflow/tf-operator
$ ./hack/update-codegen.sh

And this will update the models in openapi_generated.go.

2. create OpenAPI specification

Then we should create the OpenAPI specification from the model generated in 1. We also need to provide the spec with routing information, which includes standard kubernetes CRUD operations to tfjob. We have built a tool genspec to generate spec from go model automatically, simply use commands below:

$ go install github.com/kubeflow-incubator/genspec
$ cd ${CLIENT_GEN_ROOT}
$ genspec --output gen/openapi/swagger.json

The spec swagger.json must be generated to the path ${CLIENT_GEN_ROOT}/gen/openapi/swaggger.json.

3. generate library

Now, we use gen to generate client library. Make sure all configurations in settings have been set and simply run autoupdate script:

$ cd ${CLIENT_GEN_ROOT}/tfjob-java-client
$ ../gen/openapi/autoupdate.sh

New codes are generated to ${CLIENT_GEN_ROOT}/tfjob-java-client/kubernetes folder.

4. fix errors

There are still some issues should be fixed manually, check all items listed in kubeflow-incubator/tfjob-java-client#7 and fix them one by one. Then run test and make sure no other errors exist.

$ cd ${CLIENT_GEN_ROOT}/tfjob-java-client
$ mvn test