Skip to content

Commit

Permalink
use http trigger as the default trigger
Browse files Browse the repository at this point in the history
Signed-off-by: wanjunlei <wanjunlei@kubesphere.io>
  • Loading branch information
wanjunlei committed May 26, 2023
1 parent da591c7 commit f1eafee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
21 changes: 15 additions & 6 deletions apis/core/v1beta2/function_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,21 @@ func (r *Function) Default() {
r.Spec.Version = &version
}

if r.Spec.Serving.Triggers == nil {
r.Spec.Serving.Triggers = &Triggers{}
}

if len(r.Spec.Serving.Triggers.Dapr) == 0 {
if r.Spec.Serving.Triggers.Http == nil {
r.Spec.Serving.Triggers.Http = &HttpTrigger{}
}

if r.Spec.Serving.Triggers.Http.Port == nil || *r.Spec.Serving.Triggers.Http.Port == 0 {
port := int32(constants.DefaultFuncPort)
r.Spec.Serving.Triggers.Http.Port = &port
}
}

if r.Spec.Serving != nil &&
r.Spec.Serving.Triggers != nil &&
r.Spec.Serving.Triggers.Http != nil {
Expand Down Expand Up @@ -267,12 +282,6 @@ func (r *Function) ValidateBuild() error {
}

func (r *Function) ValidateServing() error {
if r.Spec.Serving.Triggers.Http == nil &&
(r.Spec.Serving.Triggers.Dapr == nil || len(r.Spec.Serving.Triggers.Dapr) == 0) {
return field.Required(field.NewPath("spec", "serving", "Triggers"),
"must specify one of: `http` or `dapr`")
}

if r.Spec.Serving.ScaleOptions != nil {
scaleOptions := r.Spec.Serving.ScaleOptions
minReplicas := int32(0)
Expand Down
4 changes: 2 additions & 2 deletions apis/core/v1beta2/serving_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ type Exporter struct {
}

type ServingImpl struct {
// Triggers used to trigge the Function.
// Triggers used to trigger the Function.
// +optional
Triggers *Triggers `json:"triggers"`
Triggers *Triggers `json:"triggers,omitempty"`
// The ScaleOptions will help us to set up guidelines for the autoscaling of function workloads.
// +optional
ScaleOptions *ScaleOptions `json:"scaleOptions,omitempty"`
Expand Down

0 comments on commit f1eafee

Please sign in to comment.