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 nodeSelector support in ClusterGroup #7040

Open
luolanzone opened this issue Mar 3, 2025 · 4 comments
Open

Add nodeSelector support in ClusterGroup #7040

luolanzone opened this issue Mar 3, 2025 · 4 comments
Assignees
Labels
area/network-policy Issues or PRs related to network policies. kind/feature Categorizes issue or PR as related to a new feature. reported-by/end-user Issues reported by end users.

Comments

@luolanzone
Copy link
Contributor

luolanzone commented Mar 3, 2025

There is a use case reported from the end user that four clusters are sharing one API service IP (shared one controller plane?) in their env. The user wants to set up ACNPs to make sure only selected Pods are allowed to the K8s API Service, so he/she created a ClusterGroup with pod and namespace selector matching kube-apiserver labels, however, due to the Antrea-controller would omit the hostNetwork Pods in ClusterGroup members, it doesn't meet their requirement.

In order to allow users to create ACNPs to do the right network policy control in such scenarios, it would be good to have nodeSelector support in ClusterGroup.

@luolanzone
Copy link
Contributor Author

cc @tnqn @edwardbadboy in case I missed any critical information.

@antoninbas antoninbas added reported-by/end-user Issues reported by end users. area/network-policy Issues or PRs related to network policies. kind/feature Categorizes issue or PR as related to a new feature. labels Mar 4, 2025
@luolanzone
Copy link
Contributor Author

This is to make the selector consistent on ACNP and ClusterGroup. We now already support nodeSelector in ACNP, but not in ClusterGroup.

@Dyanngg
Copy link
Contributor

Dyanngg commented Mar 18, 2025

I want to clarify the scope for this change here:

  1. nodeSelector is supported in ACNP both in ingress/egress rules and in appliedTo. However, the appliedTo case is a gated feature: when an ACNP has nodeSelector in appliedTo, it becomes a NodeNetworkPolicy. Currently this feature is in alpha and not enabled by default. So we need to determine how to deal with nodeSelector CG reference as appliedTo in ACNP: one idea is to check for feature flag enablement in an ACNP webhook if a nodeSelector CG is used in the appliedTo of an ACNP. This however introduces strong dependency of resources: we currently do not validate whether a CG exists at the time when it is referenced in an ACNP being created. I don’t feel this feature should break this… Another idea would be allow this combination to be applied in the cluster in the first place, then when Antrea controller process the ACNP, it marks the policy unrealizable in its status. @antoninbas @tnqn what do you guys think?
  2. Also just to confirm that the ask is only to add the nodeSelector in cluster-scope resources, and not namespaced ‘Group’ and ‘ANNP’ references, since it would not make sense for creating a namespaced nodeSelector.
  3. Antrea provides the ClusterGroupMember and IPGroupAssociation APIs for ClusterGroups. Should we extend these to support nodeSelector case? I.e. display Node info in ClusterGroupMember queries, and be able to reverse look up CGs by node IP

@antoninbas
Copy link
Contributor

Even today, the NodeNetworkPolicy FeatureGate only exists for the Agent. So a nodeSelector in the appliedTo field is always processed the same way in the Controller: the selector is resolved to a list of Nodes and each Node in the list will get the policy.

@Dyanngg do you want to limit the nodeSelector field to ClusterGroups used as peers (and not allow such a ClusterGroup to be used in an appliedTo)? This is what we do for groups with IPBlocks today. I think this is the use case we are trying to address here. It would greatly simplify the implementation IMO. Otherwise, if we want to allow such groups for appliedTo, we have to have some restrictions, or things can get pretty complicated if a group can have children, with one child selecting Nodes and one child selecting Pods...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/network-policy Issues or PRs related to network policies. kind/feature Categorizes issue or PR as related to a new feature. reported-by/end-user Issues reported by end users.
Projects
None yet
Development

No branches or pull requests

4 participants