-
Notifications
You must be signed in to change notification settings - Fork 386
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 NetworkPolicyReference to controlplane NetworkPolicy #1258
Conversation
Thanks for your PR. The following commands are available:
|
Codecov Report
@@ Coverage Diff @@
## master #1258 +/- ##
==========================================
- Coverage 56.29% 55.04% -1.26%
==========================================
Files 109 110 +1
Lines 12045 10597 -1448
==========================================
- Hits 6781 5833 -948
+ Misses 4673 4191 -482
+ Partials 591 573 -18
Flags with carried forward coverage won't be shown. Click here to find out more.
|
dba53fe
to
1e09de0
Compare
/test-all |
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
/cc @suwang48404 .. note this changes the message of internal network policies |
var rules []*rule | ||
for _, obj := range objs { | ||
rule := obj.(*rule) | ||
if rule.PolicyRef.Name == npName { |
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.
How is K8s NP and ANP differentiated here? If there were NP and ANP with same ns/name, wouldn't rules for both those policies be added to rules
still?
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.
Good catch, I tried to fix it but it seems not a simple fix as antctl never expects Antrea Policies before. I filed #1262 and listed existing issues. As this interface is consumed by antctl only, I would prefer addressing it with a separate PR for antctl. What do you think?
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.
I agree. cc @GraysonWu as he is working on antctl support for ClusterNetworkPolicy. This PR and issue #1262 should be relevant
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.
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.
thanks @Dyanngg @abhiraut @GraysonWu for taking care of this.
c9a9367
to
0633e8f
Compare
/test-all |
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.
Question - this is not a compatible API changes right? @tnqn
i think this is one case where we may need to handle versioning ? |
2da539d
to
3fa5ac8
Compare
b117ec1
to
9bec8cd
Compare
@jianjuns @abhiraut I'm going to update PR's description to reflect the latest compatibility impact, posting previous impact and proposal here: Compatibility impact if we change controlplane NetworkPolicy to cluster scope and use UID as name directly:
If we want to keep complete backward-compatibility for all clients, maybe we could do the following:
|
/test-all |
@tnqn I agreed with the two-stages approach you proposed. We can decide later how to address other issues and whether to increase API group version. |
The approach looks good, but I'd like to understand how this will fix #1173 in v0.10? It seems that ANP and K8s NP can still overwrite each other in the store as we are still using the same Name & Namespace in the internal policy object and we didn't update the store key function? |
@antoninbas It cannot fix #1173 and is only the first step that makes current internal API consumers not rely on the name and namespace of controlplane networkpolicy, and a prerequisite of supporting NetworkPolicy metrics/status. Changing key function or the name of controlplane networkpolicy may introduce little troubles to upgrade and backward compatibility as listed in #1258 (comment), though none of them are really serious, and we don't know its impact on external API consumers (cloud case) yet. As ANP is still alpha, do you think we could defer the fix to next release? |
@tnqn yes, sounds good. I was just double-checking that this was not indeed a fix |
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.
just one suggestion to improve a comment, otherwise LGTM
// Reference to the original NetworkPolicy that the rule belongs to. | ||
// Note it has different meaning from PolicyUID, PolicyName, and | ||
// PolicyNamespace which are the metadata of controlplane NetworkPolicy. | ||
// Although they are same for now, it might change in future, features that | ||
// need the information of the original NetworkPolicy should use SourceRef. | ||
SourceRef *v1beta1.NetworkPolicyReference |
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 has a different meaning
which are the metadata fields of the corresponding controlplane NetworkPolicy
it might change in the future
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.
done, thanks!
I was really hoping we could fix the issue in this release but i understand that it may not be enough time for us to implement v1beta2 versioning here.. lets target it for 0.11 .. in the middle of reviewing this PR |
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.
one question. lgtm otherwise
func (r *CompletedRule) isAntreaNetworkPolicyRule() bool { | ||
return r.PolicyPriority != nil | ||
return r.SourceRef.Type != v1beta1.K8sNetworkPolicy |
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.
do we need to be careful in terms of using this field right after upgrade .. ie what happens if the controller was not yet upgraded and agent was ? i.e. is sourceRef guaranteed to be not nil in such cases?
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.
If upgrading by applying yaml, the old controller pod should be removed immediately so there should be no chance that new agent can talk to old controller. For other integrated solutions, we also assume controller is upgraded first. We may need a doc like https://kubernetes.io/docs/setup/release/version-skew-policy/#supported-component-upgrade-order to document it officially. It could be a part of #1273 which is tracking the version policy.
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.
i think we recommend controller upgrade first followed by agents.. so we should be good
NetworkPolicy in controlplane API group is the object that consumed by antrea-agents. Both Antrea NetworkPolicy and K8s NetworkPolicy will be converted to it. Currently, the namespace and name of the original NetworkPolicy are copied to the controlplane NetworkPolicy and <Namespace>/<Name> is used as the key func. Therefore, one K8s NetworkPolicy may overwrite the controlplane NetworkPolicy mapping to a Antrea NetworkPolicy that has the same namespace and name. To fix it completely, the original NetworkPolicy name will not be used as the controlplane NetworkPolicy name directly. However, antrea-agents still need to know the information about the original NetworkPolicy for multiple purposes, e.g. metrics and realization status report, and traceflow observation correlation. To keep backward compatibility, this patch adds a new field "SourceRef" that includes the information about the original NetworkPolicy to the struct of controlplane NetworkPolicy. Instead of assuming controlplane NetworkPolicy has the same name as the original NetworkPolicy, antrea-agents consumes the new field to get the information about the original NetworkPolicy.
/test-all |
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-windows-conformance |
/test-windows-conformance |
/test-windows-networkpolicy |
1 similar comment
/test-windows-networkpolicy |
NetworkPolicy in controlplane API group is the object that consumed by antrea-agents. Both Antrea NetworkPolicy and K8s NetworkPolicy will be converted to it. Currently, the namespace and name of the original NetworkPolicy are copied to the controlplane NetworkPolicy and <Namespace>/<Name> is used as the key func. Therefore, one K8s NetworkPolicy may overwrite the controlplane NetworkPolicy mapping to a Antrea NetworkPolicy that has the same namespace and name.
To fix it completely, the original NetworkPolicy name will not be used as the controlplane NetworkPolicy name directly. However, antrea-agents still need to know the information about the original NetworkPolicy for multiple purposes, e.g. metrics and realization status report, and traceflow observation correlation.
To keep backward compatibility, this patch adds a new field "SourceRef" that includes the information about the original NetworkPolicy to the struct of controlplane NetworkPolicy. Instead of assuming controlplane NetworkPolicy has the same name as the original NetworkPolicy, antrea-agents consumes the new field to get the information about the original NetworkPolicy.
For #1173 and #1172
Compatibility impact: None