Skip to content

Commit

Permalink
Merge pull request #22 from jinminhao/buildAnnotations
Browse files Browse the repository at this point in the history
Build annotations and bug fix
  • Loading branch information
jinminhao authored Jan 13, 2021
2 parents 490045c + ef38a97 commit abffb39
Show file tree
Hide file tree
Showing 10 changed files with 320 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ spec:
deploymentName:
maxLength: 64
type: string
port:
format: int32
type: integer
replicas:
format: int32
minimum: 0
type: integer
resources:
properties:
limits:
Expand All @@ -62,6 +55,34 @@ spec:
type: object
runtimeVersion:
type: string
service:
properties:
autoscaler:
enum:
- kpa.autoscaling.knative.dev
- hpa.autoscaling.knative.dev
type: string
maxScale:
type: integer
metric:
enum:
- concurrency
- rps
- cpu
type: string
minScale:
type: integer
panicThreshold:
type: string
panicWindow:
type: string
target:
type: integer
targetUtilization:
type: string
window:
type: string
type: object
storageUri:
type: string
required:
Expand All @@ -78,8 +99,6 @@ spec:
additionalProperties:
type: string
type: object
canaryTraffic:
type: integer
conditions:
items:
properties:
Expand Down Expand Up @@ -114,8 +133,6 @@ spec:
format: int32
minimum: 0
type: integer
traffic:
type: integer
url:
type: string
type: object
Expand Down
64 changes: 64 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,41 @@ metadata:
creationTimestamp: null
name: manager-role
rules:
- apiGroups:
- ""
resources:
- configmaps
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
- events
verbs:
- create
- patch
- apiGroups:
- ""
resources:
- pods
verbs:
- '*'
- apiGroups:
- ""
resources:
- serviceaccounts
verbs:
- create
- get
- list
- apiGroups:
- ""
resources:
- services
verbs:
- '*'
- apiGroups:
- apps
resources:
Expand Down Expand Up @@ -89,3 +117,39 @@ rules:
- patch
- update
- watch
- apiGroups:
- rbac.authorization.k8s.io
resources:
- rolebindings
verbs:
- create
- get
- list
- apiGroups:
- rbac.authorization.k8s.io
resources:
- roles
verbs:
- create
- get
- list
- apiGroups:
- serving.knative.dev
resources:
- services
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- serving.knative.dev
resources:
- services/status
verbs:
- get
- patch
- update
7 changes: 2 additions & 5 deletions config/samples/elasticserving_v1_paddle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ metadata:
namespace: paddleservice-system
spec:
# Add fields here
resources:
requests:
cpu: 80m
deploymentName: paddleservice
replicas: 2
storageUri: hub.baidubce.com/paddlepaddle/serving:latest
runtimeVersion: paddleserving
port: 9292
service:
minScale: 2
# storageUri: nginx:latest
# runtimeVersion: nginx
6 changes: 5 additions & 1 deletion pkg/apis/elasticserving/v1/paddleservice_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ func (ss *PaddleServiceStatus) GetCondition(t apis.ConditionType) *apis.Conditio
return conditionSet.Manage(ss).GetCondition(t)
}

