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 IP based group association query API and ClientSet #4807

Merged
merged 1 commit into from
May 16, 2023

Conversation

Dyanngg
Copy link
Contributor

@Dyanngg Dyanngg commented Apr 4, 2023

This PR adds a new ipgroupassociation API type for querying the Antrea Group/ClusterGroups that an IP is associated with. Possible scenarios include:

  1. IP is assigned to a Pod, in which case the groups that select the Pod as member will be returned
  2. IP appears in an ExternalEntity's endpoints, in which case the groups that select the ExternalEntity as member will be returned
  3. IP is part of an IPBlock that defines the Group/ClusterGroup, in which case the group will be returned.
    (Note that 1 and 3 can simultaneously be true, so as 2 and 3)

Below are examples of how this API can be consumed:

  • Through kubectl proxy (e.g. curl 127.0.0.1:8001/apis/controlplane.antrea.io/v1beta2/ipassociations/10.10.0.1)
  • Through the IPGroupAssociations clientset provided under controlplane/v1beta2

@Dyanngg Dyanngg added this to the Antrea v1.12 release milestone Apr 4, 2023
@Dyanngg Dyanngg force-pushed the ip-association branch 4 times, most recently from 273da07 to 3c745d3 Compare April 6, 2023 21:34
@tnqn tnqn requested a review from GraysonWu May 5, 2023 04:13
@tnqn tnqn added the area/network-policy Issues or PRs related to network policies. label May 9, 2023
pkg/apis/controlplane/register.go Outdated Show resolved Hide resolved
pkg/apiserver/apiserver.go Outdated Show resolved Hide resolved
pkg/apiserver/registry/networkpolicy/ipassociation/rest.go Outdated Show resolved Hide resolved
pkg/apiserver/registry/networkpolicy/ipassociation/rest.go Outdated Show resolved Hide resolved
pkg/apiserver/registry/networkpolicy/ipassociation/rest.go Outdated Show resolved Hide resolved
pkg/apiserver/registry/networkpolicy/ipassociation/rest.go Outdated Show resolved Hide resolved
pkg/apiserver/registry/networkpolicy/ipassociation/rest.go Outdated Show resolved Hide resolved
pkg/apiserver/registry/networkpolicy/ipassociation/rest.go Outdated Show resolved Hide resolved
pkg/controller/grouping/controller.go Outdated Show resolved Hide resolved
@Dyanngg Dyanngg force-pushed the ip-association branch 2 times, most recently from 6ba6d6f to 9484a92 Compare May 9, 2023 23:06
pkg/apis/controlplane/types.go Outdated Show resolved Hide resolved
pkg/apiserver/apiserver.go Outdated Show resolved Hide resolved
pkg/apiserver/registry/networkpolicy/ipassociation/rest.go Outdated Show resolved Hide resolved
pkg/apiserver/registry/networkpolicy/ipassociation/rest.go Outdated Show resolved Hide resolved
pkg/apiserver/registry/networkpolicy/ipassociation/rest.go Outdated Show resolved Hide resolved
pkg/apiserver/registry/networkpolicy/ipassociation/rest.go Outdated Show resolved Hide resolved
pkg/controller/grouping/controller.go Outdated Show resolved Hide resolved
@@ -393,23 +402,34 @@ func (c *NetworkPolicyController) GetAssociatedGroups(name, namespace string) ([

// getAssociatedGroupsByName retrieves the internal Group and all it's parent Group objects
// (if any) by Group name.
func (c *NetworkPolicyController) getAssociatedGroupsByName(grpName string) []antreatypes.Group {
func (c *NetworkPolicyController) getAssociatedGroupsByName(grpName string) ([]antreatypes.Group, error) {
Copy link
Member

Choose a reason for hiding this comment

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

We should clean up such impossible error, instead of adding more. Accessing in-memory indexer can never fail unless there is programming error.

Copy link
Member

Choose a reason for hiding this comment

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

not resolved, assuming thumbs up means agreement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking on solving it in potentially another PR since the error returned by getting parent groups is outside of scope of this PR, and as far as I remember there are other places throwing the same errors as well. But I have refactored all group related ones.

pkg/controller/traceflow/controller.go Outdated Show resolved Hide resolved
@Dyanngg Dyanngg force-pushed the ip-association branch 3 times, most recently from 686d124 to 47f99f5 Compare May 10, 2023 18:50
@Dyanngg
Copy link
Contributor Author

Dyanngg commented May 10, 2023

/test-all

@Dyanngg Dyanngg requested a review from tnqn May 10, 2023 21:10
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.

The PR description needs to update to reflect the new API path. And the same content should be updated to the commit message (note that only commit message gets into the git log).

Besides, the statement "The API can be used by either querying the kubectl proxy (i.e. curl 127.0.0.1:8001/apis/controlplane.antrea.io/v1beta2/ipassociations/10.10.0.1) or by using the IPAssociations clientset provided under controlplane/v1beta2." may be a bit confusing that they are the only two ways to use the API. However, there are plenty ways to use the API as long as a client can reach the API endpoint and has the authroization. The kubectl proxy is just one manner mainly used in development and the generated code itself doesn't automatic resolving the authorization problem. If this is just a guide for testing, you may talk about querying the kubectl proxy with that path as an usage example.

pkg/apiserver/registry/networkpolicy/ipassociation/rest.go Outdated Show resolved Hide resolved
@@ -393,23 +402,34 @@ func (c *NetworkPolicyController) GetAssociatedGroups(name, namespace string) ([

// getAssociatedGroupsByName retrieves the internal Group and all it's parent Group objects
// (if any) by Group name.
func (c *NetworkPolicyController) getAssociatedGroupsByName(grpName string) []antreatypes.Group {
func (c *NetworkPolicyController) getAssociatedGroupsByName(grpName string) ([]antreatypes.Group, error) {
Copy link
Member

Choose a reason for hiding this comment

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

not resolved, assuming thumbs up means agreement.

pkg/apiserver/registry/networkpolicy/ipassociation/rest.go Outdated Show resolved Hide resolved
This commit adds a new ipgroupassociation API type for querying the
Antrea Group/ClusterGroups that an IP is associated with.
Possible scenarios include:

- IP is assigned to a Pod, in which case the groups that select the
  Pod as member will be returned
- IP appears in an ExternalEntity's endpoints, in which case the
  groups that select the ExternalEntity as member will be returned
- IP is part of an IPBlock that defines the Group/ClusterGroup, in
  which case the group will be returned.
  (Note that 1 and 3 can simultaneously be true, so as 2 and 3)

Below are examples of how this API can be consumed:

- Through kubectl proxy (i.e. curl 127.0.0.1:8001/apis/controlplane
  .antrea.io/v1beta2/ipassociations/10.10.0.1)
- Through the IPGroupAssociations clientset provided under
  controlplane/v1beta2

Signed-off-by: Dyanngg <dingyang@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

@tnqn
Copy link
Member

tnqn commented May 15, 2023

@GraysonWu please let us know if you have other comments

@Dyanngg
Copy link
Contributor Author

Dyanngg commented May 15, 2023

/test-all

@tnqn tnqn requested a review from GraysonWu May 16, 2023 05:52
@GraysonWu
Copy link
Contributor

LGTM

@tnqn
Copy link
Member

tnqn commented May 16, 2023

/test-networkpolicy

@tnqn tnqn merged commit e5d4e7f into antrea-io:main May 16, 2023
@tnqn tnqn mentioned this pull request May 22, 2023
ceclinux pushed a commit to ceclinux/antrea that referenced this pull request Jun 5, 2023
This commit adds a new ipgroupassociation API type for querying the
Antrea Group/ClusterGroups that an IP is associated with.
Possible scenarios include:

- IP is assigned to a Pod, in which case the groups that select the
  Pod as member will be returned
- IP appears in an ExternalEntity's endpoints, in which case the
  groups that select the ExternalEntity as member will be returned
- IP is part of an IPBlock that defines the Group/ClusterGroup, in
  which case the group will be returned.
  (Note that 1 and 3 can simultaneously be true, so as 2 and 3)

Below are examples of how this API can be consumed:

- Through kubectl proxy (i.e. curl 127.0.0.1:8001/apis/controlplane
  .antrea.io/v1beta2/ipgroupassociations/10.10.0.1)
- Through the IPGroupAssociations clientset provided under
  controlplane/v1beta2

Signed-off-by: Dyanngg <dingyang@vmware.com>
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants