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

Support multiple IPPools for secondary network IPAM #3606

Merged
merged 1 commit into from
Apr 13, 2022

Conversation

jianjuns
Copy link
Contributor

@jianjuns jianjuns commented Apr 8, 2022

With this change, multiple IPPools can be specified in the CNI IPAM
config, and then antrea-agent will try allocating one IP in each IPPool
for the secondary network interface.

An example CNI config:
  {
      "cniVersion": "0.3.0",
      "type": "macvlan",
      "master": "enp0s9",
      "mode": "bridge",
      "ipam": {
          "type": "antrea-ipam",
          "ippool": ["ippool-v4", "ipppol-v6"]
      }
  }

Signed-off-by: Jianjun Shen shenj@vmware.com

@codecov-commenter
Copy link

codecov-commenter commented Apr 8, 2022

Codecov Report

Merging #3606 (4fe9f24) into main (7d3b595) will decrease coverage by 13.94%.
The diff coverage is 59.52%.

❗ Current head 4fe9f24 differs from pull request most recent head b4edd18. Consider uploading reports for the commit b4edd18 to get more accurate results

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #3606       +/-   ##
===========================================
- Coverage   64.27%   50.33%   -13.95%     
===========================================
  Files         278      248       -30     
  Lines       27929    35644     +7715     
===========================================
- Hits        17952    17942       -10     
- Misses       8062    15905     +7843     
+ Partials     1915     1797      -118     
Flag Coverage Δ
e2e-tests 50.33% <59.52%> (?)
kind-e2e-tests ?
unit-tests ?

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

Impacted Files Coverage Δ
pkg/ipam/poolallocator/allocator.go 30.36% <52.17%> (-21.77%) ⬇️
pkg/agent/cniserver/ipam/antrea_ipam.go 46.82% <65.62%> (-29.47%) ⬇️
pkg/agent/cniserver/ipam/antrea_ipam_controller.go 32.87% <83.33%> (-49.70%) ⬇️
pkg/controller/networkpolicy/endpoint_querier.go 4.58% <0.00%> (-86.85%) ⬇️
pkg/agent/util/iptables/lock.go 0.00% <0.00%> (-81.82%) ⬇️
pkg/controller/externalippool/validate.go 0.00% <0.00%> (-76.20%) ⬇️
...lowaggregator/clickhouseclient/clickhouseclient.go 0.00% <0.00%> (-75.84%) ⬇️
pkg/cni/client.go 0.00% <0.00%> (-75.52%) ⬇️
pkg/controller/networkpolicy/crd_utils.go 14.48% <0.00%> (-75.42%) ⬇️
pkg/controller/networkpolicy/clustergroup.go 3.50% <0.00%> (-74.80%) ⬇️
... and 271 more

@jianjuns jianjuns added the area/ipam Issues or PRs related to IP address management (IPAM). label Apr 8, 2022
@jianjuns jianjuns requested a review from gran-vmv April 8, 2022 18:23
@jianjuns jianjuns force-pushed the secnet-ipam-mips branch 2 times, most recently from b980589 to e9fab29 Compare April 8, 2022 23:20
@jianjuns jianjuns requested a review from annakhm April 8, 2022 23:20
@jianjuns jianjuns force-pushed the secnet-ipam-mips branch 3 times, most recently from 7b325e4 to 9d8d6f3 Compare April 11, 2022 20:57
@jianjuns jianjuns requested review from gran-vmv and removed request for gran-vmv April 11, 2022 20:58
@jianjuns
Copy link
Contributor Author

/test-all
/test-flexible-ipam-e2e

@jianjuns
Copy link
Contributor Author

/test-flexible-ipam-e2e

@jianjuns jianjuns force-pushed the secnet-ipam-mips branch 3 times, most recently from ce7c150 to 70e6157 Compare April 12, 2022 02:57

index := -1
for i, allocator := range allocators {
if allocator.Has(ip) {
Copy link
Contributor

@annakhm annakhm Apr 12, 2022

Choose a reason for hiding this comment

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

This returns true if IP is in given range, regardless if it is allocated - I think this can cause confusion while reading this code. Perhaps we should rename it to avoid confusion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is the right name in your mind? But anyway it is not relevant to this PR, and I prefer not to change it in this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, its just a thought not relevant for the PR. Perhaps belongs would be a more fitting name.

annakhm
annakhm previously approved these changes Apr 12, 2022
@jianjuns
Copy link
Contributor Author

/test-all

gran-vmv
gran-vmv previously approved these changes Apr 13, 2022
Copy link
Contributor

@gran-vmv gran-vmv left a comment

Choose a reason for hiding this comment

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

LGTM

func (a *IPPoolAllocator) HasContainer(containerID, ifName string) (bool, error) {

// HasContainer checks whether an IP was associated with specified container. It returns error if the IPPool CR fails to be retrieved.
func (a *IPPoolAllocator) HasContainer(containerID, ifName string) (net.IP, error) {
Copy link
Member

Choose a reason for hiding this comment

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

should we call the method something like "GetIPByContainer" given the change?

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 prefer to keep the name, as we have other HasXXX(), though I know this func now returns an IP.

Copy link
Member

Choose a reason for hiding this comment

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

But HasPod method indeed returns whether it "Has" the Pod

Copy link
Contributor Author

@jianjuns jianjuns Apr 13, 2022

Choose a reason for hiding this comment

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

Ok. Changed to GetContainerIP().

@@ -540,11 +567,9 @@ func (a *IPPoolAllocator) ReleaseContainer(containerID, ifName string) error {
return err
}

// HasResource checks whether an IP was associated with specified pod. It returns error if the resource is crd fails to be retrieved.
// HasResource checks whether an IP was associated with specified pod. It returns error if the IPPool CR fails to be retrieved.
Copy link
Member

Choose a reason for hiding this comment

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

Not introduced by this PR, but could be corrected with the change. s/HasResource/HasPod/

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. Let me change it.

With the change, multiple IPPools can be specified in the CNI IPAM
config, and then antrea-agent will try allocating one IP in each IPPool
for the secondary network interface.

An example CNI config:
  {
      "cniVersion": "0.3.0",
      "type": "macvlan",
      "master": "enp0s9",
      "mode": "bridge",
      "ipam": {
          "type": "antrea-ipam",
          "ippool": ["ippool-v4", "ipppol-v6"]
      }
  }

Signed-off-by: Jianjun Shen <shenj@vmware.com>
@jianjuns jianjuns dismissed stale reviews from gran-vmv and annakhm via b4edd18 April 13, 2022 04:51
@jianjuns
Copy link
Contributor Author

/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 tnqn added the action/release-note Indicates a PR that should be included in release notes. label Apr 13, 2022
@tnqn tnqn added this to the Antrea v1.7 release milestone Apr 13, 2022
@jianjuns jianjuns merged commit c463028 into antrea-io:main Apr 13, 2022
@jianjuns jianjuns deleted the secnet-ipam-mips branch April 13, 2022 16:06
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. area/ipam Issues or PRs related to IP address management (IPAM).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants