From 4868de27a6a6563cf8ed31155682c5c16a497bda Mon Sep 17 00:00:00 2001 From: Ellis Tarn Date: Wed, 3 Apr 2019 14:34:50 -0700 Subject: [PATCH] Added KFService types (#8) * Added KFService types * Added Canary as a top level spec and fixed a few optional fields --- pkg/apis/serving/v1alpha1/kfservice_types.go | 153 +++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 pkg/apis/serving/v1alpha1/kfservice_types.go diff --git a/pkg/apis/serving/v1alpha1/kfservice_types.go b/pkg/apis/serving/v1alpha1/kfservice_types.go new file mode 100644 index 00000000000..6ad308eeb25 --- /dev/null +++ b/pkg/apis/serving/v1alpha1/kfservice_types.go @@ -0,0 +1,153 @@ +/* +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 v1alpha1 + +import ( + v1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// KFServiceSpec defines the desired state of KFService +type KFServiceSpec struct { + MinReplicas int32 `json:"minReplicas"` + MaxReplicas int32 `json:"maxReplicas"` + + Default ModelSpec `json:"default"` + // Optional Canary definition + Canary *CanarySpec `json:"canary,omitempty"` +} + +// ModelSpec defines the default configuration to route traffic. +type ModelSpec struct { + // The following fields follow a "1-of" semantic. Users must specify exactly one spec. + Custom *CustomSpec `json:"custom,omitempty"` + Tensorflow *TensorflowSpec `json:"tensorflow,omitempty"` + XGBoost *XGBoostSpec `json:"xgBoost,omitempty"` + ScikitLearn *ScikitLearnSpec `json:"scikitLearn,omitempty"` +} + +// CanarySpec defines an alternate configuration to route a percentage of traffic. +type CanarySpec struct { + ModelSpec `json:",inline"` + TrafficPercent int32 `json:"trafficPercent"` +} + +// TensorflowSpec defines arguments for configuring Tensorflow model serving. +type TensorflowSpec struct { + ModelUri string `json:"modelUri"` + // Defaults to latest TF Version. + RuntimeVersion string `json:"runtimeVersion,omitempty"` + // Defaults to requests and limits of 1CPU, 2Gb MEM. + Resources v1.ResourceRequirements `json:"resources,omitempty"` +} + +// XGBoostSpec defines arguments for configuring XGBoost model serving. +type XGBoostSpec struct { + ModelUri string `json:"modelUri"` + // Defaults to latest XGBoost Version. + RuntimeVersion string `json:"runtimeVersion,omitempty"` + // Defaults to requests and limits of 1CPU, 2Gb MEM. + Resources v1.ResourceRequirements `json:"resources,omitempty"` +} + +// ScikitLearnSpec defines arguments for configuring ScikitLearn model serving. +type ScikitLearnSpec struct { + ModelURI string `json:"modelUri"` + // Defaults to latest ScikitLearn Version. + RuntimeVersion string `json:"runtimeVersion,omitempty"` + // Defaults to requests and limits of 1CPU, 2Gb MEM. + Resources v1.ResourceRequirements `json:"resources,omitempty"` +} + +// CustomSpec provides a hook for arbitrary container configuration. +type CustomSpec struct { + Container v1.Container `json:"container"` +} + +// KFServiceStatus defines the observed state of KFService +type KFServiceStatus struct { + Conditions StatusConditionsSpec `json:"conditions,omitempty"` + URI URISpec `json:"uri,omitempty"` + Default StatusConfigurationSpec `json:"default,omitempty"` + Canary StatusConfigurationSpec `json:"canary,omitempty"` +} + +// URISpec describes the available network endpoints for the service. +type URISpec struct { + Internal string `json:"internal,omitempty"` + External string `json:"external,omitempty"` +} + +// StatusConfigurationSpec describes the state of the configuration receiving traffic. +type StatusConfigurationSpec struct { + Name string `json:"name,omitempty"` + Replicas int `json:"replicas,omitempty"` + Traffic int `json:"traffic,omitempty"` +} + +// StatusConditionsSpec displays the current conditions of the resource. +type StatusConditionsSpec struct { + Type ConditionType `json:"type"` + Status v1.ConditionStatus `json:"status"` + + // Last time the condition was probed. + LastProbeTime metav1.Time `json:"lastProbeTime,omitempty" protobuf:"bytes,3,opt,name=lastProbeTime"` + // Last time the condition transitioned from one status to another. + LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty" protobuf:"bytes,4,opt,name=lastTransitionTime"` + // Unique, one-word, CamelCase reason for the condition's last transition. + Reason string `json:"reason,omitempty"` + // Human-readable message indicating details about last transition. + Message string `json:"message,omitempty"` +} + +// ConditionType is the of status conditions. +type ConditionType string + +// These are valid conditions of a service. +const ( + Ready ConditionType = "Ready" + RoutingReady ConditionType = "RoutingReady" + ResourcesAvailable ConditionType = "ResourcesAvailabe" + ContainerHealthy ConditionType = "ContainerHealthy" + RevisionReady ConditionType = "RevisionReady" +) + +// +genclient +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// KFService is the Schema for the services API +// +k8s:openapi-gen=true +type KFService struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec KFServiceSpec `json:"spec,omitempty"` + Status KFServiceStatus `json:"status,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// KFServiceList contains a list of Service +type KFServiceList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []KFService `json:"items"` +} + +func init() { + SchemeBuilder.Register(&KFService{}, &KFServiceList{}) +}