Skip to content

Commit

Permalink
Generate sdk for v2
Browse files Browse the repository at this point in the history
  • Loading branch information
pugangxa committed Nov 24, 2021
1 parent 285cb98 commit e273736
Show file tree
Hide file tree
Showing 108 changed files with 5,418 additions and 12,882 deletions.
18 changes: 5 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,21 @@ module github.com/kubeflow/mpi-operator
go 1.13

require (
github.com/emicklei/go-restful v2.9.6+incompatible // indirect
github.com/go-logr/logr v0.3.0 // indirect
github.com/go-openapi/spec v0.20.3
github.com/google/go-cmp v0.5.6 // indirect
github.com/googleapis/gnostic v0.5.1 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/imdario/mergo v0.3.10 // indirect
github.com/kubeflow/common v0.4.0
github.com/onsi/ginkgo v1.14.1 // indirect
github.com/onsi/gomega v1.10.2 // indirect
github.com/kubeflow/mpi-operator/v2 v2.0.0-00010101000000-000000000000
github.com/prometheus/client_golang v1.10.0
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e // indirect
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e // indirect
google.golang.org/appengine v1.6.6 // indirect
k8s.io/api v0.19.9
k8s.io/apimachinery v0.19.9
k8s.io/apiserver v0.19.9
k8s.io/client-go v0.19.9
k8s.io/klog v1.0.0
k8s.io/kube-openapi v0.0.0-20200805222855-6aeccd4b50c6
k8s.io/sample-controller v0.19.9
k8s.io/utils v0.0.0-20200912215256-4140de9c8800 // indirect
volcano.sh/apis v1.2.0-k8s1.19.6
)

replace k8s.io/code-generator => k8s.io/code-generator v0.19.9
replace (
k8s.io/code-generator => k8s.io/code-generator v0.19.9
github.com/kubeflow/mpi-operator/v2 => ./v2
)
106 changes: 106 additions & 0 deletions go.sum

Large diffs are not rendered by default.

32 changes: 24 additions & 8 deletions hack/python-sdk/gen-sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,47 @@ set -o pipefail
SWAGGER_JAR_URL="https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/5.1.0/openapi-generator-cli-5.1.0.jar"
SWAGGER_CODEGEN_JAR="hack/python-sdk/openapi-generator-cli.jar"
SWAGGER_CODEGEN_CONF="hack/python-sdk/swagger_config.json"
SWAGGER_CODEGEN_FILE="pkg/apis/kubeflow/v1/swagger.json"
SWAGGER_V1_CODEGEN_FILE="pkg/apis/kubeflow/v1/swagger.json"
SWAGGER_V2_CODEGEN_FILE="v2/pkg/apis/kubeflow/v2beta1/swagger.json"
SDK_OUTPUT_PATH="sdk/python"

if [ -z "${GOPATH:-}" ]; then
export GOPATH=$(go env GOPATH)
fi

# Backup existing openapi_generated.go
# Backup existing v1 openapi_generated.go
mv pkg/apis/kubeflow/v1/openapi_generated.go pkg/apis/kubeflow/v1/openapi_generated.go.backup

echo "Generating OpenAPI specification ..."
echo "Generating V1 OpenAPI specification ..."
openapi-gen --input-dirs github.com/kubeflow/mpi-operator/pkg/apis/kubeflow/v1,github.com/kubeflow/common/pkg/apis/common/v1 --output-package github.com/kubeflow/mpi-operator/pkg/apis/kubeflow/v1 --go-header-file hack/boilerplate/boilerplate.go.txt

echo "Generating swagger file ..."
go run hack/python-sdk/main.go 0.1 > ${SWAGGER_CODEGEN_FILE}
echo "Generating V1 swagger file ..."
go run hack/python-sdk/main.go V1 v1 > ${SWAGGER_V1_CODEGEN_FILE}

# Backup existing v2 openapi_generated.go
mv v2/pkg/apis/kubeflow/v2beta1/openapi_generated.go v2/pkg/apis/kubeflow/v2beta1/openapi_generated.go.backup

echo "Generating V2 OpenAPI specification ..."
openapi-gen --input-dirs github.com/kubeflow/mpi-operator/v2/pkg/apis/kubeflow/v2beta1,github.com/kubeflow/common/pkg/apis/common/v1 --output-package github.com/kubeflow/mpi-operator/v2/pkg/apis/kubeflow/v2beta1 --go-header-file hack/boilerplate/boilerplate.go.txt

echo "Generating V2 swagger file ..."
go run hack/python-sdk/main.go V2 v2beta1 > ${SWAGGER_V2_CODEGEN_FILE}

echo "Downloading the swagger-codegen JAR package ..."
if ! [ -f ${SWAGGER_CODEGEN_JAR} ]; then
wget -O ${SWAGGER_CODEGEN_JAR} ${SWAGGER_JAR_URL}
fi

echo "Generating Python SDK for Kubeflow MPI-Operator ..."
java -jar ${SWAGGER_CODEGEN_JAR} generate -i ${SWAGGER_CODEGEN_FILE} -g python-legacy -o ${SDK_OUTPUT_PATH} -c ${SWAGGER_CODEGEN_CONF}
echo "Generating V1 Python SDK for Kubeflow MPI-Operator ..."
java -jar ${SWAGGER_CODEGEN_JAR} generate -i ${SWAGGER_V1_CODEGEN_FILE} -g python-legacy -o ${SDK_OUTPUT_PATH}/v1 -c ${SWAGGER_CODEGEN_CONF}

# Rollback the current openapi_generated.go
echo "Generating V2 Python SDK for Kubeflow MPI-Operator ..."
java -jar ${SWAGGER_CODEGEN_JAR} generate -i ${SWAGGER_V2_CODEGEN_FILE} -g python-legacy -o ${SDK_OUTPUT_PATH}/v2beta1 -c ${SWAGGER_CODEGEN_CONF}

# Rollback the current V1 openapi_generated.go
mv pkg/apis/kubeflow/v1/openapi_generated.go.backup pkg/apis/kubeflow/v1/openapi_generated.go

# Rollback the current V2 openapi_generated.go
mv v2/pkg/apis/kubeflow/v2beta1/openapi_generated.go.backup v2/pkg/apis/kubeflow/v2beta1/openapi_generated.go

echo "Kubeflow MPI-Operator Python SDK is generated successfully to folder ${SDK_OUTPUT_PATH}/."
25 changes: 19 additions & 6 deletions hack/python-sdk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,22 @@ import (
"k8s.io/klog"
"k8s.io/kube-openapi/pkg/common"

mpijob "github.com/kubeflow/mpi-operator/pkg/apis/kubeflow/v1"
mpijobv1 "github.com/kubeflow/mpi-operator/pkg/apis/kubeflow/v1"
mpijobv2 "github.com/kubeflow/mpi-operator/v2/pkg/apis/kubeflow/v2beta1"
)

// Generate OpenAPI spec definitions for MPIJob Resource
func main() {
if len(os.Args) <= 1 {
klog.Fatal("Supply a version")
if len(os.Args) <= 2 {
klog.Fatal("Supply the MPIJob version and the swagger spec version")
}
version := os.Args[1]

sdkVersion := os.Args[1]
if sdkVersion != "V1" && sdkVersion != "V2" {
fmt.Println("Only `V1` or `V2` for MPIJob is supported now")
}

version := os.Args[2]
if !strings.HasPrefix(version, "v") {
version = "v" + version
}
Expand All @@ -43,8 +50,12 @@ func main() {
return spec.MustCreateRef(
"#/definitions/" + common.EscapeJsonPointer(swaggify(name)))
}

oAPIDefs := mpijob.GetOpenAPIDefinitions(filter)
var oAPIDefs map[string]common.OpenAPIDefinition
if sdkVersion == "V1" {
oAPIDefs = mpijobv1.GetOpenAPIDefinitions(filter)
} else if sdkVersion == "V2" {
oAPIDefs = mpijobv2.GetOpenAPIDefinitions(filter)
}
defs := spec.Definitions{}
for defName, val := range oAPIDefs {
defs[swaggify(defName)] = val.Schema
Expand Down Expand Up @@ -72,10 +83,12 @@ func main() {

func swaggify(name string) string {
name = strings.Replace(name, "github.com/kubeflow/mpi-operator/pkg/apis/kubeflow/", "", -1)
name = strings.Replace(name, "github.com/kubeflow/mpi-operator/v2/pkg/apis/kubeflow/", "", -1)
name = strings.Replace(name, "github.com/kubeflow/common/pkg/apis/common/", "", -1)
name = strings.Replace(name, "github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/", "", -1)
name = strings.Replace(name, "k8s.io/api/core/", "", -1)
name = strings.Replace(name, "k8s.io/apimachinery/pkg/apis/meta/", "", -1)
name = strings.Replace(name, "k8s.io/apimachinery/pkg/runtime/", "", -1)
name = strings.Replace(name, "k8s.io/apimachinery/pkg/api/", "", -1)
name = strings.Replace(name, "k8s.io/kubernetes/pkg/controller/", "", -1)
name = strings.Replace(name, "k8s.io/client-go/listers/core/", "", -1)
Expand Down
14 changes: 4 additions & 10 deletions pkg/apis/kubeflow/v1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions pkg/apis/kubeflow/v1/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"info": {
"description": "Python SDK for MPI-Operator",
"title": "mpijob",
"version": "v0.1"
"version": "v1"
},
"paths": {},
"definitions": {
Expand Down Expand Up @@ -81,11 +81,11 @@
"type": "object",
"properties": {
"apiVersion": {
"description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources",
"description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
"type": "string"
},
"kind": {
"description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds",
"description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
"type": "string"
},
"metadata": {
Expand All @@ -107,7 +107,7 @@
],
"properties": {
"apiVersion": {
"description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources",
"description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
"type": "string"
},
"items": {
Expand All @@ -117,7 +117,7 @@
}
},
"kind": {
"description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds",
"description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
"type": "string"
},
"metadata": {
Expand Down
1 change: 0 additions & 1 deletion pkg/apis/kubeflow/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pkg/apis/kubeflow/v1/zz_generated.defaults.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 0 additions & 34 deletions sdk/python/setup.py

This file was deleted.

File renamed without changes.
33 changes: 33 additions & 0 deletions sdk/python/v1/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# ref: https://docs.gitlab.com/ee/ci/README.html

stages:
- test

.nosetest:
stage: test
script:
- pip install -r requirements.txt
- pip install -r test-requirements.txt
- pytest --cov=mpijob

nosetest-2.7:
extends: .nosetest
image: python:2.7-alpine
nosetest-3.3:
extends: .nosetest
image: python:3.3-alpine
nosetest-3.4:
extends: .nosetest
image: python:3.4-alpine
nosetest-3.5:
extends: .nosetest
image: python:3.5-alpine
nosetest-3.6:
extends: .nosetest
image: python:3.6-alpine
nosetest-3.7:
extends: .nosetest
image: python:3.7-alpine
nosetest-3.8:
extends: .nosetest
image: python:3.8-alpine
23 changes: 23 additions & 0 deletions sdk/python/v1/.openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
36 changes: 36 additions & 0 deletions sdk/python/v1/.openapi-generator/FILES
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.gitignore
.gitlab-ci.yml
.travis.yml
README.md
docs/V1JobCondition.md
docs/V1JobStatus.md
docs/V1MPIJob.md
docs/V1MPIJobList.md
docs/V1MPIJobSpec.md
docs/V1ReplicaSpec.md
docs/V1ReplicaStatus.md
docs/V1RunPolicy.md
docs/V1SchedulingPolicy.md
git_push.sh
mpijob/__init__.py
mpijob/api/__init__.py
mpijob/api_client.py
mpijob/configuration.py
mpijob/exceptions.py
mpijob/models/__init__.py
mpijob/models/v1_job_condition.py
mpijob/models/v1_job_status.py
mpijob/models/v1_mpi_job.py
mpijob/models/v1_mpi_job_list.py
mpijob/models/v1_mpi_job_spec.py
mpijob/models/v1_replica_spec.py
mpijob/models/v1_replica_status.py
mpijob/models/v1_run_policy.py
mpijob/models/v1_scheduling_policy.py
mpijob/rest.py
requirements.txt
setup.cfg
setup.py
test-requirements.txt
test/__init__.py
tox.ini
1 change: 1 addition & 0 deletions sdk/python/v1/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.1.0
17 changes: 17 additions & 0 deletions sdk/python/v1/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# ref: https://docs.travis-ci.com/user/languages/python
language: python
python:
- "2.7"
- "3.2"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
- "3.7"
- "3.8"
# command to install dependencies
install:
- "pip install -r requirements.txt"
- "pip install -r test-requirements.txt"
# command to run tests
script: pytest --cov=mpijob
Loading

0 comments on commit e273736

Please sign in to comment.