containernetworking / cni.dev

CNI website
https://cni.dev
Apache License 2.0
48 stars 55 forks source link

Plugins(dhcp): add examples about DHCP options #91

Closed SilverBut closed 2 years ago

SilverBut commented 3 years ago

Add description and example about DHCP options. See containernetworking/plugins#670 and containernetworking/plugins#660 for details.

Signed-off-by: SilverBut SilverBut@users.noreply.github.com

gazben commented 2 years ago

@SilverBut When I use the example config like this:

{
    "cniVersion": "0.4.0",
    "name": "external",
    "plugins": [
        {
            "type": "macvlan",
            "master": "enp0s18",
            "ipam": {
                "type": "dhcp",
        "daemonSocketPath": "/run/cni/dhcp.sock",
        "request": [
            {
                "skipDefault": false
            }
        ],
                "daemonSocketPath": "/run/cni/dhcp.sock",
                "provide": [
                    {
                        "option": "host-name",
                        "fromArg": "HOSTNAME"
                    }
                ]
            }
        }
    ]
}

Error:

error adding pod focused_goldstine_focused_goldstine to CNI network "external": error calling DHCP.Allocate: Can not parse option "": Can not parse option: strconv.ParseUint: parsing "": invalid syntax

If I remove the request part:

error adding pod elegant_chaplygin_elegant_chaplygin to CNI network "external": error calling DHCP.Allocate: no more tries

Is there something missing from the example config?

I tried to send the HOSTNAME from the default nginx container:

/ # env
HOSTNAME=443c79530615
SHLVL=2
HOME=/root
PKG_RELEASE=1
container=podman
TERM=xterm
NGINX_VERSION=1.21.5
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
NJS_VERSION=0.7.1
PWD=/
SilverBut commented 2 years ago

Hi @gazben Sorry for late response.

According to the doc:

    * `fromArg` (string, optional): Get value from `CNI_ARGS` by given argument name.

CNI_ARGS is not the environment variable list of the container. This is set by the "frontend" you are using, for example, podman set it here, and defined in the CNI spec.

Well, I don't know how to get CNI_ARGS correctly. But when using podman I would try this:

# sudo strace -f -s 4000 podman run --rm docker.io/library/golang:1.17 cat /proc/self/environ 2>&1 | grep -i cniArgs
[pid 428698] write(8, "{\"kind\":\"cniCacheV1\",.......,\"ifName\":\"eth0\",\"networkName\":\"podman\",\"cniArgs\":[[\"IgnoreUnknown\",\"1\"],[\"K8S_POD_NAMESPACE\",\"crazy_ellis\"],[\"K8S_POD_NAME\",\"crazy_ellis\"],[\"K8S_POD_INFRA_CONTAINER_ID\",\"a15ae3a2f6c86271ee84e307b0757ef4002fe520419af7c11f9308a717292f86\"]],......

It's obvious that this is not always a practical way, but it works at this time ;-)

SilverBut commented 2 years ago

Besides hey @jellonek since the related code is already merged, will this PR get merged before next CNI plugin release?