Skip to content

Commit

Permalink
refactor: do not use shared schemas in types (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
yetone authored Jun 1, 2023
1 parent 24b4d1e commit c406bf9
Show file tree
Hide file tree
Showing 10 changed files with 188 additions and 72 deletions.
14 changes: 14 additions & 0 deletions apis/serving/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,17 @@ type Resources struct {
Requests *ResourceItem `json:"requests,omitempty"`
Limits *ResourceItem `json:"limits,omitempty"`
}

type DeploymentTargetHPAConf struct {
CPU *int32 `json:"cpu,omitempty"`
GPU *int32 `json:"gpu,omitempty"`
Memory *string `json:"memory,omitempty"`
QPS *int64 `json:"qps,omitempty"`
MinReplicas *int32 `json:"min_replicas,omitempty"`
MaxReplicas *int32 `json:"max_replicas,omitempty"`
}

type LabelItemSchema struct {
Key string `json:"key"`
Value string `json:"value"`
}
60 changes: 59 additions & 1 deletion apis/serving/common/zz_generated.deepcopy.go

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

7 changes: 3 additions & 4 deletions apis/serving/v1alpha1/bentodeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/bentoml/yatai-deployment/apis/serving/common"
"github.com/bentoml/yatai-schemas/modelschemas"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
Expand All @@ -47,9 +46,9 @@ type BentoDeploymentSpec struct {

BentoTag string `json:"bento_tag"`

Resources *common.Resources `json:"resources,omitempty"`
Autoscaling *modelschemas.DeploymentTargetHPAConf `json:"autoscaling,omitempty"`
Envs *[]modelschemas.LabelItemSchema `json:"envs,omitempty"`
Resources *common.Resources `json:"resources,omitempty"`
Autoscaling *common.DeploymentTargetHPAConf `json:"autoscaling,omitempty"`
Envs *[]common.LabelItemSchema `json:"envs,omitempty"`

Runners []BentoDeploymentRunnerSpec `json:"runners,omitempty"`
}
Expand Down
15 changes: 7 additions & 8 deletions apis/serving/v1alpha1/zz_generated.deepcopy.go

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

15 changes: 7 additions & 8 deletions apis/serving/v1alpha2/bentodeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/bentoml/yatai-deployment/apis/serving/common"
"github.com/bentoml/yatai-schemas/modelschemas"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

type BentoDeploymentRunnerSpec struct {
Name string `json:"name,omitempty"`
Resources *common.Resources `json:"resources,omitempty"`
Autoscaling *modelschemas.DeploymentTargetHPAConf `json:"autoscaling,omitempty"`
Envs *[]modelschemas.LabelItemSchema `json:"envs,omitempty"`
Name string `json:"name,omitempty"`
Resources *common.Resources `json:"resources,omitempty"`
Autoscaling *common.DeploymentTargetHPAConf `json:"autoscaling,omitempty"`
Envs *[]common.LabelItemSchema `json:"envs,omitempty"`
}

type BentoDeploymentIngressSpec struct {
Expand All @@ -44,9 +43,9 @@ type BentoDeploymentSpec struct {

BentoTag string `json:"bento_tag"`

Resources *common.Resources `json:"resources,omitempty"`
Autoscaling *modelschemas.DeploymentTargetHPAConf `json:"autoscaling,omitempty"`
Envs *[]modelschemas.LabelItemSchema `json:"envs,omitempty"`
Resources *common.Resources `json:"resources,omitempty"`
Autoscaling *common.DeploymentTargetHPAConf `json:"autoscaling,omitempty"`
Envs *[]common.LabelItemSchema `json:"envs,omitempty"`

Runners []BentoDeploymentRunnerSpec `json:"runners,omitempty"`

Expand Down
26 changes: 12 additions & 14 deletions apis/serving/v1alpha2/zz_generated.deepcopy.go

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

16 changes: 8 additions & 8 deletions apis/serving/v1alpha3/bentodeployment_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ import (
"github.com/bentoml/yatai-common/utils"
resourcesv1alpha1 "github.com/bentoml/yatai-image-builder/apis/resources/v1alpha1"
resourcesclient "github.com/bentoml/yatai-image-builder/generated/resources/clientset/versioned/typed/resources/v1alpha1"
"github.com/bentoml/yatai-schemas/modelschemas"

"github.com/bentoml/yatai-deployment/apis/serving/common"
"github.com/bentoml/yatai-deployment/apis/serving/v2alpha1"
)

func TransformToOldHPA(hpa *v2alpha1.Autoscaling) (oldHpa *modelschemas.DeploymentTargetHPAConf, err error) {
func TransformToOldHPA(hpa *v2alpha1.Autoscaling) (oldHpa *common.DeploymentTargetHPAConf, err error) {
if hpa == nil {
return
}

oldHpa = &modelschemas.DeploymentTargetHPAConf{
oldHpa = &common.DeploymentTargetHPAConf{
MinReplicas: utils.Int32Ptr(hpa.MinReplicas),
MaxReplicas: utils.Int32Ptr(hpa.MaxReplicas),
}
Expand Down Expand Up @@ -82,7 +82,7 @@ func TransformToOldHPA(hpa *v2alpha1.Autoscaling) (oldHpa *modelschemas.Deployme
return
}

func TransformToNewHPA(oldHpa *modelschemas.DeploymentTargetHPAConf) (hpa *v2alpha1.Autoscaling, err error) {
func TransformToNewHPA(oldHpa *common.DeploymentTargetHPAConf) (hpa *v2alpha1.Autoscaling, err error) {
if oldHpa == nil {
return
}
Expand Down Expand Up @@ -219,7 +219,7 @@ func TransformToOldExtraPodSpec(src *v2alpha1.ExtraPodSpec) (dst *ExtraPodSpec)
return
}

func TransformToNewEnvs(oldEnvs *[]modelschemas.LabelItemSchema) (envs []corev1.EnvVar) {
func TransformToNewEnvs(oldEnvs *[]common.LabelItemSchema) (envs []corev1.EnvVar) {
if oldEnvs == nil {
return
}
Expand All @@ -233,18 +233,18 @@ func TransformToNewEnvs(oldEnvs *[]modelschemas.LabelItemSchema) (envs []corev1.
return
}

func TransformToOldEnvs(envs []corev1.EnvVar) (oldEnvs *[]modelschemas.LabelItemSchema) {
func TransformToOldEnvs(envs []corev1.EnvVar) (oldEnvs *[]common.LabelItemSchema) {
if envs == nil {
return
}

oldEnvs_ := []modelschemas.LabelItemSchema{}
oldEnvs_ := []common.LabelItemSchema{}
for _, item := range envs {
if item.Value == "" {
continue
}

oldEnvs_ = append(oldEnvs_, modelschemas.LabelItemSchema{
oldEnvs_ = append(oldEnvs_, common.LabelItemSchema{
Key: item.Name,
Value: item.Value,
})
Expand Down
20 changes: 9 additions & 11 deletions apis/serving/v1alpha3/bentodeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/bentoml/yatai-deployment/apis/serving/common"

"github.com/bentoml/yatai-schemas/modelschemas"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
Expand All @@ -42,12 +40,12 @@ type ExtraPodSpec struct {
}

type BentoDeploymentRunnerSpec struct {
Name string `json:"name,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Resources *common.Resources `json:"resources,omitempty"`
Autoscaling *modelschemas.DeploymentTargetHPAConf `json:"autoscaling,omitempty"`
Envs *[]modelschemas.LabelItemSchema `json:"envs,omitempty"`
Name string `json:"name,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Resources *common.Resources `json:"resources,omitempty"`
Autoscaling *common.DeploymentTargetHPAConf `json:"autoscaling,omitempty"`
Envs *[]common.LabelItemSchema `json:"envs,omitempty"`

// +optional
ExtraPodMetadata *ExtraPodMetadata `json:"extra_pod_metadata,omitempty"`
Expand Down Expand Up @@ -76,9 +74,9 @@ type BentoDeploymentSpec struct {

BentoTag string `json:"bento_tag"`

Resources *common.Resources `json:"resources,omitempty"`
Autoscaling *modelschemas.DeploymentTargetHPAConf `json:"autoscaling,omitempty"`
Envs *[]modelschemas.LabelItemSchema `json:"envs,omitempty"`
Resources *common.Resources `json:"resources,omitempty"`
Autoscaling *common.DeploymentTargetHPAConf `json:"autoscaling,omitempty"`
Envs *[]common.LabelItemSchema `json:"envs,omitempty"`

Runners []BentoDeploymentRunnerSpec `json:"runners,omitempty"`

Expand Down
28 changes: 13 additions & 15 deletions apis/serving/v1alpha3/zz_generated.deepcopy.go

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

Loading

0 comments on commit c406bf9

Please sign in to comment.