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

Pass interface name and MAC back to runtime #145

Merged
merged 6 commits into from
Jan 25, 2017

Conversation

dcbw
Copy link
Member

@dcbw dcbw commented Mar 2, 2016

Add the infrastructure to pass interface names back from the plugin to the runtime. This lays the groundwork for letting runtimes not pass CNI_IFNAME and allowing plugins to determine that themsevles. This should be backwards compatible; if the runtime sends CNI_IFNAME then plugins must honor that and return an error if they cannot. If the runtime does not send CNI_IFNAME, the plugins currently default to 'eth0'.

Example output:

{
    "interface": {
        "hostIfname": "veth511119b6",
        "hostMac": "56:95:eb:4c:a0:91",
        "containerIfname": "eth0",
        "containerMac": "6a:1f:52:95:86:2c"
    },
    "ip4": {
        "ip": "10.1.0.152/24",
        "gateway": "10.1.0.1",
        "routes": [
            {
                "dst": "0.0.0.0/0"
            }
        ]
    },
    "dns": {}

@dcbw
Copy link
Member Author

dcbw commented Mar 2, 2016

For example, with OpenShift we'd use the hostIfname so that we don't have to jump into the container with 'nsenter' and grab the peer ifindex, then look that up on the host side. We also use nsenter to get the container veth MAC address, so this would also remove that step.

I'm going to plumb this through Kubernetes too, since it assumes interfaces are always called 'eth0' which may not always be the case, like with the Calico CNI plugin.

@dcbw
Copy link
Member Author

dcbw commented Mar 3, 2016

@steveej fixed the issue, PTAL

@caseydavenport
Copy link

Looks useful :)

Wanted to chime in with a few thoughts:

  • This is quite nice for CNI plugins which don't use multiple interfaces to implement multiple CNI networks (e.g Calico). We should make sure the spec includes that orchestrators should allow for multiple CNI networks to return the same interface fields .
  • This does put a bit more work on the backs of network plugins in terms of determining what interface they should use, but it isn't a whole lot of work and gives the plugin more flexibility which is nice.

