Skip to content

Commit

Permalink
api: custom error response (envoyproxy#4259)
Browse files Browse the repository at this point in the history
* api: custom error response

Relates to envoyproxy#1400

Signed-off-by: Arko Dasgupta <[email protected]>

* address comments

Signed-off-by: Arko Dasgupta <[email protected]>

---------

Signed-off-by: Arko Dasgupta <[email protected]>
  • Loading branch information
arkodg authored Sep 25, 2024
1 parent 77c042c commit 6eefb28
Show file tree
Hide file tree
Showing 6 changed files with 572 additions and 0 deletions.
7 changes: 7 additions & 0 deletions api/v1alpha1/backendtrafficpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ type BackendTrafficPolicySpec struct {
// +optional
// +notImplementedHide
Compression []*Compression `json:"compression,omitempty"`

// ResponseOverride defines the configuration to override specific responses with a custom one.
// If multiple configurations are specified, the first one to match wins.
//
// +optional
// +notImplementedHide
ResponseOverride []*ResponseOverride `json:"responseOverride,omitempty"`
}

// +kubebuilder:object:root=true
Expand Down
79 changes: 79 additions & 0 deletions api/v1alpha1/shared_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,3 +609,82 @@ type HTTP2Settings struct {
// +optional
OnInvalidMessage *InvalidMessageAction `json:"onInvalidMessage,omitempty"`
}

// ResponseOverride defines the configuration to override specific responses with a custom one.
type ResponseOverride struct {
// Match configuration.
Match CustomResponseMatch `json:"match"`
// Response configuration.
Response CustomResponse `json:"response"`
}

// CustomResponseMatch defines the configuration for matching a user response to return a custom one.
type CustomResponseMatch struct {
// Status code to match on. The match evaluates to true if any of the matches are successful.
StatusCode []StatusCodeMatch `json:"statusCode"`
}

// StatusCodeValueType defines the types of values for the status code match supported by Envoy Gateway.
// +kubebuilder:validation:Enum=Value;Range
type StatusCodeValueType string

type StatusCodeMatch struct {
// Type is the type of value.
//
// +kubebuilder:default=Value
// +unionDiscriminator
Type *StatusCodeValueType `json:"type"`

// Value contains the value of the status code.
//
// +optional
Value *string `json:"value,omitempty"`
// ValueRef contains the contents of the body
// specified as a local object reference.
// Only a reference to ConfigMap is supported.
//
// +optional
Range *StatusCodeRange `json:"range,omitempty"`
}

// StatusCodeRange defines the configuration for define a range of status codes.
type StatusCodeRange struct {
// Start of the range, including the start value.
Start int `json:"start"`
// End of the range, including the end value.
End int `json:"end"`
}

// CustomResponse defines the configuration for returning a custom response.
type CustomResponse struct {
// Content Type of the response. This will be set in the Content-Type header.
//
// +optional
ContentType *string `json:"contentType,omitempty"`

// Body of the Custom Response
Body CustomResponseBody `json:"body"`
}

// ResponseValueType defines the types of values for the response body supported by Envoy Gateway.
// +kubebuilder:validation:Enum=Inline;ValueRef
type ResponseValueType string

// CustomResponseBody
type CustomResponseBody struct {
// Type is the type of method to use to read the body value.
//
// +unionDiscriminator
Type *ResponseValueType `json:"type"`

// Inline contains the value as an inline string.
//
// +optional
Inline *string `json:"inline,omitempty"`
// ValueRef contains the contents of the body
// specified as a local object reference.
// Only a reference to ConfigMap is supported.
//
// +optional
ValueRef *gwapiv1.LocalObjectReference `json:"valueRef,omitempty"`
}
146 changes: 146 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,120 @@ spec:
required:
- type
type: object
responseOverride:
description: |-
ResponseOverride defines the configuration to override specific responses with a custom one.
If multiple configurations are specified, the first one to match wins.
items:
description: ResponseOverride defines the configuration to override
specific responses with a custom one.
properties:
match:
description: Match configuration.
properties:
statusCode:
description: Status code to match on. The match evaluates
to true if any of the matches are successful.
items:
properties:
range:
description: |-
ValueRef contains the contents of the body
specified as a local object reference.
Only a reference to ConfigMap is supported.
properties:
end:
description: End of the range, including the end
value.
type: integer
start:
description: Start of the range, including the
start value.
type: integer
required:
- end
- start
type: object
type:
default: Value
description: Type is the type of value.
enum:
- Value
- Range
type: string
value:
description: Value contains the value of the status
code.
type: string
required:
- type
type: object
type: array
required:
- statusCode
type: object
response:
description: Response configuration.
properties:
body:
description: Body of the Custom Response
properties:
inline:
description: Inline contains the value as an inline
string.
type: string
type:
description: Type is the type of method to use to read
the body value.
enum:
- Inline
- ValueRef
type: string
valueRef:
description: |-
ValueRef contains the contents of the body
specified as a local object reference.
Only a reference to ConfigMap is supported.
properties:
group:
description: |-
Group is the group of the referent. For example, "gateway.networking.k8s.io".
When unspecified or empty string, core API group is inferred.
maxLength: 253
pattern: ^$|^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
type: string
kind:
description: Kind is kind of the referent. For example
"HTTPRoute" or "Service".
maxLength: 63
minLength: 1
pattern: ^[a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9])?$
type: string
name:
description: Name is the name of the referent.
maxLength: 253
minLength: 1
type: string
required:
- group
- kind
- name
type: object
required:
- type
type: object
contentType:
description: Content Type of the response. This will be
set in the Content-Type header.
type: string
required:
- body
type: object
required:
- match
- response
type: object
type: array
retry:
description: |-
Retry provides more advanced usage, allowing users to customize the number of retries, retry fallback strategy, and retry triggering conditions.
Expand Down
Loading

0 comments on commit 6eefb28

Please sign in to comment.