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: Implement target selectors for policies. #3704

Merged
merged 4 commits into from
Jul 3, 2024

Conversation

liorokman
Copy link
Contributor

What this PR does / why we need it:
This PR implements target selectors for policies

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

Signed-off-by: Lior Okman <lior.okman@sap.com>
Signed-off-by: Lior Okman <lior.okman@sap.com>
@liorokman liorokman requested a review from a team as a code owner June 29, 2024 08:46
Signed-off-by: Lior Okman <lior.okman@sap.com>
Copy link

codecov bot commented Jun 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.05%. Comparing base (51c6eb4) to head (f126ce2).
Report is 21 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3704      +/-   ##
==========================================
+ Coverage   68.81%   69.05%   +0.24%     
==========================================
  Files         175      176       +1     
  Lines       21525    21720     +195     
==========================================
+ Hits        14812    14999     +187     
- Misses       5636     5639       +3     
- Partials     1077     1082       +5     

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

@@ -495,3 +496,37 @@ func irConfigName(policy client.Object) string {
strings.ToLower(policy.GetObjectKind().GroupVersionKind().Kind),
utils.NamespacedName(policy).String())
}

func getPolicyTargetRefs[T client.Object](policy egv1a1.PolicyTargetReferences, potentialTargets []T) []gwapiv1a2.LocalPolicyTargetReferenceWithSectionName {
dedup := map[gwapiv1a2.LocalPolicyTargetReferenceWithSectionName]byte{}
Copy link
Contributor

Choose a reason for hiding this comment

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

sets instead ?

}

ret := []gwapiv1a2.LocalPolicyTargetReferenceWithSectionName{}
for key := range dedup {
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 garantee stability of list order with maps or sets ?

Copy link
Contributor

Choose a reason for hiding this comment

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

also is there a way to make this stateless ? we are actively trying to reduce mem usage #3698

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can we garantee stability of list order with maps or sets ?

No. Sets are the same as the builtin maps, since they are implemented in the same way, and they do not guarantee the list order. When transforming the map to a list, I can sort the list. What would be the correct key in which the list should be ordered?

is there a way to make this stateless ? we are actively trying to reduce mem usage

Using a map to deduplicate the set of relevant targets means that the code never allocates more memory than it would need to keep track of the targets of the policy. I don't see a way to collect the targets of the selectors and not keep some state. Note that the memory is only allocated for the duration of the time it takes to handle the policy - it's not some cache that is kept and never released.

Copy link
Contributor

Choose a reason for hiding this comment

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

lets sort based on creation timestamp

	// Sort based on timestamp
	sort.Slice(ret, func(i, j int) bool {
		return ret[i].CreationTimestamp.Before(&(ret[j].CreationTimestamp))
	})
	```

@arkodg arkodg added this to the v1.1.0-rc1 milestone Jul 3, 2024
returned refs are consistent.

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

/retest

Copy link
Contributor

@guydc guydc left a comment

Choose a reason for hiding this comment

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

LGTM, Thanks!

Copy link
Contributor

@arkodg arkodg left a comment

Choose a reason for hiding this comment

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

thanks !

@arkodg arkodg merged commit 93019c3 into envoyproxy:main Jul 3, 2024
27 checks passed
@liorokman liorokman deleted the target-selectors branch July 4, 2024 04:45
@sadovnikov
Copy link
Contributor

@arkodg, @liorokman, I installed v1.1.0-rc.1 and tried to create a SecurityPolicy with the target selectors. It failed on validation. #3901 is logged for this.

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 targetSelectors in Envoy Gateway policies
4 participants