Skip to content

feat: Adding extension server policy handling. - #3371

Merged
guydc merged 16 commits into
envoyproxy:mainfrom
liorokman:listener-hook-context
May 31, 2024
Merged

guydc merged 16 commits into
envoyproxy:mainfrom
liorokman:listener-hook-context

Conversation

@liorokman

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:
This PR implements extension server policies which can be attached to HTTP listeners.

See the full description in the issue (#2975)

Which issue(s) this PR fixes:
Fixes #2975

@liorokman
liorokman requested a review from a team as a code owner May 11, 2024 15:51
@liorokman
liorokman marked this pull request as draft May 11, 2024 15:51
@liorokman
liorokman force-pushed the listener-hook-context branch from 754eb7b to ee207be Compare May 11, 2024 16:13
@codecov

codecov Bot commented May 12, 2024 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 55.55556% with 124 lines in your changes are missing coverage. Please review.

Project coverage is 67.26%. Comparing base (76c08e6) to head (3772293).
Report is 6 commits behind head on main.

Files Patch % Lines
internal/provider/kubernetes/status.go 3.84% 24 Missing and 1 partial ⚠️
internal/gatewayapi/runner/runner.go 21.42% 20 Missing and 2 partials ⚠️
internal/gatewayapi/resource.go 0.00% 18 Missing ⚠️
internal/provider/kubernetes/controller.go 64.58% 14 Missing and 3 partials ⚠️
internal/extension/registry/xds_hook.go 0.00% 16 Missing ⚠️
internal/gatewayapi/extensionserverpolicy.go 84.90% 10 Missing and 6 partials ⚠️
internal/provider/kubernetes/status_updater.go 25.00% 8 Missing and 1 partial ⚠️
internal/message/types.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3371      +/-   ##
==========================================
- Coverage   67.77%   67.26%   -0.52%     
==========================================
  Files         166      167       +1     
  Lines       20037    20282     +245     
==========================================
+ Hits        13581    13643      +62     
- Misses       5466     5645     +179     
- Partials      990      994       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@liorokman
liorokman force-pushed the listener-hook-context branch 2 times, most recently from e227366 to bc120d8 Compare May 15, 2024 08:50
@liorokman
liorokman marked this pull request as ready for review May 16, 2024 05:09
@guydc

guydc commented May 16, 2024

Copy link
Copy Markdown
Contributor

cc @AliceProxy

@guydc
guydc requested a review from Alice-Lilith May 16, 2024 16:55
@liorokman

Copy link
Copy Markdown
Contributor Author

/retest

2 similar comments
@liorokman

Copy link
Copy Markdown
Contributor Author

/retest

@liorokman

Copy link
Copy Markdown
Contributor Author

/retest

@liorokman
liorokman force-pushed the listener-hook-context branch from d5d5bd9 to 7ba5af2 Compare May 22, 2024 11:02
@liorokman

Copy link
Copy Markdown
Contributor Author

@AliceProxy @arkodg @guydc PTAL

Comment thread internal/gatewayapi/resource.go Resolved
Comment thread internal/utils/field/field.go Resolved
Comment thread internal/provider/kubernetes/status.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets make sure the field matches the type gwapiv1a2.PolicyStatus

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already validated by the compiler.

The val object is provided by the update parameter to the function invoked by the HandleSubscription function. It is a generic type, and it is narrowed to gwapiv1a2.PolicyStatus in line 407:

https://github.com/envoyproxy/gateway/pull/3371/files/cc736cb4086b88cfdfe6db20766a36e847aa4cae#diff-d017a6c31bddedd24ec2acb631ee77e2aab14a461ad17ee416f6563c0253f413R407

Alice-Lilith
Alice-Lilith previously approved these changes May 22, 2024

@Alice-Lilith Alice-Lilith left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No complaints from me. I 👍'd a few of Arko's suggestion, but I don't think this should really break any existing extensions other than needing to update the function signatures when they pull the latest package import with these changes.

@liorokman

Copy link
Copy Markdown
Contributor Author

/retest

1 similar comment
@liorokman

Copy link
Copy Markdown
Contributor Author

/retest

Comment thread internal/gatewayapi/translator.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still seeing the Logger and LoggedErrors being defined here
can we follow the approach taken in the gatewayapi lib where we have a top level errs field e.g.

, in this case it would be in the Translate function and we'd append the errors returned from individual functions e.g.
errs = errors.Join(errs, err)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference is that in BackendTrafficPolicy the errors are aggregated into a single error and then stored in the policy status.

In this policy, the decision was not to update the policy status section for errors, which means that errors would need to be propagated all the way to the runner in order to be logged. This is a pretty large structural change.

I will remove the logger, but I think keeping the LoggedErrors approach is better.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was assuming this would be a best effort approach in the extension manager, but it looks like we've enhanced the gateway api translator to make sure the extension policy is conformant. In that case, lets populate the Status of the policy instead of using LoggedErrors

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When an extension policy doesn't implement the required contract - it has no targetRef or targetRefs attribute in its spec - then it's not possible to correctly place an error message in the policy status section. This is because finding the right place for the condition requires having the targetRef.

I think that there's value in logging this, though, to help with debugging sessions where the user wants to understand why the policy is not being sent to the extension server.

@guydc guydc mentioned this pull request May 24, 2024
@liorokman
liorokman force-pushed the listener-hook-context branch from cca4bda to cd72c97 Compare May 25, 2024 09:18
@liorokman

Copy link
Copy Markdown
Contributor Author

/retest

1 similar comment
@liorokman

Copy link
Copy Markdown
Contributor Author

/retest

liorokman added 16 commits May 30, 2024 17:44
Signed-off-by: Lior Okman <[email protected]>
Signed-off-by: Lior Okman <[email protected]>
Signed-off-by: Lior Okman <[email protected]>
Signed-off-by: Lior Okman <[email protected]>
Signed-off-by: Lior Okman <[email protected]>
Signed-off-by: Lior Okman <[email protected]>
an extension server configured.

Signed-off-by: Lior Okman <[email protected]>
returned errors in the runner.

Signed-off-by: Lior Okman <[email protected]>
@liorokman
liorokman force-pushed the listener-hook-context branch from 5404675 to 3772293 Compare May 30, 2024 18:44
@liorokman

Copy link
Copy Markdown
Contributor Author

/retest

result, err := t.Translate(resources)
if err != nil {
// Currently all errors that Translate returns should just be logged
r.Logger.Error(err, "errors detected during translation")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arkodg
arkodg requested review from a team and Alice-Lilith May 30, 2024 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support ExtensionContextPolicy resources to provide state to Extension Server hooks

4 participants