libnetwork: provide endpoint name for IPAM drivers#50586
libnetwork: provide endpoint name for IPAM drivers#50586thaJeztah merged 1 commit intomoby:masterfrom
Conversation
6dc78eb to
827c0c7
Compare
e49bd02 to
e934704
Compare
austinvazquez
left a comment
There was a problem hiding this comment.
Approach lgtm, just a minor suggestion.
e934704 to
1f909d8
Compare
|
@akerouanton PTAL |
| var err error | ||
|
|
||
| ep := &Endpoint{name: name, generic: make(map[string]any), iface: &EndpointInterface{}} | ||
| ep := &Endpoint{name: name, generic: make(map[string]any), iface: &EndpointInterface{}, ipamOptions: map[string]string{netlabel.EndpointName: name}} |
There was a problem hiding this comment.
CreateOptionIpam overwrites ipamOptions:
moby/daemon/libnetwork/endpoint.go
Lines 1057 to 1072 in 16f2e81
So, I believe this currently works because no CreateOptionIpam was passed to (*Network).CreateEndpoint(), which means no IPAM flags were specified on docker network create ….
Could you touch CreateOptionIpam up, and add a unit test please?
There was a problem hiding this comment.
Ah, and it's probably worth putting &Endpoint{} instantiation on multiple lines to improve readability.
There was a problem hiding this comment.
Afaiu options provided with docker network create --ipam-opt ... are only passed to IPAM driver functionRequestPool. Not to RequestAddress. So CreateOptionIpam will not need update but will add unit test for this.
There was a problem hiding this comment.
So CreateOptionIpam will not need update but will add unit test for this.
Ah, right. I confused myself, sorry 🙈 You're changing createEndpoint, so it's definitely docker run --ip ….
For the record, I ran the following commands with breakpoints set before / after ep.processOptions(options...) and I can confirm that CreateOptionIpam removes the predefined endpoint name label.
$ docker network create --subnet 172.21.0.0/24 testnet
$ docker run --rm --network testnet --ip 172.21.0.10 alpine true
One way to test this PR would be to add a test specifically for CreateOptionIpam. Call the func it returns with an endpoint initialized with a non-empty map of labels, and verify that CreateOptionIpam preserve them. (And you can remove the change you made in TestIpamReleaseOnNetDriverFailures as it's not related to this PR.)
There was a problem hiding this comment.
Afaiu options provided with
docker network create --ipam-opt ...are only passed to IPAM driver functionRequestPool. Not toRequestAddress.
Ah, right. I confused myself, sorry 🙈 You're changing createEndpoint, so it's definitely docker run --ip ….
For the record, I ran the following commands with breakpoints set before / after ep.processOptions(options...) and I can confirm that CreateOptionIpam removes the predefined endpoint name label.
$ docker network create --subnet 172.21.0.0/24 testnet
$ docker run --rm --network testnet --ip 172.21.0.10 alpine true
One way to test this PR would be to add a test specifically for CreateOptionIpam. Call the func it returns with an endpoint initialized with a non-empty map of labels, and verify that CreateOptionIpam preserve them. (And you can remove the change you made in TestIpamReleaseOnNetDriverFailures as it's not related to this PR.)
There was a problem hiding this comment.
Oh, my original solution was actually correct. It was change suggested in #50586 (comment) which broke case where --ip flag is used.
This cannot be handled in CreateOptionIpam because endpoint name is not known in there so perhaps it would be enough for now just leave comment for those who might touch this in future?
Also I think that ep.ipamOptions is always nil before initialization so it should not be needed to check it but let's see what is result of CI.
There was a problem hiding this comment.
@akerouanton test added and verified that it would fail if ipamOptions was added in line 1188 like it was in f4a72b8 which you tested.
Ping also @corhere as I see that you self-requested a review for this.
EDIT: Ended up to disable new test in Windows because creating and removing networks like this will easily get HNS to unknown state and this is not OS specific logic.
f4a72b8 to
d678c1d
Compare
6a4cb4e to
875f3b0
Compare
akerouanton
left a comment
There was a problem hiding this comment.
A few nits, otherwise LGTM
Signed-off-by: Olli Janatuinen <[email protected]>
875f3b0 to
c6717f4
Compare
@akerouanton Those are fixed now. |
- What I did
I'm building IPAM driver which integrates Docker and HashiCorp Nomad in way that it is possible dynamically allocate sub ranges (like can do manually with
--ip-range) by utilizing Nomad namespace metadata.So for example I would create network to Windows nodes like this:
and to Linux nodes like this:
And then create application environments with Nomad namespace configuration like this:
But it requires that IPAM driver knows that to which Nomad namespace container sending
RequestAddressbelongs to.Initially I tried to solve that by enabling
RequiresMACAddresscapability and using that to find correct container and it's labels but it turns out thatContainerInspectcannot be called inside ofRequestAddressfunction because libnetwork has locks enabled in that point.So this PR provides minimal change to libnetwork allowing this to be done in IPAM drivers.
- How I did it
Added logic which will always send
com.docker.network.endpoint.namelabel to IPAM driver containing name of the endpoint (=> name of the container).That solves issue for me because containers naming is hardcoded in Nomad so I can simply parse allocation ID from it and call Read Allocation API
- How to verify it
In current form it it should not need anything more than pass CI. If maintainers want, this can be also put behind of capability flag but I don't think that it is necessary as it is just extra label.
EDIT: Plugin described above is now available in here and seems to be working fine with this.
- A picture of a cute animal (not mandatory but encouraged)
