Skip to content

Commit 1fb792e

Browse files
authored
Move generated Python models into kubeflow_trainer_api package (#2632)
Signed-off-by: kramaranya <kramaranya15@gmail.com>
1 parent c333826 commit 1fb792e

367 files changed

Lines changed: 37538 additions & 50 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ exclude: |
2929
sdk/kubeflow/trainer/__init__.py|
3030
sdk/kubeflow/trainer/api/__init__.py|
3131
sdk/kubeflow/trainer/models/.*|
32+
api/python_api/kubeflow_trainer_api/models/.*|
3233
sdk/docs/.*
3334
)$

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,12 @@ manifests: controller-gen ## Generate manifests.
117117
output:rbac:artifacts:config=manifests/base/rbac \
118118
output:webhook:artifacts:config=manifests/base/webhook
119119

120+
## TODO (kramaranya): Remove gen-sdk.sh when moving SDK
120121
.PHONY: generate
121122
generate: go-mod-download manifests ## Generate APIs and SDK.
122123
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate/boilerplate.go.txt" paths="./pkg/apis/..."
123124
hack/update-codegen.sh
125+
hack/python-api/gen-api.sh
124126
hack/python-sdk/gen-sdk.sh
125127

126128
.PHONY: go-mod-download

api/python_api/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Kubeflow Trainer API
2+
3+
Python package containing Kubeflow Trainer API models.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2025 The Kubeflow Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
__version__ = "2.0.0"

api/python_api/kubeflow_trainer_api/models/__init__.py