func (ss *PaddleServiceStatus) propagateStatus(conditionType apis.ConditionType, serviceStatus *knservingv1.ServiceStatus) {
func (ss *PaddleServiceStatus) PropagateStatus(serviceStatus *knservingv1.ServiceStatus) {
conditionType := DefaultPaddleServiceReady
statusSpec := StatusConfigurationSpec{}
if ss.Default == nil {
ss.Default = &statusSpec
}
statusSpec.Name = serviceStatus.LatestCreatedRevisionName
serviceCondition := serviceStatus.GetCondition(knservingv1.ServiceConditionReady)

Expand Down
40 changes: 31 additions & 9 deletions pkg/apis/elasticserving/v1/paddleservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,39 @@ type PaddleServiceSpec struct {
// Defaults to requests and limits of 1CPU, 2Gb MEM.
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
// +optional
// +kubebuilder:validation:Minimum=0
Replicas *int32 `json:"replicas,omitempty"`
// Port
Port int32 `json:"port,omitempty"`
Service ServiceSpec `json:"service,omitempty"`
}

// ServiceSpec defines the configuration for Knative Service.
type ServiceSpec struct {
//+optional
Autoscaler Autoscaler `json:"autoscaler,omitempty"`
//+optional
Metric AutoscalerMetric `json:"metric,omitempty"`
//+optional
Window string `json:"window,omitempty"`
//+optional
PanicWindow string `json:"panicWindow,omitempty"`
//+optional
PanicThreshold string `json:"panicThreshold,omitempty"`
//+optional
MinScale *int `json:"minScale,omitempty"`
//+optional
MaxScale int `json:"maxScale,omitempty"`
//+optional
Target int `json:"target,omitempty"`
//+optional
TargetUtilization string `json:"targetUtilization,omitempty"`
}

// Autoscaler defines the autoscaler class
//+kubebuilder:validation:Enum=kpa.autoscaling.knative.dev;hpa.autoscaling.knative.dev
type Autoscaler string

// AutoscalerMetric defines the metric for the autoscaler
//+kubebuilder:validation:Enum=concurrency;rps;cpu
type AutoscalerMetric string

// PaddleServiceStatus defines the observed state of PaddleService
type PaddleServiceStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
Expand All @@ -53,11 +80,6 @@ type PaddleServiceStatus struct {
duckv1beta1.Status `json:",inline"`
// URL of the PaddleService
URL string `json:"url,omitempty"`
// Traffic percentage that goes to default services
Traffic int `json:"traffic,omitempty"`
// Traffic percentage that goes to canary services
CanaryTraffic int `json:"canaryTraffic,omitempty"`

// Statuses for the default endpoints of the PaddleService
Default *StatusConfigurationSpec `json:"default,omitempty"`
// Addressable URL for eventing
Expand Down
26 changes: 21 additions & 5 deletions pkg/apis/elasticserving/v1/zz_generated.deepcopy.go

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

35 changes: 31 additions & 4 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package constants

import (
"knative.dev/serving/pkg/apis/autoscaling"
)

// PaddleService Key
const (
PaddleService = "paddleService"
Expand All @@ -19,10 +23,33 @@ var (

// PaddleService resource defaults
var (
PaddleServiceDefaultCPU = "0.1"
PaddleServiceDefaultMemory = "128Mi"
PaddleServiceDefaultMinScale = 0 // 0 if scale-to-zero is desired
PaddleServiceDefaultMaxScale = 0 // 0 means limitless
PaddleServiceDefaultCPU = "0.1"
PaddleServiceDefaultMemory = "128Mi"
PaddleServiceDefaultMinScale = 1 // 0 if scale-to-zero is desired
PaddleServiceDefaultMaxScale = 10 // 0 means limitless
PaddleServiceDefaultTimeout int64 = 300
PaddleServiceDefaultScalingClass = autoscaling.KPA // kpa or hpa
PaddleServiceDefaultScalingMetric = "concurrency" // concurrency, rps or cpu (hpa required)
PaddleServiceDefaultScalingTarget = 100
PaddleServiceDefaultTargetUtilizationPercentage = "70"
PaddleServiceDefaultWindow = "60s"
PaddleServiceDefaultPanicWindow = "10" // percentage of StableWindow
PaddleServiceDefaultPanicThreshold = "200"
)

var (
ServiceAnnotationsList = []string{
autoscaling.MinScaleAnnotationKey,
autoscaling.MaxScaleAnnotationKey,
autoscaling.ClassAnnotationKey,
autoscaling.MetricAnnotationKey,
autoscaling.TargetAnnotationKey,
autoscaling.TargetUtilizationPercentageKey,
autoscaling.WindowAnnotationKey,
autoscaling.PanicWindowPercentageAnnotationKey,
autoscaling.PanicThresholdPercentageAnnotationKey,
"kubectl.kubernetes.io/last-applied-configuration",
}
)

func DefaultServiceName(name string) string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ func NewServiceReconciler(client client.Client, scheme *runtime.Scheme, configMa
}
}

// +kubebuilder:rbac:groups=serving.knative.dev,resources=services,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=serving.knative.dev,resources=services/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=rbac.authorization.k8s.io,resources=roles,verbs=get;list;create;
// +kubebuilder:rbac:groups=rbac.authorization.k8s.io,resources=rolebindings,verbs=get;list;create;
// +kubebuilder:rbac:groups="",resources=serviceaccounts,verbs=get;list;create;
// +kubebuilder:rbac:groups="",resources=services,verbs=*
// +kubebuilder:rbac:groups="",resources=pods,verbs=*
// +kubebuilder:rbac:groups="",resources=events,verbs=create;patch
// +kubebuilder:rbac:groups="",resources=configmaps,verbs=get;list;watch
// +kubebuilder:rbac:groups=elasticserving.paddlepaddle.org,resources=paddlesvcs,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=elasticserving.paddlepaddle.org,resources=paddlesvcs/status,verbs=get;update;patch

func (r *ServiceReconciler) Reconcile(paddlesvc *elasticservingv1.PaddleService) error {
var service *knservingv1.Service
var err error
Expand All @@ -52,14 +64,17 @@ func (r *ServiceReconciler) Reconcile(paddlesvc *elasticservingv1.PaddleService)
}

// TODO: Modify status
// paddlesvc.Status.PropagateStatus(nil)
return nil
}

if _, err := r.reconcileService(paddlesvc, service); err != nil {
return err
} else {
// TODO: Modify status
// paddlesvc.Status.PropagateStatus(status)
}

// TODO: Modify status
return nil
}

Expand Down
Loading

0 comments on commit abffb39

Please sign in to comment.