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

feat: Adding extension server policy handling. #3371

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

liorokman
Copy link
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
Copy link

codecov bot commented May 12, 2024

Codecov Report

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

Project coverage is 67.13%. Comparing base (c2c9b43) to head (62d1a8a).

Files Patch % Lines
internal/gatewayapi/runner/runner.go 22.22% 19 Missing and 2 partials ⚠️
internal/provider/kubernetes/status.go 16.66% 19 Missing and 1 partial ⚠️
internal/gatewayapi/resource.go 0.00% 18 Missing ⚠️
internal/provider/kubernetes/controller.go 63.82% 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/extension/testutils/hooks.go 62.50% 3 Missing and 3 partials ⚠️
internal/message/types.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3371      +/-   ##
==========================================
- Coverage   67.22%   67.13%   -0.10%     
==========================================
  Files         166      167       +1     
  Lines       19720    19961     +241     
==========================================
+ Hits        13257    13400     +143     
- Misses       5507     5590      +83     
- Partials      956      971      +15     

☔ 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
Copy link
Contributor

guydc commented May 16, 2024

cc @AliceProxy

@guydc guydc requested a review from AliceProxy May 16, 2024 16:55
@liorokman
Copy link
Contributor Author

/retest

2 similar comments
@liorokman
Copy link
Contributor Author

/retest

@liorokman
Copy link
Contributor Author

/retest

@liorokman
Copy link
Contributor Author

@AliceProxy @arkodg @guydc PTAL

@@ -56,6 +56,7 @@ type Resources struct {
SecurityPolicies []*egv1a1.SecurityPolicy `json:"securityPolicies,omitempty" yaml:"securityPolicies,omitempty"`
BackendTLSPolicies []*gwapiv1a3.BackendTLSPolicy `json:"backendTLSPolicies,omitempty" yaml:"backendTLSPolicies,omitempty"`
EnvoyExtensionPolicies []*egv1a1.EnvoyExtensionPolicy `json:"envoyExtensionPolicies,omitempty" yaml:"envoyExtensionPolicies,omitempty"`
ExtServerPolicies []unstructured.Unstructured `json:"extServerPolicies,omitempty" yaml:"extServerPolicies,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ExtServerPolicies []unstructured.Unstructured `json:"extServerPolicies,omitempty" yaml:"extServerPolicies,omitempty"`
ExtensionServerPolicies []unstructured.Unstructured `json:"extensionServerPolicies,omitempty" yaml:"extServerPolicies,omitempty"`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

for _, currTarget := range targetRefs {
if currTarget.Kind != KindGateway {
// TODO: mark this targetRef as an error
t.Logger.Sugar().Errorf("extension policy %s doesn't target a Gateway", policy.GetName())
Copy link
Contributor

Choose a reason for hiding this comment

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

we've tried to keep the gateway-api lib as minimal as possible, so it can be reused again in other places in the future, can we instead collect errs here and return and let the runner log them ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

"github.com/envoyproxy/gateway/internal/utils"
)

func (t *Translator) ProcessExtensionServerPolicies(policies []unstructured.Unstructured,
Copy link
Contributor

Choose a reason for hiding this comment

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

I dont see this being used anywhere

This comment was marked as duplicate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is being used in translator.go.

@@ -12,6 +12,22 @@ import (
"unicode"
)

func SetMapValues(input map[string]any, fieldName string, fieldValue any) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we reuse SetValue ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so. SetValue assumes that the input is a struct, this function assumes that the input is a map[string]any.

It's possible to force SetValue to do this, but I don't think that this would make the code clearer.

panic(err)
}
tCopy := t.DeepCopy()
tCopy.Object["status"] = *val
Copy link
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
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

mergeGateways sets.Set[string]
resources *message.ProviderResources
extGVKs []schema.GroupVersionKind
extServerPolicies []schema.GroupVersionKind
Copy link
Contributor

Choose a reason for hiding this comment

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

why not reuse extGVKs here ?

This comment was marked as duplicate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Like @AliceProxy wrote, keeping it separate captures the fact that these GVKs are used for different purposes in different places.

Maybe I should rename extGVKs to extRouteFilters ?

AliceProxy
AliceProxy previously approved these changes May 22, 2024
Copy link
Member

@AliceProxy AliceProxy left a comment

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.

"github.com/envoyproxy/gateway/internal/utils"
)

func (t *Translator) ProcessExtensionServerPolicies(policies []unstructured.Unstructured,

This comment was marked as duplicate.

mergeGateways sets.Set[string]
resources *message.ProviderResources
extGVKs []schema.GroupVersionKind
extServerPolicies []schema.GroupVersionKind

This comment was marked as duplicate.

@liorokman
Copy link
Contributor Author

/retest

1 similar comment
@liorokman
Copy link
Contributor Author

/retest

@@ -101,12 +102,15 @@ type Translator struct {

// Namespace is the namespace that Envoy Gateway runs in.
Namespace string

Logger logging.Logger
Copy link
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
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.

@zirain zirain mentioned this pull request May 25, 2024
Signed-off-by: Lior Okman <lior.okman@sap.com>
Signed-off-by: Lior Okman <lior.okman@sap.com>
Signed-off-by: Lior Okman <lior.okman@sap.com>
Signed-off-by: Lior Okman <lior.okman@sap.com>
runner

Signed-off-by: Lior Okman <lior.okman@sap.com>
Signed-off-by: Lior Okman <lior.okman@sap.com>
Signed-off-by: Lior Okman <lior.okman@sap.com>
Signed-off-by: Lior Okman <lior.okman@sap.com>
Signed-off-by: Lior Okman <lior.okman@sap.com>
Signed-off-by: Lior Okman <lior.okman@sap.com>
Signed-off-by: Lior Okman <lior.okman@sap.com>
Signed-off-by: Lior Okman <lior.okman@sap.com>
Signed-off-by: Lior Okman <lior.okman@sap.com>
Signed-off-by: Lior Okman <lior.okman@sap.com>
@liorokman
Copy link
Contributor Author

/retest

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