Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Istio FaultInjection #1643

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions artifacts/flagger/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,41 @@ spec:
type: array
maxAge:
type: string
FaultInjection:
description: Istio HTTP FaultInjection
type: object
properties:
delay:
description: Delay HTTP requests
type: object
properties:
fixedDelay:
description: The fixed delay to wait before returning a response
type: string
percent:
type: integer
minimum: 0
maximum: 100
percentage:
type: object
properties:
value:
type: number
abort:
description: Abort HTTP requests
type: object
properties:
httpStatus:
description: The HTTP status code to return
type: integer
grpcStatus:
description: The gRPC status code to return
type: string
percentage:
type: object
properties:
value:
type: number
trafficPolicy:
description: Istio traffic policy
type: object
Expand Down
35 changes: 35 additions & 0 deletions charts/flagger/crds/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,41 @@ spec:
type: array
maxAge:
type: string
FaultInjection:
description: Istio HTTP FaultInjection
type: object
properties:
delay:
description: Delay HTTP requests
type: object
properties:
fixedDelay:
description: The fixed delay to wait before returning a response
type: string
percent:
type: integer
minimum: 0
maximum: 100
percentage:
type: object
properties:
value:
type: number
abort:
description: Abort HTTP requests
type: object
properties:
httpStatus:
description: The HTTP status code to return
type: integer
grpcStatus:
description: The gRPC status code to return
type: string
percentage:
type: object
properties:
value:
type: number
trafficPolicy:
description: Istio traffic policy
type: object
Expand Down
35 changes: 35 additions & 0 deletions kustomize/base/flagger/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,41 @@ spec:
type: array
maxAge:
type: string
FaultInjection:
description: Istio HTTP FaultInjection
type: object
properties:
delay:
description: Delay HTTP requests
type: object
properties:
fixedDelay:
description: The fixed delay to wait before returning a response
type: string
percent:
type: integer
minimum: 0
maximum: 100
percentage:
type: object
properties:
value:
type: number
abort:
description: Abort HTTP requests
type: object
properties:
httpStatus:
description: The HTTP status code to return
type: integer
grpcStatus:
description: The gRPC status code to return
type: string
percentage:
type: object
properties:
value:
type: number
trafficPolicy:
description: Istio traffic policy
type: object
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/flagger/v1beta1/canary.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ type CanaryService struct {
// Canary is the metadata to add to the canary service
// +optional
Canary *CustomMetadata `json:"canary,omitempty"`

// fault injection policy for the generated virtual service
// +optional
Fault *istiov1beta1.HTTPFaultInjection `json:"FaultInjection,omitempty"`
}

// CanaryAnalysis is used to describe how the analysis should be done
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/flagger/v1beta1/zz_generated.deepcopy.go

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

16 changes: 13 additions & 3 deletions pkg/apis/istio/v1beta1/virtual_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -850,9 +850,18 @@ type HTTPFaultInjection struct {
// seconds. An optional _percent_ field, a value between 0 and 100, can
// be used to only delay a certain percentage of requests. If left
// unspecified, all request will be delayed.

type PercentagePercent struct {
Value float64 `json:"value,omitempty"`
}

type InjectDelay struct {
// Percentage of requests on which the delay will be injected (0-100).
Percent int `json:"percent,omitempty"`
// Percentage of the traffic to be mirrored by the `mirror` field.
// If this field is absent, all the traffic (100%) will be mirrored.
// Max value is 100.
Percentage *PercentagePercent `json:"percentage,omitempty"`

// REQUIRED. Add a fixed delay before forwarding the request. Format:
// 1h/1m/1s/1ms. MUST be >=1ms.
Expand Down Expand Up @@ -890,11 +899,12 @@ type InjectDelay struct {
// and 100, is used to only abort a certain percentage of requests. If
// not specified, all requests are aborted.
type InjectAbort struct {
// Percentage of requests to be aborted with the error code provided (0-100).
Perecent int `json:"percent,omitempty"`

// REQUIRED. HTTP status code to use to abort the Http request.
HttpStatus int `json:"httpStatus"`
// GRPC status code to use to abort the request
GrpcStatus string `json:"grpcstatus,omitempty"`
// Percentage of requests to be aborted with the error code provided.
Percentage *PercentagePercent `json:"percentage,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
30 changes: 28 additions & 2 deletions pkg/apis/istio/v1beta1/zz_generated.deepcopy.go

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

6 changes: 6 additions & 0 deletions pkg/router/istio.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ func (ir *IstioRouter) reconcileVirtualService(canary *flaggerv1.Canary) error {
Retries: canary.Spec.Service.Retries,
CorsPolicy: canary.Spec.Service.CorsPolicy,
Headers: canary.Spec.Service.Headers,
Fault: canary.Spec.Service.Fault,
Route: canaryRoute,
},
},
Expand Down Expand Up @@ -245,6 +246,7 @@ func (ir *IstioRouter) reconcileVirtualService(canary *flaggerv1.Canary) error {
Retries: canary.Spec.Service.Retries,
CorsPolicy: canary.Spec.Service.CorsPolicy,
Headers: canary.Spec.Service.Headers,
Fault: canary.Spec.Service.Fault,
Route: canaryRoute,
},
{
Expand All @@ -254,6 +256,7 @@ func (ir *IstioRouter) reconcileVirtualService(canary *flaggerv1.Canary) error {
Retries: canary.Spec.Service.Retries,
CorsPolicy: canary.Spec.Service.CorsPolicy,
Headers: canary.Spec.Service.Headers,
Fault: canary.Spec.Service.Fault,
Route: []istiov1beta1.HTTPRouteDestination{
makeDestination(canary, primaryName, 100),
},
Expand Down Expand Up @@ -504,6 +507,7 @@ func (ir *IstioRouter) SetRoutes(
Retries: canary.Spec.Service.Retries,
CorsPolicy: canary.Spec.Service.CorsPolicy,
Headers: canary.Spec.Service.Headers,
Fault: canary.Spec.Service.Fault,
Route: []istiov1beta1.HTTPRouteDestination{
makeDestination(canary, primaryName, primaryWeight),
makeDestination(canary, canaryName, canaryWeight),
Expand Down Expand Up @@ -619,6 +623,7 @@ func (ir *IstioRouter) SetRoutes(
Retries: canary.Spec.Service.Retries,
CorsPolicy: canary.Spec.Service.CorsPolicy,
Headers: canary.Spec.Service.Headers,
Fault: canary.Spec.Service.Fault,
Route: []istiov1beta1.HTTPRouteDestination{
makeDestination(canary, primaryName, primaryWeight),
makeDestination(canary, canaryName, canaryWeight),
Expand All @@ -631,6 +636,7 @@ func (ir *IstioRouter) SetRoutes(
Retries: canary.Spec.Service.Retries,
CorsPolicy: canary.Spec.Service.CorsPolicy,
Headers: canary.Spec.Service.Headers,
Fault: canary.Spec.Service.Fault,
Route: []istiov1beta1.HTTPRouteDestination{
makeDestination(canary, primaryName, primaryWeight),
},
Expand Down