-
Notifications
You must be signed in to change notification settings - Fork 700
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
Update scripts to generate sdk for all frameworks #1389
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,26 +23,48 @@ import ( | |
"strings" | ||
|
||
"github.com/go-openapi/spec" | ||
mxJob "github.com/kubeflow/tf-operator/pkg/apis/mxnet/v1" | ||
pytorchJob "github.com/kubeflow/tf-operator/pkg/apis/pytorch/v1" | ||
tfjob "github.com/kubeflow/tf-operator/pkg/apis/tensorflow/v1" | ||
xgboostJob "github.com/kubeflow/tf-operator/pkg/apis/xgboost/v1" | ||
"k8s.io/klog" | ||
"k8s.io/kube-openapi/pkg/common" | ||
) | ||
|
||
// Generate OpenAPI spec definitions for TFJob Resource | ||
func main() { | ||
if len(os.Args) <= 1 { | ||
klog.Fatal("Supply a version") | ||
if len(os.Args) <= 2 { | ||
klog.Fatal("Supply a framework and version") | ||
} | ||
version := os.Args[1] | ||
framework := os.Args[1] | ||
version := os.Args[2] | ||
if !strings.HasPrefix(version, "v") { | ||
version = "v" + version | ||
} | ||
oAPIDefs := tfjob.GetOpenAPIDefinitions(func(name string) spec.Ref { | ||
return spec.MustCreateRef("#/definitions/" + common.EscapeJsonPointer(swaggify(name))) | ||
}) | ||
var oAPIDefs map[string]common.OpenAPIDefinition | ||
|
||
switch framework { | ||
case "tensorflow": | ||
oAPIDefs = tfjob.GetOpenAPIDefinitions(func(name string) spec.Ref { | ||
return spec.MustCreateRef("#/definitions/" + common.EscapeJsonPointer(swaggify(name, framework))) | ||
}) | ||
case "pytorch": | ||
oAPIDefs = pytorchJob.GetOpenAPIDefinitions(func(name string) spec.Ref { | ||
return spec.MustCreateRef("#/definitions/" + common.EscapeJsonPointer(swaggify(name, framework))) | ||
}) | ||
case "mxnet": | ||
oAPIDefs = mxJob.GetOpenAPIDefinitions(func(name string) spec.Ref { | ||
return spec.MustCreateRef("#/definitions/" + common.EscapeJsonPointer(swaggify(name, framework))) | ||
}) | ||
case "xgboost": | ||
oAPIDefs = xgboostJob.GetOpenAPIDefinitions(func(name string) spec.Ref { | ||
return spec.MustCreateRef("#/definitions/" + common.EscapeJsonPointer(swaggify(name, framework))) | ||
}) | ||
} | ||
Comment on lines
+46
to
+63
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. @kubeflow/wg-training-leads Do we want to have to have multiple or one Swagger for each framework? 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. You mean compress all swagger into a big one? 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. Yes, I am just thinking what is the best way to locate these swaggers. 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. We still need to generate each for different framework. Then I mixin into one and use it to generate SDK. |
||
|
||
defs := spec.Definitions{} | ||
for defName, val := range oAPIDefs { | ||
defs[swaggify(defName)] = val.Schema | ||
defs[swaggify(defName, framework)] = val.Schema | ||
} | ||
swagger := spec.Swagger{ | ||
SwaggerProps: spec.SwaggerProps{ | ||
|
@@ -51,8 +73,8 @@ func main() { | |
Paths: &spec.Paths{Paths: map[string]spec.PathItem{}}, | ||
Info: &spec.Info{ | ||
InfoProps: spec.InfoProps{ | ||
Title: "tfjob", | ||
Description: "Python SDK for TF-Operator", | ||
Title: framework, | ||
Description: fmt.Sprintf("Python SDK for %v", framework), | ||
Version: version, | ||
}, | ||
}, | ||
|
@@ -65,15 +87,9 @@ func main() { | |
fmt.Println(string(jsonBytes)) | ||
} | ||
|
||
func swaggify(name string) string { | ||
name = strings.Replace(name, "github.com/kubeflow/tf-operator/pkg/apis/tensorflow/", "", -1) | ||
name = strings.Replace(name, "github.com/kubeflow/common/job_controller/api/", "", -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/kubernetes/pkg/controller/", "", -1) | ||
name = strings.Replace(name, "k8s.io/client-go/listers/core/", "", -1) | ||
name = strings.Replace(name, "k8s.io/client-go/util/workqueue", "", -1) | ||
func swaggify(name, framework string) string { | ||
name = strings.Replace(name, fmt.Sprintf("github.com/kubeflow/tf-operator/pkg/apis/%s/", framework), "", -1) | ||
name = strings.Replace(name, "github.com/kubeflow/common/pkg/apis/common/", "", -1) | ||
name = strings.Replace(name, "/", ".", -1) | ||
return name | ||
} |
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.
@Jeffwan We might need to generate OpenAPI Definition for our APIs to avoid corev1 definition as you mentioned here: #1389 (comment).
Then, our Swagger will have only Training related APIs.
What do you think ?
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.
@andreyvelich
Yeah. I think this is the problem. Not sure what corev1 are populated. Do you have any ideas? Seems something is misconfigured in this
hack/python-sdk/main.go
?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.
Do we need to use
code-generator
to generate it ? Similar to this: https://github.com/kubeflow/katib/blob/master/hack/update-openapigen.sh#L49-L53.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.
Yeah. Same tool. I update the
--input-dirs
to exclude those unrelated files. Thanks @andreyvelich