Skip to content

Commit

Permalink
Add CanaryStrategy instead of CanarySteps
Browse files Browse the repository at this point in the history
Signed-off-by: Bryce-Huang <[email protected]>

Signed-off-by: Bryce-Huang <[email protected]>
  • Loading branch information
Bryce-huang committed Sep 15, 2023
1 parent b7203ba commit 8970586
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 63 deletions.
18 changes: 15 additions & 3 deletions apis/core/v1beta2/function_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,23 @@ type FunctionSpec struct {
Build *BuildImpl `json:"build,omitempty"`
// Information needed to run a function. The serving step will be skipped if `Serving` is nil.
Serving *ServingImpl `json:"serving,omitempty"`
// Canary strategy for a function
// +optional
CanaryStrategy *CanaryStrategy `json:"canaryStrategy,omitempty"`
}
type CanaryStrategy struct {
// Canary release steps for a function
// +optional
CanarySteps []CanaryStep `json:"canarySteps,omitempty"`
}

type CanaryStep struct {
// Weight indicate how many percentage of traffic the canary function should receive
// +optional
Weight *int32 `json:"weight,omitempty"`
Pause Pause `json:"pause,omitempty"`
// Pause defines a pause stage for a canary step, manual or auto
// +optional
Pause Pause `json:"pause,omitempty"`
}
type Pause struct {
// Duration the amount of time to wait before moving to the next step.
Expand Down Expand Up @@ -240,8 +251,9 @@ type FunctionStatus struct {
CanaryStatus *CanaryStatus `json:"canaryStatus,omitempty"`
// Addresses holds the addresses that used to access the Function.
// +optional
Addresses []FunctionAddress `json:"addresses,omitempty"`
Revision *Revision `json:"revision,omitempty"`
Addresses []FunctionAddress `json:"addresses,omitempty"`
Revision *Revision `json:"revision,omitempty"`
StableRevision *Revision `json:"stableRevision,omitempty"`
// Sources holds the results emitted from the step definition
// of different sources
//
Expand Down
12 changes: 6 additions & 6 deletions apis/core/v1beta2/function_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ func (r *Function) Validate() error {
"must be specified when `spec.build` is not enabled")
}

if r.Spec.CanarySteps != nil && len(r.Spec.CanarySteps) > 0 {
if err := r.ValidateCanarySteps(field.NewPath("spec", "canarySteps")); err != nil {
if r.Spec.CanaryStrategy != nil && len(r.Spec.CanaryStrategy.CanarySteps) > 0 {
if err := r.ValidCanaryStrategy(field.NewPath("spec", "canaryStrategy")); err != nil {
return err
}
}
Expand Down Expand Up @@ -292,15 +292,15 @@ func (r *Function) ValidateBuild() error {

return nil
}
func (r *Function) ValidateCanarySteps(fldPath *field.Path) error {
steps := r.Spec.CanarySteps
func (r *Function) ValidCanaryStrategy(fldPath *field.Path) error {
steps := r.Spec.CanaryStrategy.CanarySteps
for i, step := range steps {
weight := step.Weight
if weight == nil {
return field.Invalid(fldPath.Index(i).Child("weight"), steps, `Weight cannot be empty`)
return field.Invalid(fldPath.Index(i).Child("canarySteps").Child("weight"), steps, `Weight cannot be empty`)
}
if *weight < 1 || *weight > 100 {
return field.Invalid(fldPath.Index(i).Child("weight"), steps, `Weight cannot be less than 1 or greater than 100`)
return field.Invalid(fldPath.Index(i).Child("canarySteps").Child("weight"), steps, `Weight cannot be less than 1 or greater than 100`)
}
if step.Pause.Duration != nil {
if *step.Pause.Duration < 1 {
Expand Down
86 changes: 68 additions & 18 deletions apis/core/v1beta2/function_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,17 +720,19 @@ func Test_Validate(t *testing.T) {
Serving: &ServingImpl{
Triggers: &Triggers{Http: &HttpTrigger{Engine: (*Engine)(utilpointer.String(string(HttpEngineKnative)))}},
},
CanarySteps: []CanaryStep{
{
Weight: utilpointer.Int32(10),
Pause: Pause{
Duration: utilpointer.Int32(10000),
CanaryStrategy: &CanaryStrategy{
CanarySteps: []CanaryStep{
{
Weight: utilpointer.Int32(10),
Pause: Pause{
Duration: utilpointer.Int32(10000),
},
},
},
{
Weight: utilpointer.Int32(20),
Pause: Pause{
Duration: utilpointer.Int32(10000),
{
Weight: utilpointer.Int32(20),
Pause: Pause{
Duration: utilpointer.Int32(10000),
},
},
},
},
Expand All @@ -745,9 +747,47 @@ func Test_Validate(t *testing.T) {
Serving: &ServingImpl{
Triggers: &Triggers{Http: &HttpTrigger{Engine: (*Engine)(utilpointer.String(string(HttpEngineKnative)))}},
},
CanarySteps: []CanaryStep{
{
Weight: utilpointer.Int32(-1),
CanaryStrategy: &CanaryStrategy{
CanarySteps: []CanaryStep{
{
Weight: utilpointer.Int32(10),
Pause: Pause{
Duration: utilpointer.Int32(10000),
},
},
{
Weight: utilpointer.Int32(20),
Pause: Pause{
Duration: utilpointer.Int32(10000),
},
},
},
},
},
},
wantErr: false,
}, {
name: "function.spec.canarySteps.weight-error",
r: Function{
Spec: FunctionSpec{
Image: "test",
Serving: &ServingImpl{
Triggers: &Triggers{Http: &HttpTrigger{Engine: (*Engine)(utilpointer.String(string(HttpEngineKnative)))}},
},
CanaryStrategy: &CanaryStrategy{
CanarySteps: []CanaryStep{
{
Weight: utilpointer.Int32(20),
Pause: Pause{
Duration: utilpointer.Int32(10000),
},
},
{
Weight: utilpointer.Int32(10),
Pause: Pause{
Duration: utilpointer.Int32(10000),
},
},
},
},
},
Expand All @@ -761,15 +801,25 @@ func Test_Validate(t *testing.T) {
Serving: &ServingImpl{
Triggers: &Triggers{Http: &HttpTrigger{Engine: (*Engine)(utilpointer.String(string(HttpEngineKnative)))}},
},
CanarySteps: []CanaryStep{
{
Weight: utilpointer.Int32(10),
Pause: Pause{Duration: utilpointer.Int32(-1)},
CanaryStrategy: &CanaryStrategy{
CanarySteps: []CanaryStep{
{
Weight: utilpointer.Int32(10),
Pause: Pause{
Duration: utilpointer.Int32(10000),
},
},
{
Weight: utilpointer.Int32(20),
Pause: Pause{
Duration: utilpointer.Int32(10000),
},
},
},
},
},
},
wantErr: true,
wantErr: false,
},
}

Expand Down
37 changes: 31 additions & 6 deletions apis/core/v1beta2/zz_generated.deepcopy.go

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

39 changes: 26 additions & 13 deletions config/bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11557,23 +11557,31 @@ spec:
required:
- srcRepo
type: object
canarySteps:
description: Canary release steps for a function
items:
properties:
pause:
canaryStrategy:
description: Canary strategy for a function
properties:
canarySteps:
description: Canary release steps for a function
items:
properties:
duration:
description: Duration the amount of time to wait before
moving to the next step.
pause:
description: Pause defines a pause stage for a canary step,
manual or auto
properties:
duration:
description: Duration the amount of time to wait before
moving to the next step.
format: int32
type: integer
type: object
weight:
description: Weight indicate how many percentage of traffic
the canary function should receive
format: int32
type: integer
type: object
weight:
format: int32
type: integer
type: object
type: array
type: array
type: object
image:
description: Function image name
type: string
Expand Down Expand Up @@ -21356,6 +21364,11 @@ spec:
- name
type: object
type: array
stableRevision:
properties:
imageDigest:
type: string
type: object
stableServing:
properties:
buildDuration:
Expand Down
39 changes: 26 additions & 13 deletions config/crd/bases/core.openfunction.io_functions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9835,23 +9835,31 @@ spec:
required:
- srcRepo
type: object
canarySteps:
description: Canary release steps for a function
items:
properties:
pause:
canaryStrategy:
description: Canary strategy for a function
properties:
canarySteps:
description: Canary release steps for a function
items:
properties:
duration:
description: Duration the amount of time to wait before
moving to the next step.
pause:
description: Pause defines a pause stage for a canary step,
manual or auto
properties:
duration:
description: Duration the amount of time to wait before
moving to the next step.
format: int32
type: integer
type: object
weight:
description: Weight indicate how many percentage of traffic
the canary function should receive
format: int32
type: integer
type: object
weight:
format: int32
type: integer
type: object
type: array
type: array
type: object
image:
description: Function image name
type: string
Expand Down Expand Up @@ -19634,6 +19642,11 @@ spec:
- name
type: object
type: array
stableRevision:
properties:
imageDigest:
type: string
type: object
stableServing:
properties:
buildDuration:
Expand Down
Loading

0 comments on commit 8970586

Please sign in to comment.