Skip to content

Commit 1297c7e

Browse files
require name when creating serving environment (kubeflow#868)
* require name when creating serving env Signed-off-by: Adysen Rothman <[email protected]> * add req field to create Signed-off-by: Adysen Rothman <[email protected]> * make clean install tidy python Signed-off-by: Adysen Rothman <[email protected]> * resolve poetry formatting diffs Signed-off-by: Adysen Rothman <[email protected]> --------- Signed-off-by: Adysen Rothman <[email protected]>
1 parent 67bee30 commit 1297c7e

File tree

16 files changed

+124
-113
lines changed

16 files changed

+124
-113
lines changed

api/openapi/model-registry.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,9 +1687,16 @@ components:
16871687
- $ref: "#/components/schemas/BaseResourceUpdate"
16881688
ServingEnvironmentCreate:
16891689
description: A Model Serving environment for serving `RegisteredModels`.
1690+
required:
1691+
- name
16901692
allOf:
16911693
- $ref: "#/components/schemas/BaseResourceCreate"
16921694
- $ref: "#/components/schemas/ServingEnvironmentUpdate"
1695+
- type: object
1696+
properties:
1697+
name:
1698+
description: The name of the ServingEnvironment.
1699+
type: string
16931700
InferenceService:
16941701
description: >-
16951702
An `InferenceService` entity in a `ServingEnvironment` represents a deployed `ModelVersion` from a `RegisteredModel` created by Model Serving.

clients/python/src/mr_openapi/models/serving_environment.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ class ServingEnvironment(BaseModel):
3535
description="The external id that come from the clients’ system. This field is optional. If set, it must be unique among all resources within a database instance.",
3636
alias="externalId",
3737
)
38-
name: StrictStr | None = Field(
39-
default=None,
40-
description="The client provided name of the artifact. This field is optional. If set, it must be unique among all the artifacts of the same artifact type within a database instance and cannot be changed once set.",
41-
)
38+
name: StrictStr = Field(description="The name of the ServingEnvironment.")
4239
id: StrictStr | None = Field(default=None, description="The unique server generated id of the resource.")
4340
create_time_since_epoch: StrictStr | None = Field(
4441
default=None,

clients/python/src/mr_openapi/models/serving_environment_create.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ class ServingEnvironmentCreate(BaseModel):
3535
description="The external id that come from the clients’ system. This field is optional. If set, it must be unique among all resources within a database instance.",
3636
alias="externalId",
3737
)
38-
name: StrictStr | None = Field(
39-
default=None,
40-
description="The client provided name of the artifact. This field is optional. If set, it must be unique among all the artifacts of the same artifact type within a database instance and cannot be changed once set.",
41-
)
38+
name: StrictStr = Field(description="The name of the ServingEnvironment.")
4239
__properties: ClassVar[list[str]] = ["customProperties", "description", "externalId", "name"]
4340

4441
model_config = ConfigDict(

internal/converter/generated/mlmd_openapi_converter.gen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/converter/generated/openapi_converter.gen.go

Lines changed: 3 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/converter/generated/openapi_mlmd_converter.gen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/converter/mlmd_openapi_converter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type MLMDToOpenAPIConverter interface {
4848
// goverter:map Properties Description | MapDescription
4949
ConvertDocArtifact(source *proto.Artifact) (*openapi.DocArtifact, error)
5050

51-
// goverter:map Name | MapNameFromOwned
51+
// goverter:map Name | MapName
5252
// goverter:map Properties Description | MapDescription
5353
ConvertServingEnvironment(source *proto.Context) (*openapi.ServingEnvironment, error)
5454

internal/mapper/mapper_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func TestMapFromModelArtifactsEmpty(t *testing.T) {
104104
func TestMapFromServingEnvironment(t *testing.T) {
105105
assertion, m := setup(t)
106106

107-
ctx, err := m.MapFromServingEnvironment(&openapi.ServingEnvironment{Name: of("Env")})
107+
ctx, err := m.MapFromServingEnvironment(&openapi.ServingEnvironment{Name: *of("Env")})
108108
assertion.Nil(err)
109109
assertion.Equal("Env", ctx.GetName())
110110
assertion.Equal(servingEnvironmentTypeId, ctx.GetTypeId())

internal/server/openapi/type_asserts.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,15 @@ func AssertServingEnvironmentCreateConstraints(obj model.ServingEnvironmentCreat
815815

816816
// AssertServingEnvironmentCreateRequired checks if the required fields are not zero-ed
817817
func AssertServingEnvironmentCreateRequired(obj model.ServingEnvironmentCreate) error {
818+
elements := map[string]interface{}{
819+
"name": obj.Name,
820+
}
821+
for name, el := range elements {
822+
if isZero := IsZeroValue(el); isZero {
823+
return &RequiredError{Field: name}
824+
}
825+
}
826+
818827
return nil
819828
}
820829

@@ -847,6 +856,15 @@ func AssertServingEnvironmentListRequired(obj model.ServingEnvironmentList) erro
847856

848857
// AssertServingEnvironmentRequired checks if the required fields are not zero-ed
849858
func AssertServingEnvironmentRequired(obj model.ServingEnvironment) error {
859+
elements := map[string]interface{}{
860+
"name": obj.Name,
861+
}
862+
for name, el := range elements {
863+
if isZero := IsZeroValue(el); isZero {
864+
return &RequiredError{Field: name}
865+
}
866+
}
867+
850868
return nil
851869
}
852870

pkg/core/core_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,11 @@ func (suite *CoreTestSuite) registerModel(service api.ModelRegistryApi, override
172172
}
173173

174174
// utility function that register a new simple ServingEnvironment and return its ID
175-
func (suite *CoreTestSuite) registerServingEnvironment(service api.ModelRegistryApi, overrideName *string, overrideExternalId *string) string {
175+
func (suite *CoreTestSuite) registerServingEnvironment(service api.ModelRegistryApi, overrideName string, overrideExternalId *string) string {
176176
eutName := "Simple ServingEnvironment"
177177
eutExtID := "Simple ServingEnvironment ExtID"
178178
eut := &openapi.ServingEnvironment{
179-
Name: &eutName,
179+
Name: eutName,
180180
ExternalId: &eutExtID,
181181
Description: &entityDescription,
182182
CustomProperties: &map[string]openapi.MetadataValue{
@@ -186,7 +186,7 @@ func (suite *CoreTestSuite) registerServingEnvironment(service api.ModelRegistry
186186
},
187187
}
188188

189-
if overrideName != nil {
189+
if overrideName != "" {
190190
eut.Name = overrideName
191191
}
192192

@@ -233,7 +233,7 @@ func (suite *CoreTestSuite) registerModelVersion(
233233
}
234234

235235
// utility function that register a new simple ServingEnvironment and return its ID
236-
func (suite *CoreTestSuite) registerInferenceService(service api.ModelRegistryApi, registerdModelId string, overrideParentResourceName *string, overrideParentResourceExternalId *string, overrideName *string, overrideExternalId *string) string {
236+
func (suite *CoreTestSuite) registerInferenceService(service api.ModelRegistryApi, registerdModelId string, overrideParentResourceName string, overrideParentResourceExternalId *string, overrideName *string, overrideExternalId *string) string {
237237
servingEnvironmentId := suite.registerServingEnvironment(service, overrideParentResourceName, overrideParentResourceExternalId)
238238

239239
eutName := "simpleInferenceService"

0 commit comments

Comments
 (0)