Skip to content

Add From/To fields in SecurityPolicy#1391

Open
wenqiq wants to merge 8 commits intovmware-tanzu:mainfrom
wenqiq:topic/wenqi/securityPolicy
Open

Add From/To fields in SecurityPolicy#1391
wenqiq wants to merge 8 commits intovmware-tanzu:mainfrom
wenqiq:topic/wenqi/securityPolicy

Conversation

@wenqiq
Copy link
Contributor

@wenqiq wenqiq commented Mar 12, 2026

No description provided.

Signed-off-by: Wenqi Qiu <wenqi.qiu@broadcom.com>
@codecov-commenter
Copy link

codecov-commenter commented Mar 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.79%. Comparing base (4ba0355) to head (8359c7b).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1391      +/-   ##
==========================================
+ Coverage   76.74%   76.79%   +0.04%     
==========================================
  Files         151      151              
  Lines       21307    21342      +35     
==========================================
+ Hits        16353    16389      +36     
  Misses       3784     3784              
+ Partials     1170     1169       -1     
Flag Coverage Δ
unit-tests 76.79% <100.00%> (+0.04%) ⬆️
Files with missing lines Coverage Δ
pkg/nsx/services/securitypolicy/builder.go 87.59% <100.00%> (+0.11%) ⬆️
pkg/nsx/services/securitypolicy/expand.go 73.19% <100.00%> (+0.34%) ⬆️
pkg/nsx/services/securitypolicy/firewall.go 72.24% <100.00%> (+0.42%) ⬆️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@wenqiq wenqiq marked this pull request as ready for review March 17, 2026 13:37
Signed-off-by: Wenqi Qiu <wenqi.qiu@broadcom.com>
Sources []SecurityPolicyPeer `json:"sources,omitempty"`
// Destinations defines the endpoints where the traffic is to. For egress rule only.
Destinations []SecurityPolicyPeer `json:"destinations,omitempty"`
// From is an alias of Sources for ingress rules.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is for T1 mode, I think we don't need to change it, it's in deprecated stage.

for compatibility with Kubernetes NetworkPolicy style syntax. `from` can be used in
place of `sources` for ingress rules, and `to` can be used in place of `destinations`
for egress rules. If both `sources` and `from` (or `destinations` and `to`) are set
in the same rule, `sources`/`destinations` takes precedence and the alias is ignored.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should take From/To take precedence because we want to deprecate sources/destinations

// fields so that rule hashing and tagging are independent of which alias the user used.
func normalizeRulePeers(rule *v1alpha1.SecurityPolicyRule) {
if len(rule.Sources) == 0 && len(rule.From) > 0 {
rule.Sources = append(rule.Sources, rule.From...)
Copy link
Contributor

Choose a reason for hiding this comment

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

we might want to keep rule.From and remove rule.Sources later, so, is better copy to rule.From.
This might need more changes where it's referring to rule.Source.

rule.Sources = append(rule.Sources, rule.From...)
}
if len(rule.Destinations) == 0 && len(rule.To) > 0 {
rule.Destinations = append(rule.Destinations, rule.To...)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto.

wenqiq added 6 commits March 19, 2026 21:26
Signed-off-by: Wenqi Qiu <wenqi.qiu@broadcom.com>
Signed-off-by: Wenqi Qiu <wenqi.qiu@broadcom.com>
Signed-off-by: Wenqi Qiu <wenqi.qiu@broadcom.com>
Signed-off-by: Wenqi Qiu <wenqi.qiu@broadcom.com>
Signed-off-by: Wenqi Qiu <wenqi.qiu@broadcom.com>
Signed-off-by: Wenqi Qiu <wenqi.qiu@broadcom.com>
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.

3 participants