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

ipam/host-local: support multiple IP ranges #12

Merged
merged 1 commit into from
Jun 15, 2017

Conversation

squeed
Copy link
Member

@squeed squeed commented Jun 1, 2017

This change allows the host-local allocator to allocate multiple IPs. This is intended to enable dual-stack, but is not limited to only two subnets or separate address families.

Migrated from containernetworking/cni#451.

@squeed
Copy link
Member Author

squeed commented Jun 1, 2017

@leblancd @dcbw I took your feedback in to account:

  • Overlapping ranges are an error
  • last_reserved_ip is now suffixed with the base64 of the RangeStart
  • An error is returned if multiple ranges per address family are configured with cniVersion of 0.2.0 or below
  • RangeStart is now .1

@squeed
Copy link
Member Author

squeed commented Jun 1, 2017

build failure is due to a minor Travis misconfiguration

Copy link

@leblancd leblancd left a comment

Choose a reason for hiding this comment

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

Looks very good to me, but I have a question about total number of IP addresses supported for CNI <= 0.2.0, and questions about whether we need a few scattered V6 test cases.

}

// Releases all IPs allocated for the container with given ID
// Relase clears all IPs allocated for the container with given ID
Copy link

Choose a reason for hiding this comment

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

Typo, "Relase" should be "Release".

// This is not critical, we just lose round-robin this one time.
lastReservedIP, err := a.store.LastReservedIP(a.rangeID)
if err != nil && !os.IsNotExist(err) {
log.Printf("Error retriving last reserved ip: %v", err)
Copy link

Choose a reason for hiding this comment

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

Typo, "retriving".

}

// CNI spec 0.2.0 and below supported only one v4 and v6 address
if numV4 > 1 || numV6 > 1 {
Copy link

Choose a reason for hiding this comment

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

Shouldn't this be a check for "if numV4 + numV6 > 1". I thought the CNI versions <= 0.2.0 only supported a single IP address in the stdout sent back to whatever invokes the plugin (either v4-only or v6-only)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nah, 0.1.0 supports one v4 and v6.

"type": "host-local",
"ranges": [
{
"subnet": "10.1.2.0/24",
Copy link

Choose a reason for hiding this comment

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

Should there be a "Should detect overlap" test case for IPv6?

"master": "foo0",
"args": {
"cni": {
"ips": [ "10.1.2.11", "11.11.11.11"]
Copy link

Choose a reason for hiding this comment

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

Should there be a "Should parse config args" test case for IPv6?

@@ -289,4 +323,203 @@ var _ = Describe("host-local Operations", func() {
Expect(err).NotTo(HaveOccurred())
Expect(strings.Index(string(out), "Error retriving last reserved ip")).To(Equal(-1))
})

It("allocates a custom IP when requested by config args", func() {
Copy link

Choose a reason for hiding this comment

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

Do we need an "allocates a custom IP..." test case for IPv6, or is the custom IP logic agnostic of family?

RangeStart: net.ParseIP("10.0.0.128"),
},
false),
Entry("same subnet, overlapping start + end",
Copy link

Choose a reason for hiding this comment

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

Need overlapping, non-overlapping, and containing range tests for V6?

@squeed
Copy link
Member Author

squeed commented Jun 2, 2017

@leblancd updated; we don't need specific v6 in most cases since the logic is family agnostic. The important functions (IPInRange(), Overlaps(), Canonicalize()) have pretty extensive v6 tests.

I added a few more end-to-end v6 tests but duplicating every test case isn't needed.

Copy link

@leblancd leblancd left a comment

Choose a reason for hiding this comment

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

Changes look good to me.

{
"subnet": "3ffe:ffff:0:01ff::/64",
"rangeStart": "3ffe:ffff:0:01ff::0010",
"rangeEnd": "3ffe:ffff:0:01ff::0020",
Copy link
Contributor

Choose a reason for hiding this comment

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

Tiny nit: line should not end with a comma

@@ -49,34 +60,66 @@ We can test it out on the command-line:
```bash
$ export CNI_COMMAND=ADD
$ export CNI_CONTAINERID=f81d4fae-7dec-11d0-a765-00a0c91e6bf6
$ echo '{ "name": "default", "ipam": { "type": "host-local", "subnet": "203.0.113.0/24" } }' | ./host-local
$ echo '{ "cniVersion": "0.3.1", "name": "examplenet", "ipam": { "type": "host-local", "ranges": [ {"subnet": "203.0.113.0/24"}, {"subnet": "2001:db8:1::/64"}], "dataDir": "/tmp/cni-example" } }' | CNI_COMMAND=ADD CNI_CONTAINERID=example CNI_NETNS=/dev/null CNI_IFNAME=dummy0 CNI_PATH=. ./host-local
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like you're setting CNI_CONTAINERID and CNI_COMMAND in two places.

Copy link
Contributor

@rosenhouse rosenhouse left a comment

Choose a reason for hiding this comment

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

A couple tiny nits with the documentation. Otherwise LGTM.

@squeed
Copy link
Member Author

squeed commented Jun 12, 2017

This is ready to merge - can I get a second approver?

This change allows the host-local allocator to allocate multiple IPs.
This is intended to enable dual-stack, but is not limited to only two
subnets or separate address families.
Copy link
Member

@dcbw dcbw left a comment

Choose a reason for hiding this comment

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

LGTM

@dcbw dcbw merged commit e2558a0 into containernetworking:master Jun 15, 2017
lsm5 pushed a commit to lsm5/containernetworking-plugins that referenced this pull request Oct 24, 2019
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants