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

Remove child group existence validation for ClusterGroup #2443

Merged
merged 2 commits into from
Aug 2, 2021

Conversation

Dyanngg
Copy link
Contributor

@Dyanngg Dyanngg commented Jul 21, 2021

This is the first of two PRs that relaxes admission validations for ClusterGroup references. This PR removes the restriction that a child ClusterGroup must exist before it can be referred to as childGroup in other ClusterGroups. With this change, the effective member of a nested ClusterGroup will be calculated as the union of its childGroup members, for each childGroup that exist in the cluster.

Note that this PR does not change the max nested level of ClusterGroups, which is 1 at the moment. This means that any ClusterGroup that has a parent cannot be a nested ClusterGroup itself; and reversely, a ClusterGroup cannot select another nested ClusterGroup as its childGroup. This is validated upon creation/update of a ClusterGroup. The order of events matter in this case, as any update which would cause a ClusterGroup nesting over the order of 1 will be rejected.

i.e. if we have 3 ClusterGroups: cg1; cg2: child=cg1; cg3: child=cg2

  1. Creation of cg1, cg2 in whichever order will be allowed. After that, creation of cg3 will not be allowed.
  2. Creation of cg1, cg3 in whichever order will be allowed. After that, creation of cg2 will not be allowed.
  3. Creation of cg2, cg3 in whichever order will be allowed. After that, creation of cg1 will not be allowed.

Tests done:

  1. Creation of CG validation, as specified above
  2. ClusterGroup membership for nested CG whose childGroups all exist, partially exist and none exist.
  3. ACNP with ClusterGroup reference, whose childGroup is then created/updated/deleted.

Signed-off-by: Yang Ding <dingyang@vmware.com>
@Dyanngg Dyanngg requested a review from abhiraut July 21, 2021 04:47
@codecov-commenter
Copy link

codecov-commenter commented Jul 21, 2021

Codecov Report

Merging #2443 (d0b5321) into main (365623f) will increase coverage by 5.01%.
The diff coverage is 77.77%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2443      +/-   ##
==========================================
+ Coverage   59.82%   64.84%   +5.01%     
==========================================
  Files         284      284              
  Lines       22170    25524    +3354     
