Skip to content

Commit

Permalink
extproc: adds request/response attributes options
Browse files Browse the repository at this point in the history
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
  • Loading branch information
mathetake committed Oct 22, 2024
1 parent 544bd9c commit 9e7790f
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 0 deletions.
14 changes: 14 additions & 0 deletions api/v1alpha1/ext_proc_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,18 @@ type ExtProc struct {
//
// +optional
ProcessingMode *ExtProcProcessingMode `json:"processingMode,omitempty"`

// RequestAttributes is a list of request attributes that should be sent to the external processor
// on the request_headers message. The possible attributes are defined in the envoy documentation:
// https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes#arch-overview-attributes
//
// +optional
RequestAttributes []string `json:"requestAttributes,omitempty"`

// ResponseAttributes is a list of response attributes that should be sent to the external processor
// on the response_headers message. The possible attributes are defined in the envoy documentation:
// https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes#arch-overview-attributes
//
// +optional
ResponseAttributes []string `json:"responseAttributes,omitempty"`
}
10 changes: 10 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 @@ -940,6 +940,22 @@ spec:
type: string
type: object
type: object
requestAttributes:
description: |-
RequestAttributes is a list of request attributes that should be sent to the external processor
on the request_headers message. The possible attributes are defined in the envoy documentation:
https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes#arch-overview-attributes
items:
type: string
type: array
responseAttributes:
description: |-
ResponseAttributes is a list of response attributes that should be sent to the external processor
on the response_headers message. The possible attributes are defined in the envoy documentation:
https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes#arch-overview-attributes
items:
type: string
type: array
type: object
x-kubernetes-validations:
- message: BackendRefs must be used, backendRef is not supported.
Expand Down
8 changes: 8 additions & 0 deletions internal/gatewayapi/envoyextensionpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,14 @@ func (t *Translator) buildExtProc(
}
}

if extProc.RequestAttributes != nil {
extProcIR.RequestAttributes = extProc.RequestAttributes
}

if extProc.ResponseAttributes != nil {
extProcIR.ResponseAttributes = extProc.ResponseAttributes
}

return extProcIR, err
}

Expand Down
6 changes: 6 additions & 0 deletions internal/ir/xds.go
Original file line number Diff line number Diff line change
Expand Up @@ -2546,6 +2546,12 @@ type ExtProc struct {

// ResponseBodyProcessingMode Defines response body processing
ResponseBodyProcessingMode *ExtProcBodyProcessingMode `json:"responseBodyProcessingMode,omitempty" yaml:"responseBodyProcessingMode,omitempty"`

// RequestAttributes defines the attributes to be sent to the external processor
RequestAttributes []string `json:"requestAttributes,omitempty" yaml:"requestAttributes,omitempty"`

// ResponseAttributes defines the attributes to be sent to the external processor
ResponseAttributes []string `json:"responseAttributes,omitempty" yaml:"responseAttributes,omitempty"`
}

// Wasm holds the information associated with the Wasm extensions.
Expand Down
10 changes: 10 additions & 0 deletions internal/ir/zz_generated.deepcopy.go

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

8 changes: 8 additions & 0 deletions internal/xds/translator/extproc.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ func extProcConfig(extProc ir.ExtProc) *extprocv3.ExternalProcessor {
config.ProcessingMode.ResponseHeaderMode = extprocv3.ProcessingMode_SEND
}

if extProc.RequestAttributes != nil {
config.RequestAttributes = extProc.RequestAttributes
}

if extProc.ResponseAttributes != nil {
config.ResponseAttributes = extProc.ResponseAttributes
}

return config
}

Expand Down
2 changes: 2 additions & 0 deletions test/cel-validation/envoyextensionpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ func TestEnvoyExtensionPolicyTarget(t *testing.T) {
},
},
},
RequestAttributes: []string{"request.path"},
ResponseAttributes: []string{"response.code"},
},
},
PolicyTargetReferences: egv1a1.PolicyTargetReferences{
Expand Down

0 comments on commit 9e7790f

Please sign in to comment.