Lines changed: 374 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# coding: utf-8
2+
3+
"""
4+
Kubeflow Trainer OpenAPI Spec
5+
6+
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
7+
8+
The version of the OpenAPI document: unversioned
9+
Generated by OpenAPI Generator (https://openapi-generator.tech)
10+
11+
Do not edit the class manually.
12+
""" # noqa: E501
13+
14+
15+
from __future__ import annotations
16+
import pprint
17+
import re # noqa: F401
18+
import json
19+
20+
from pydantic import BaseModel, ConfigDict, Field, StrictStr
21+
from typing import Any, ClassVar, Dict, List
22+
from kubeflow_trainer_api.models.io_k8s_api_autoscaling_v2_metric_target import IoK8sApiAutoscalingV2MetricTarget
23+
from typing import Optional, Set
24+
from typing_extensions import Self
25+
26+
class IoK8sApiAutoscalingV2ContainerResourceMetricSource(BaseModel):
27+
"""
28+
ContainerResourceMetricSource indicates how to scale on a resource metric known to Kubernetes, as specified in requests and limits, describing each pod in the current scale target (e.g. CPU or memory). The values will be averaged together before being compared to the target. Such metrics are built in to Kubernetes, and have special scaling options on top of those available to normal per-pod metrics using the \"pods\" source. Only one \"target\" type should be set.
29+
""" # noqa: E501
30+
container: StrictStr = Field(description="container is the name of the container in the pods of the scaling target")
31+
name: StrictStr = Field(description="name is the name of the resource in question.")
32+
target: IoK8sApiAutoscalingV2MetricTarget = Field(description="target specifies the target value for the given metric")
33+
__properties: ClassVar[List[str]] = ["container", "name", "target"]
34+
35+
model_config = ConfigDict(
36+
populate_by_name=True,
37+
validate_assignment=True,
38+
protected_namespaces=(),
39+
)
40+
41+
42+
def to_str(self) -> str:
43+
"""Returns the string representation of the model using alias"""
44+
return pprint.pformat(self.model_dump(by_alias=True))
45+
46+
def to_json(self) -> str:
47+
"""Returns the JSON representation of the model using alias"""
48+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
49+
return json.dumps(self.to_dict())
50+
51+
@classmethod
52+
def from_json(cls, json_str: str) -> Optional[Self]:
53+
"""Create an instance of IoK8sApiAutoscalingV2ContainerResourceMetricSource from a JSON string"""
54+
return cls.from_dict(json.loads(json_str))
55+
56+
def to_dict(self) -> Dict[str, Any]:
57+
"""Return the dictionary representation of the model using alias.
58+
59+
This has the following differences from calling pydantic's
60+
`self.model_dump(by_alias=True)`:
61+
62+
* `None` is only added to the output dict for nullable fields that
63+
were set at model initialization. Other fields with value `None`
64+
are ignored.
65+
"""
66+
excluded_fields: Set[str] = set([
67+
])
68+
69+
_dict = self.model_dump(
70+
by_alias=True,
71+
exclude=excluded_fields,
72+
exclude_none=True,
73+
)
74+
# override the default output from pydantic by calling `to_dict()` of target
75+
if self.target:
76+
_dict['target'] = self.target.to_dict()
77+
return _dict
78+
79+
@classmethod
80+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
81+
"""Create an instance of IoK8sApiAutoscalingV2ContainerResourceMetricSource from a dict"""
82+
if obj is None:
83+
return None
84+
85+
if not isinstance(obj, dict):
86+
return cls.model_validate(obj)
87+
88+
_obj = cls.model_validate({
89+
"container": obj.get("container") if obj.get("container") is not None else '',
90+
"name": obj.get("name") if obj.get("name") is not None else '',
91+
"target": IoK8sApiAutoscalingV2MetricTarget.from_dict(obj["target"]) if obj.get("target") is not None else None
92+
})
93+
return _obj
94+
95+
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# coding: utf-8
2+
3+
"""
4+
Kubeflow Trainer OpenAPI Spec
5+
6+
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
7+
8+
The version of the OpenAPI document: unversioned
9+
Generated by OpenAPI Generator (https://openapi-generator.tech)
10+
11+
Do not edit the class manually.
12+
""" # noqa: E501
13+
14+
15+
from __future__ import annotations
16+
import pprint
17+
import re # noqa: F401
18+
import json
19+
20+
from pydantic import BaseModel, ConfigDict, Field, StrictStr
21+
from typing import Any, ClassVar, Dict, List
22+
from kubeflow_trainer_api.models.io_k8s_api_autoscaling_v2_metric_value_status import IoK8sApiAutoscalingV2MetricValueStatus
23+
from typing import Optional, Set
24+
from typing_extensions import Self
25+
26+
class IoK8sApiAutoscalingV2ContainerResourceMetricStatus(BaseModel):
27+
"""
28+
ContainerResourceMetricStatus indicates the current value of a resource metric known to Kubernetes, as specified in requests and limits, describing a single container in each pod in the current scale target (e.g. CPU or memory). Such metrics are built in to Kubernetes, and have special scaling options on top of those available to normal per-pod metrics using the \"pods\" source.
29+
""" # noqa: E501
30+
container: StrictStr = Field(description="container is the name of the container in the pods of the scaling target")
31+
current: IoK8sApiAutoscalingV2MetricValueStatus = Field(description="current contains the current value for the given metric")
32+
name: StrictStr = Field(description="name is the name of the resource in question.")
33+
__properties: ClassVar[List[str]] = ["container", "current", "name"]
34+
35+
model_config = ConfigDict(
36+
populate_by_name=True,
37+
validate_assignment=True,
38+
protected_namespaces=(),
39+
)
40+
41+
42+
def to_str(self) -> str:
43+
"""Returns the string representation of the model using alias"""
44+
return pprint.pformat(self.model_dump(by_alias=True))
45+
46+
def to_json(self) -> str:
47+
"""Returns the JSON representation of the model using alias"""
48+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
49+
return json.dumps(self.to_dict())
50+
51+
@classmethod
52+
def from_json(cls, json_str: str) -> Optional[Self]:
53+
"""Create an instance of IoK8sApiAutoscalingV2ContainerResourceMetricStatus from a JSON string"""
54+
return cls.from_dict(json.loads(json_str))
55+
56+
def to_dict(self) -> Dict[str, Any]:
57+
"""Return the dictionary representation of the model using alias.
58+
59+
This has the following differences from calling pydantic's
60+
`self.model_dump(by_alias=True)`:
61+
62+
* `None` is only added to the output dict for nullable fields that
63+
were set at model initialization. Other fields with value `None`
64+
are ignored.
65+
"""
66+
excluded_fields: Set[str] = set([
67+
])
68+
69+
_dict = self.model_dump(
70+
by_alias=True,
71+
exclude=excluded_fields,
72+
exclude_none=True,
73+
)
74+
# override the default output from pydantic by calling `to_dict()` of current
75+
if self.current:
76+
_dict['current'] = self.current.to_dict()
77+
return _dict
78+
79+
@classmethod
80+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
81+
"""Create an instance of IoK8sApiAutoscalingV2ContainerResourceMetricStatus from a dict"""
82+
if obj is None:
83+
return None
84+
85+
if not isinstance(obj, dict):
86+
return cls.model_validate(obj)
87+
88+
_obj = cls.model_validate({
89+
"container": obj.get("container") if obj.get("container") is not None else '',
90+
"current": IoK8sApiAutoscalingV2MetricValueStatus.from_dict(obj["current"]) if obj.get("current") is not None else None,
91+
"name": obj.get("name") if obj.get("name") is not None else ''
92+
})
93+
return _obj
94+
95+
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# coding: utf-8
2+
3+
"""
4+
Kubeflow Trainer OpenAPI Spec
5+
6+
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
7+
8+
The version of the OpenAPI document: unversioned
9+
Generated by OpenAPI Generator (https://openapi-generator.tech)
10+
11+
Do not edit the class manually.
12+
""" # noqa: E501
13+
14+
15+
from __future__ import annotations
16+
import pprint
17+
import re # noqa: F401
18+
import json
19+
20+
from pydantic import BaseModel, ConfigDict, Field, StrictStr
21+
from typing import Any, ClassVar, Dict, List, Optional
22+
from typing import Optional, Set
23+
from typing_extensions import Self
24+
25+
class IoK8sApiAutoscalingV2CrossVersionObjectReference(BaseModel):
26+
"""
27+
CrossVersionObjectReference contains enough information to let you identify the referred resource.
28+
""" # noqa: E501
29+
api_version: Optional[StrictStr] = Field(default=None, description="apiVersion is the API version of the referent", alias="apiVersion")
30+
kind: StrictStr = Field(description="kind is the kind of the referent; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds")
31+
name: StrictStr = Field(description="name is the name of the referent; More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names")
32+
__properties: ClassVar[List[str]] = ["apiVersion", "kind", "name"]
33+
34+
model_config = ConfigDict(
35+
populate_by_name=True,
36+
validate_assignment=True,
37+
protected_namespaces=(),
38+
)
39+
40+
41+
def to_str(self) -> str:
42+
"""Returns the string representation of the model using alias"""
43+
return pprint.pformat(self.model_dump(by_alias=True))
44+
45+
def to_json(self) -> str:
46+
"""Returns the JSON representation of the model using alias"""
47+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
48+
return json.dumps(self.to_dict())
49+
50+
@classmethod
51+
def from_json(cls, json_str: str) -> Optional[Self]:
52+
"""Create an instance of IoK8sApiAutoscalingV2CrossVersionObjectReference from a JSON string"""
53+
return cls.from_dict(json.loads(json_str))
54+
55+
def to_dict(self) -> Dict[str, Any]:
56+
"""Return the dictionary representation of the model using alias.
57+
58+
This has the following differences from calling pydantic's
59+
`self.model_dump(by_alias=True)`:
60+
61+
* `None` is only added to the output dict for nullable fields that
62+
were set at model initialization. Other fields with value `None`
63+
are ignored.
64+
"""
65+
excluded_fields: Set[str] = set([
66+
])
67+
68+
_dict = self.model_dump(
69+
by_alias=True,
70+
exclude=excluded_fields,
71+
exclude_none=True,
72+
)
73+
return _dict
74+
75+
@classmethod
76+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
77+
"""Create an instance of IoK8sApiAutoscalingV2CrossVersionObjectReference from a dict"""
78+
if obj is None:
79+
return None
80+
81+
if not isinstance(obj, dict):
82+
return cls.model_validate(obj)
83+
84+
_obj = cls.model_validate({
85+
"apiVersion": obj.get("apiVersion"),
86+
"kind": obj.get("kind") if obj.get("kind") is not None else '',
87+
"name": obj.get("name") if obj.get("name") is not None else ''
88+
})
89+
return _obj
90+
91+

0 commit comments

Comments
 (0)