This repository has been archived by the owner on Sep 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
213df9c
commit bd1cb7d
Showing
8 changed files
with
30,701 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# How to Generate an OpenAPI Spec for PyTorch Operator | ||
|
||
From the root of the repo, | ||
`go run hack/gen-openapi-spec/main.go v0.6 > pkg/apis/pytorch/v1beta2/swagger.json` | ||
|
||
## TODO | ||
|
||
Add instructions for creating an sdk from the swagger.json generated. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
module github.com/kubeflow/pytorch-operator | ||
|
||
go 1.12 | ||
|
||
require ( | ||
cloud.google.com/go v0.36.0 | ||
github.com/PuerkitoBio/purell v1.1.0 | ||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 | ||
github.com/beorn7/perks v1.0.0 | ||
github.com/davecgh/go-spew v1.1.1 | ||
github.com/docker/distribution v0.0.0-20170726174610-edc3ab29cdff | ||
github.com/emicklei/go-restful v2.9.0+incompatible | ||
github.com/ghodss/yaml v1.0.0 | ||
github.com/go-openapi/jsonpointer v0.18.0 | ||
github.com/go-openapi/jsonreference v0.18.0 | ||
github.com/go-openapi/spec v0.18.0 | ||
github.com/go-openapi/swag v0.18.0 | ||
github.com/gogo/protobuf v1.2.0 | ||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b | ||
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef | ||
github.com/golang/protobuf v1.3.1 | ||
github.com/google/btree v1.0.0 | ||
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf | ||
github.com/google/uuid v1.1.1 | ||
github.com/googleapis/gnostic v0.2.0 | ||
github.com/gregjones/httpcache v0.0.0-20190212212710-3befbb6ad0cc | ||
github.com/hashicorp/golang-lru v0.5.0 | ||
github.com/imdario/mergo v0.3.7 | ||
github.com/json-iterator/go v1.1.6 | ||
github.com/konsorten/go-windows-terminal-sequences v1.0.1 | ||
github.com/kubeflow/tf-operator v0.5.3 | ||
github.com/kubernetes-sigs/kube-batch v0.0.0-20190101025100-b0dbd4f2df59 | ||
github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329 | ||
github.com/matttproud/golang_protobuf_extensions v1.0.1 | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd | ||
github.com/modern-go/reflect2 v1.0.1 | ||
github.com/onrik/logrus v0.0.0-20181225141908-a09d5cdcdc62 | ||
github.com/opencontainers/go-digest v1.0.0-rc1 | ||
github.com/pborman/uuid v0.0.0-20180906182336-adf5a7427709 | ||
github.com/petar/GoLLRB v0.0.0-20130427215148-53be0d36a84c | ||
github.com/peterbourgon/diskv v2.0.1+incompatible | ||
github.com/prometheus/client_golang v0.9.4 | ||
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90 | ||
github.com/prometheus/common v0.4.1 | ||
github.com/prometheus/procfs v0.0.2 | ||
github.com/sirupsen/logrus v1.3.0 | ||
github.com/spf13/pflag v1.0.3 | ||
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67 | ||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd | ||
golang.org/x/oauth2 v0.0.0-20190212230446-3e8b2be13635 | ||
golang.org/x/sys v0.0.0-20190209173611-3b5209105503 | ||
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2 | ||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c | ||
golang.org/x/tools v0.0.0-20190213042836-0e66cc6fab8b | ||
google.golang.org/appengine v1.4.0 | ||
gopkg.in/inf.v0 v0.9.1 | ||
gopkg.in/square/go-jose.v2 v2.2.2 | ||
gopkg.in/yaml.v2 v2.2.2 | ||
k8s.io/api v0.0.0-20180712090710-2d6f90ab1293 | ||
k8s.io/apiextensions-apiserver v0.0.0-20180808065829-408db4a50408 | ||
k8s.io/apimachinery v0.0.0-20180621070125-103fd098999d | ||
k8s.io/apiserver v0.0.0-20180808060109-1844acd6a035 | ||
k8s.io/client-go v0.0.0-20180806134042-1f13a808da65 | ||
k8s.io/code-generator v0.0.0-20180621065459-6702109cc68e | ||
k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6 | ||
k8s.io/klog v0.2.0 | ||
k8s.io/kube-openapi v0.0.0-20180509051136-39cb288412c4 | ||
k8s.io/kubernetes v1.11.7 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
Copyright 2019 kubeflow.org. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"log" | ||
"os" | ||
"strings" | ||
|
||
"github.com/go-openapi/spec" | ||
pytorchjobspec "github.com/kubeflow/pytorch-operator/pkg/apis/pytorch/v1beta2" | ||
"k8s.io/kube-openapi/pkg/common" | ||
) | ||
|
||
// Generate OpenAPI spec definitions for KFService Resource | ||
func main() { | ||
if len(os.Args) <= 1 { | ||
log.Fatal("Supply a version") | ||
} | ||
version := os.Args[1] | ||
if !strings.HasPrefix(version, "v") { | ||
version = "v" + version | ||
} | ||
oAPIDefs := pytorchjobspec.GetOpenAPIDefinitions(func(name string) spec.Ref { | ||
return spec.MustCreateRef("#/definitions/" + common.EscapeJsonPointer(swaggify(name))) | ||
}) | ||
defs := spec.Definitions{} | ||
for defName, val := range oAPIDefs { | ||
defs[swaggify(defName)] = val.Schema | ||
} | ||
swagger := spec.Swagger{ | ||
SwaggerProps: spec.SwaggerProps{ | ||
Swagger: "2.0", | ||
Definitions: defs, | ||
Paths: &spec.Paths{Paths: map[string]spec.PathItem{}}, | ||
Info: &spec.Info{ | ||
InfoProps: spec.InfoProps{ | ||
Title: "TFOperator", | ||
Version: version, | ||
}, | ||
}, | ||
}, | ||
} | ||
jsonBytes, err := json.MarshalIndent(swagger, "", " ") | ||
if err != nil { | ||
log.Fatal(err.Error()) | ||
} | ||
fmt.Println(string(jsonBytes)) | ||
} | ||
|
||
// swaggify converts the github package | ||
// e.g.: | ||
// github.com/kubeflow/tf-operator/pkg/apis/tensorflow/v1beta2.TFJob | ||
// to: | ||
// kf.tensorflow.v1beta2.TFJob | ||
func swaggify(name string) string { | ||
name = strings.Replace(name, "github.com/kubeflow/tf-operator/pkg/apis/", "kf", -1) | ||
parts := strings.Split(name, "/") | ||
hostParts := strings.Split(parts[0], ".") | ||
// reverses something like k8s.io to io.k8s | ||
for i, j := 0, len(hostParts)-1; i < j; i, j = i+1, j-1 { | ||
hostParts[i], hostParts[j] = hostParts[j], hostParts[i] | ||
} | ||
parts[0] = strings.Join(hostParts, ".") | ||
return strings.Join(parts, ".") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.