@dcbw - Also wanted to correct the point above - the Calico CNI plugin does respect the CNI_IFNAME variable. I believe you're thinking of Mike Spreitzer's experimentation with mapping his own CNI plugin for Kubernetes to the Calico libnetwork plugin (which doesn't respect CNI_IFNAME for obvious reasons).

@dcbw
Copy link
Member Author

dcbw commented Mar 8, 2016

@caseydavenport thanks for the clarification, and sorry for blaming the Calico plugin where I shouldn't have :)

@zachgersh
Copy link
Contributor

hey @dcbw would it be possible to include some tests of this functionality? We've started backfilling tests and it would be great to merge new code with tests.

If you need examples or want to chat about how to test this I'd be happy to help.

The specification does not declare how this information must be processed by CNI consumers.
Examples include generating an `/etc/resolv.conf` file to be injected into the container filesystem or running a DNS forwarder on the host.
- `cniVersion` specifies a [Semantic Version 2.0](http://semver.org) of CNI specification used by the plugin.
- `dns` field contains a dictionary consisting of common DNS information that this network is aware of. The result is returned in the same format as specified in the [configuration](#network-configuration). The specification does not declare how this information must be processed by CNI consumers. Examples include generating an `/etc/resolv.conf` file to be injected into the container filesystem or running a DNS forwarder on the host.
Copy link
Member

Choose a reason for hiding this comment

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

Did you reformat this section intentionally? We've been writing one sentence (separated by .) per line in markdown files.

@dcbw
Copy link
Member Author

dcbw commented Mar 17, 2016

@steveej unintentional reformatting, I'll fix and repush with some testcases.

@steveej
Copy link
Member

steveej commented Mar 18, 2016

@steveej unintentional reformatting, I'll fix and repush with some testcases.

Thanks :-)

Also, please make sure the commit message conforms to https://github.com/appc/cni/blob/master/CONTRIBUTING.md#format-of-the-commit-message. We should go back to insisting on this, as git log is starting to get out of shape :-| I wonder if I can get some bot to do this for us.

@dcbw dcbw force-pushed the pass-ifname-back branch 2 times, most recently from 3c82107 to bd0d7b2 Compare March 24, 2016 18:20
@dcbw
Copy link
Member Author

dcbw commented Mar 24, 2016

@steveej repushed with the SPEC.md reformat fix. Also, instead of hardcoding "eth0" I have updated all plugins to use a prefix+index method and retry with an incremented index if the interface creation fails with EEXIST. This should make all plugins handle multiple interfaces in the same container as long as the runtime doesn't pass CNI_IFNAME.

I have not added testcases yet, so this isn't ready to merge. But I wanted to get your opinion on this updated approach.

@dcbw
Copy link
Member Author

dcbw commented Mar 24, 2016

Also, please make sure the commit message conforms to https://github.com/appc/cni/blob/master/CONTRIBUTING.md#format-of-the-commit-message. We should go back to insisting on this, as git log is starting to get out of shape :-| I wonder if I can get some bot to do this for us.

Also updated the git commit message, is that better?

@dcbw
Copy link
Member Author

dcbw commented Apr 7, 2016

Rebased on top of #167 with additional tests.

@dcbw
Copy link
Member Author

dcbw commented Jan 19, 2017

@tgraf I just pushed an update that move Routes out of the IPs structure and updates the spec to clarify what IPAM plugins return. See #145 (comment) for more details on immediate plans.

@containernetworking/cni-maintainers this push has these changes:

  1. moves Routes out of the IPs structure to a top-level alongside IPs and DNS
  2. renames the "IP" list in Result to "IPs" to be consistent with Routes and Interfaces
  3. adds a testcase to pkg/ipam to ensure we don't break it's Gateway handling functionality in the future
  4. updates the Spec with some forgotten things and to clarify what IPAM plugins should returnd

PTAL thanks!

@tomdee
Copy link
Member

tomdee commented Jan 20, 2017

The spec changes look OK to me, with just one simple fix:

  • You should bump the spec version at the top of the SPEC.md (might need a rebase)

That being said, I'm a little fuzzy on what the routes (or gateway) are actually used for or needed for. Is that information consumed by any runtimes or is it just just used for passing info between IPAM and network plugins?

@tgraf
Copy link
Contributor

tgraf commented Jan 20, 2017

@dcbw Given that []nexthops can be added later on while staying compatible with the non-array gw I believe what is being proposed a good course of action.

@dcbw
Copy link
Member Author

dcbw commented Jan 20, 2017

That being said, I'm a little fuzzy on what the routes (or gateway) are actually used for or needed for. Is that information consumed by any runtimes or is it just just used for passing info between IPAM and network plugins?

@tomdee mostly passed between plugins. I can't see why anything except the thing that configures the container's networking (eg, the IPAM-wrapping plugin) would use it.

@dcbw dcbw force-pushed the pass-ifname-back branch from da8e2c9 to 0bd0a58 Compare January 20, 2017 04:19
@dcbw
Copy link
Member Author

dcbw commented Jan 20, 2017

@tomdee updated the spec version, I don't know why I hadn't done that before...

@dcbw
Copy link
Member Author

dcbw commented Jan 20, 2017

@tomdee @rosenhouse @squeed rebased on top of ordered chaining.

"version": "<4-or-6>",
"address": "<ip-and-prefix-in-CIDR>",
"gateway": "<ip-address-of-the-gateway>", (optional)
"interface": "<index into 'interfaces' list>"
Copy link
Contributor

Choose a reason for hiding this comment

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

Totally minor nit-pick, but the quotes probably don't belong around the numeric index value.

Copy link
Member Author

Choose a reason for hiding this comment

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

"version": "<4-or-6>",
"address": "<ip-and-prefix-in-CIDR>",
"gateway": "<ip-address-of-the-gateway>", (optional)
"interface": "<index into 'interfaces' list>" (not required for IPAM plugins)
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, I think this numeric index for interface shouldn't have quotes around the value.

Copy link
Member Author

Choose a reason for hiding this comment

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

dcbw added 6 commits January 25, 2017 11:31
Otherwise the test fails, since Go's JSON marshaller prints
dict items alphabetically in its String() call.
…untime

Updates the spec and plugins to return an array of interfaces and IP details
to the runtime including:

- interface names and MAC addresses configured by the plugin
- whether the interfaces are sandboxed (container/VM) or host (bridge, veth, etc)
- multiple IP addresses configured by IPAM and which interface they
have been assigned to

Returning interface details is useful for runtimes, as well as allowing
more flexible chaining of CNI plugins themselves.  For example, some
meta plugins may need to know the host-side interface to be able to
apply firewall or traffic shaping rules to the container.
@dcbw dcbw force-pushed the pass-ifname-back branch from d3606f4 to d5acb12 Compare January 25, 2017 17:33
@dcbw
Copy link
Member Author

dcbw commented Jan 25, 2017

@rosenhouse fix up the spec; if this looks good mind hitting the merge button? Thanks!

@rosenhouse
Copy link
Contributor

It would be an honor...

@rosenhouse rosenhouse merged commit c4271db into containernetworking:master Jan 25, 2017
Copy link

@AlexeyKasatkin AlexeyKasatkin left a comment

Choose a reason for hiding this comment

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

Seems, I'm a bit too late with comments.

return err
}

// String returns a formatted string in the form of "[Interfaces: $1,][ IP: $2,] DNS: $3" where

Choose a reason for hiding this comment

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

and "Routes"

result.IP4 = &types.IPConfig{
IP: *ipn,
result.IPs = []*current.IPConfig{{
Version: "4",

Choose a reason for hiding this comment

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

Just to be in context: Will Allocate() be called for ip4 nets only? Or how does this behave now?

Copy link
Member Author

Choose a reason for hiding this comment

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

@AlexeyKasatkin nothing about the Allocate() call and the lease acquisition process changes. The DHCP plugin does not currently support DHCPv6 at all, and thus it's still limited to DHCPv4. Any invocation of the DHCP plugin will inherently try only IPv4.

But IPv6 patches would be gratefully accepted!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.