==========================================
+ Hits        13264    16551    +3287     
+ Misses       7487     7418      -69     
- Partials     1419     1555     +136     
Flag Coverage Δ
e2e-tests 55.79% <77.77%> (?)
kind-e2e-tests 46.87% <0.00%> (-0.21%) ⬇️
unit-tests 42.21% <0.00%> (+0.20%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/controller/networkpolicy/validate.go 74.06% <77.77%> (+54.28%) ⬆️
pkg/agent/agent_linux.go 80.00% <0.00%> (-20.00%) ⬇️
pkg/controller/egress/ipallocator/allocator.go 67.82% <0.00%> (-15.16%) ⬇️
pkg/controller/networkpolicy/endpoint_querier.go 77.64% <0.00%> (-13.79%) ⬇️
pkg/apis/controlplane/v1beta1/conversion.go 72.44% <0.00%> (-11.89%) ⬇️
pkg/util/ip/ip.go 68.67% <0.00%> (-11.63%) ⬇️
pkg/legacyapis/core/v1alpha2/register.go 69.23% <0.00%> (-10.77%) ⬇️
pkg/controller/egress/controller.go 76.76% <0.00%> (-10.44%) ⬇️
pkg/apis/stats/register.go 71.42% <0.00%> (-10.39%) ⬇️
pkg/legacyapis/stats/register.go 71.42% <0.00%> (-10.39%) ⬇️
... and 269 more

@abhiraut
Copy link
Contributor

abhiraut commented Jul 21, 2021

the following cases are most likely handled by the controllers but would like to verify:

  • create CNP (appTo: cgA) first; then create cgA; ensure cgA is reflected in CNP AppliedToGroup
    • Similarly ensure cgA referenced in source/dest groups is reflected in AddressGroups
  • Delete cgA and ensure cgA is removed from CNP AppliedToGroup/AddressGroups

maybe we can add e2e tests for above too

@Dyanngg
Copy link
Contributor Author

Dyanngg commented Jul 21, 2021

the following cases are most likely handled by the controllers but would like to verify:

  • create CNP (appTo: cgA) first; then create cgA; ensure cgA is reflected in CNP AppliedToGroup

    • Similarly ensure cgA referenced in source/dest groups is reflected in AddressGroups
  • Delete cgA and ensure cgA is removed from CNP AppliedToGroup/AddressGroups

maybe we can add e2e tests for above too

Yes those cases are covered and I have added E2E tests for those

@Dyanngg Dyanngg changed the title [WIP] Remove child group existence validation for ClusterGroup Remove child group existence validation for ClusterGroup Jul 21, 2021
@Dyanngg Dyanngg added this to the Antrea v1.3 release milestone Jul 21, 2021
@Dyanngg Dyanngg added the area/network-policy/lifecycle Issues or PRs related to the network policy lifecycle. label Jul 21, 2021
Copy link
Contributor

@jianjuns jianjuns left a comment

Choose a reason for hiding this comment

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

Question - we do not need NetworkPolicyController changes to support child group creation after parent?

@Dyanngg
Copy link
Contributor Author

Dyanngg commented Jul 22, 2021

Question - we do not need NetworkPolicyController changes to support child group creation after parent?

We don't. Before this change, any updates in the childGroup selectors also need to propagate to the parent ClusterGroups, and if those ClusterGroups are used in ACNPs, the effective appliedTo/addressGroups will be updated. Hence the logic is already there.

@jianjuns
Copy link
Contributor

Great!

We don't. Before this change, any updates in the childGroup selectors also need to propagate to the parent ClusterGroups, and if those ClusterGroups are used in ACNPs, the effective appliedTo/addressGroups will be updated. Hence the logic is already there.

abhiraut
abhiraut previously approved these changes Jul 27, 2021
@Dyanngg
Copy link
Contributor Author

Dyanngg commented Jul 28, 2021

/test-all

antoninbas
antoninbas previously approved these changes Jul 30, 2021
@antoninbas
Copy link
Contributor

/test-e2e

@antoninbas
Copy link
Contributor

@Dyanngg the e2e test failure actually seems to be because of this PR

FAIL: TestLegacyClusterGroup/TestLegacyGroupClusterGroupValidate/Case=LegacyInvalidChildGroupName

Signed-off-by: Yang Ding <dingyang@vmware.com>
@Dyanngg Dyanngg dismissed stale reviews from antoninbas and abhiraut via d0b5321 July 30, 2021 18:03
@Dyanngg Dyanngg force-pushed the remove-child-cg-restriction branch from b116be6 to d0b5321 Compare July 30, 2021 18:03
@Dyanngg Dyanngg requested review from abhiraut and antoninbas July 30, 2021 18:04
@Dyanngg
Copy link
Contributor Author

Dyanngg commented Jul 30, 2021

@Dyanngg the e2e test failure actually seems to be because of this PR

FAIL: TestLegacyClusterGroup/TestLegacyGroupClusterGroupValidate/Case=LegacyInvalidChildGroupName

Thanks for the reminder. Yes this is an out of date testcase since we do not validate childGroup existence anymore. Forgot to update the testcase for legacy testgroup. Fixed now. /test-all

@Dyanngg
Copy link
Contributor Author

Dyanngg commented Jul 30, 2021

/test-all

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 Aug 2, 2021

i.e. if we have 3 ClusterGroups: cg1; cg2: child=cg1; cg3: child=cg2

  1. Creation of cg2, cg3 in whichever order will be allowed. After that, creation of cg1 will not be allowed.

I think this is not true? Creating cg3 after cg2 or creating cg2 after cg3 will fail?

@tnqn tnqn merged commit 9222647 into antrea-io:main Aug 2, 2021
antoninbas pushed a commit that referenced this pull request Oct 20, 2022
Signed-off-by: Yang Ding <dingyang@vmware.com>
(cherry picked from commit 9222647)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/network-policy/lifecycle Issues or PRs related to the network policy lifecycle.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants