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

Add Action to NetworkPolicy Evaluation response #6112

Merged
merged 1 commit into from
Apr 3, 2024

Conversation

qiyueyao
Copy link
Contributor

As necessary for networkpolicyevaluation consumption, this PR adds the Action field to the above antctl command response.

@qiyueyao qiyueyao requested review from Dyanngg and tnqn March 15, 2024 21:31
}
assert.Equal(t, []string{"testName", "ns", "K8sNetworkPolicy", "10", "In"}, test.GetTableRow(32))
assert.Equal(t, []string{"testName", "ns", "K8sNetworkPolicy", "10", "In", "Allow"}, test.GetTableRow(32))
Copy link
Contributor

Choose a reason for hiding this comment

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

Quite misleading UT. K8s NP should not have action. We should use a testcase to test action "" and another at least to test outputting a real action

Copy link
Contributor Author

@qiyueyao qiyueyao Mar 16, 2024

Choose a reason for hiding this comment

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

That makes sense, but this also reminds me that for the manually inserted K8s default isolation rules, it's better to assign "Drop" to them for identification? Or perhaps an Index of max int is enough?

Copy link
Contributor

Choose a reason for hiding this comment

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

We could add "isolate"

@qiyueyao qiyueyao force-pushed the action-npeval branch 2 times, most recently from c54831e to a317d3a Compare March 18, 2024 21:54
@qiyueyao qiyueyao requested a review from Dyanngg March 19, 2024 22:35
Comment on lines 695 to 697
// RuleActionIsolation indicates that the traffic matching the rule should be
// affected by Kubernetes NetworkPolicy default isolation.
RuleActionIsolation RuleAction = "Isolation"
Copy link
Member

Choose a reason for hiding this comment

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

Trying to understand this. Is this a real action or for other purpose? I feel it sounds a bit confusing. The existing actions are all verbs clearly stating what action will be taken, while "Isolation" describes a state. And I don't get its difference from "Pass".

Copy link
Contributor

Choose a reason for hiding this comment

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

No I did not mean this should be a real action. And I agree that it does not make sense to be added to the CRD action type here. @qiyueyao what we want is simply a "isolate" string in the networkpolicyevaluation result if it is an isolation rule

Copy link
Contributor Author

@qiyueyao qiyueyao Mar 27, 2024

Choose a reason for hiding this comment

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

Understood, one question: if we want this "isolation" also in the API response, or just in the antctl response?
Currently added a step to identify default isolation rules in antctl processing, let me know if we also want it in API response (the place adding a real action, but a string instead of action constant).
Discussed offline: we don't want to add a fake action to API response, just process the response in antctl.

@qiyueyao qiyueyao force-pushed the action-npeval branch 2 times, most recently from 658e7e0 to df954e0 Compare April 2, 2024 18:54
Dyanngg
Dyanngg previously approved these changes Apr 2, 2024
Copy link
Contributor

@Dyanngg Dyanngg left a comment

Choose a reason for hiding this comment

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

LGTM

@qiyueyao
Copy link
Contributor Author

qiyueyao commented Apr 2, 2024

@tnqn @antoninbas Do you have additional comments for setting action field in antctl output after receiving API response? ⬇️
Particularly, filling with "Allow" for K8s NP rule, and "Isolation" for implicit K8s NP isolation.

Copy link
Contributor

@antoninbas antoninbas left a comment

Choose a reason for hiding this comment

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

LGTM, I am fine with Allow / Isolate for K8s NPs

if r.Response.Rule.Action != nil {
action = string(*r.Response.Rule.Action)
} else if r.Response.RuleIndex == math.MaxInt32 {
action = "Isolation"
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 @tnqn suggested Isolate for this one (to stick to a verb), which I also prefer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I misunderstood.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to "Isolate"

}

func (r EvaluationResponse) GetTableRow(_ int) []string {
if r.NetworkPolicyEvaluation != nil && r.Response != nil {
action := "Allow"
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe add a quick comment here explaining that this handling is to account for K8s NPs (r.Response.Rule.Action == nil corresponds to K8s NP "allow" and r.Response.RuleIndex == math.MaxInt32 corresponds to a drop action because of the "default isolation" model).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

@antoninbas antoninbas added the action/release-note Indicates a PR that should be included in release notes. label Apr 2, 2024
As necessary for networkpolicyevaluation consumption, this PR
adds the Action field to the above antctl command response.

Signed-off-by: Qiyue Yao <yaoq@vmware.com>
Copy link
Member

@tnqn tnqn left a comment

Choose a reason for hiding this comment

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

LGTM after s/Isolation/Isolate/

@antoninbas
Copy link
Contributor

/test-all

@antoninbas antoninbas merged commit 933e5cb into antrea-io:main Apr 3, 2024
53 of 56 checks passed
@qiyueyao qiyueyao deleted the action-npeval branch April 3, 2024 23:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/release-note Indicates a PR that should be included in release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants