-
Notifications
You must be signed in to change notification settings - Fork 367
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
Fix dumping OVS flows of a NetworkPolicy #3335
Conversation
Codecov Report
@@ Coverage Diff @@
## main #3335 +/- ##
==========================================
- Coverage 62.13% 53.65% -8.49%
==========================================
Files 266 239 -27
Lines 26519 34037 +7518
==========================================
+ Hits 16477 18261 +1784
- Misses 8222 13996 +5774
+ Partials 1820 1780 -40
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's good to add a test when fixing a bug like this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The title of the PR/commit should mention it's fixing it, i.e. "Fix dumping OVS flows of a NetworkPolicy"
@@ -1455,6 +1455,11 @@ func (c *client) GetNetworkPolicyFlowKeys(npName, npNamespace string) []string { | |||
|
|||
for _, conjObj := range c.policyCache.List() { | |||
conj := conjObj.(*policyRuleConjunction) | |||
// If the NetworkPolicyReference in the policyRuleConjunction is nil then that entry in client's | |||
// policyCache should be ignored because here we need to dump flows of NetworkPolicy. | |||
if conj.npRef == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to explain why the reference could be nil in the comment of this field in the struct.
7a0ceba
to
c3dacc6
Compare
c3dacc6
to
cddadf1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you squash the two commits to one?
pkg/agent/openflow/network_policy.go
Outdated
@@ -525,7 +525,8 @@ type policyRuleConjunction struct { | |||
serviceClause *clause | |||
actionFlows []binding.Flow | |||
metricFlows []binding.Flow | |||
// NetworkPolicy reference information for debugging usage. | |||
// NetworkPolicy reference information for debugging usage, its' value can be nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// NetworkPolicy reference information for debugging usage, its' value can be nil | |
// NetworkPolicy reference information for debugging usage, its value can be nil |
// NetworkPolicy reference information for debugging usage, its' value can be nil | |
// NetworkPolicy reference information for debugging usage, its' value can be nil |
pkg/agent/openflow/network_policy.go
Outdated
@@ -525,7 +525,8 @@ type policyRuleConjunction struct { | |||
serviceClause *clause | |||
actionFlows []binding.Flow | |||
metricFlows []binding.Flow | |||
// NetworkPolicy reference information for debugging usage. | |||
// NetworkPolicy reference information for debugging usage, its' value can be nil | |||
// when a new DNS Conjunction is added to the policyCache. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// when a new DNS Conjunction is added to the policyCache. | |
// for conjunctions that are not built for a specific NetworkPolicy, e.g. DNS packetin Conjunction. |
// dnsID will store the ID for New DNS packet, that is created, | ||
// to test for nil NetworkPolicyReference. | ||
dnsID := uint32(107) | ||
c.NewDNSpacketInConjunction(dnsID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to call this function in the begining of the test to be similar with the actual code. It should check error is nil to ensure it takes effect.
@@ -222,6 +222,10 @@ func TestInstallPolicyRuleFlows(t *testing.T) { | |||
assert.Equal(t, 3, getChangedFlowOPCount(matchFlows2, insertion)) | |||
err = c.applyConjunctiveMatchFlows(ctxChanges2) | |||
require.Nil(t, err) | |||
// dnsID will store the ID for New DNS packet, that is created, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment doesn't reflect the real meaning of the ID, which is the OVS rule ID of the DNS response intercept rule. Here I would suggest to just pass 1 as the ID and comment:
Create a policyRuleConjunction for the dns response interception flows to ensure nil NetworkPolicyReference is handled correctly by GetNetworkPolicyFlowKeys.
f4791e5
to
a6c1efa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks
err := c.NewDNSpacketInConjunction(dnsID) | ||
require.Nil(t, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
require.NoError(t, c.NewDNSpacketInConjunction(dnsID))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the suggestion.
a6c1efa
to
9a46a9a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/test-conformance |
@jainpulkit22 golangci-lint check failed because the comment is not gofmted. |
Fixes antrea-io#3306. This commit fixes the nil pointer dereference error while dumping ovsflows of NetworkPolicy, and adds a test to validate the changes. Signed-off-by: Pulkit Jain <jainpu@vmware.com>
9a46a9a
to
b6389fb
Compare
/test-all |
/test-integration |
Fixes antrea-io#3306. This commit fixes the nil pointer dereference error while dumping ovsflows of NetworkPolicy, and adds a test to validate the changes. Signed-off-by: Pulkit Jain <jainpu@vmware.com>
Fixes #3306.
This PR fixes the nil pointer dereference error while dumping the ovsflows of NetworkPolicy, by adding a nil check on the NetworkPolicyReference attribute of the policyRuleConjunction Object
Signed-off-by: Pulkit Jain jainpu@vmware.com