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 container hostname to netavark #24675

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gtjoseph
Copy link

@gtjoseph gtjoseph commented Nov 25, 2024

Passing the hostname allows netavark to include it in DHCP lease
requests which, in an environment where DDNS is used, can cause
DNS entries to be created automatically.

  • The current Hostname() function in container.go was updated to
    check the new container_name_as_hostname option in the
    CONTAINERS table of containers.conf. If set and no hostname
    was configured for the container, it causes the hostname to be
    set to a version of the container's name with the characters not
    valid for a hostname removed. If not set (the default), the original
    behavior of setting the hostname to the short container ID is
    preserved.

  • Because the Hostname() function can return the host's hostname
    if the container isn't running in a private UTS namespace, and we'd
    NEVER want to send that in a DHCP request for a container, a new
    function NetworkHostname() was added which functions like Hostname()
    except that it will return an empty string instead of the host's
    hostname if the container is not running in a private UTS namespace.

  • networking_common.getNetworkOptions() now uses NetworkHostname()
    to set the ContainerHostname member of the NetworkOptions structure.
    That member was added to the structure in a corresponding commit in
    common/libnetwork/types/network.go.

  • Added test to containers_conf_test.go

Signed-off-by: George Joseph g.devel@wxy78.net

NOTE:
Requires containers/common#2254
Required by containers/netavark#1130

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 25, 2024
Copy link
Contributor

openshift-ci bot commented Nov 25, 2024

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@openshift-ci openshift-ci bot added the do-not-merge/release-note-label-needed Enforce release-note requirement, even if just None label Nov 25, 2024
@gtjoseph gtjoseph force-pushed the main-pass-hostname-to-netavark branch from 57d0866 to aa649e7 Compare November 25, 2024 17:34
@gtjoseph gtjoseph changed the title main pass hostname to netavark Pass container hostname to netavark Nov 25, 2024
@gtjoseph
Copy link
Author

The use_container_name_as_hostname addition might be a bit controversial. I have no problem with backing it out if needed.

@baude
Copy link
Member

baude commented Nov 25, 2024

can you add a test?

@gtjoseph
Copy link
Author

can you add a test?

Sure, if you can give me some guidance on how to do it. I looked at the existing networking tests but none seemed appropriate to use as a template. From a podman perspective, all this new feature does is set the new ContainerHostname field in common's libnetwork NetworkOptions. The only true way to test this is to start a container with a macvlan network and dhcp ipam driver, then check the contents of the DHCP Discover packet.

@Luap99
Copy link
Member

Luap99 commented Nov 26, 2024

can you add a test?

Sure, if you can give me some guidance on how to do it. I looked at the existing networking tests but none seemed appropriate to use as a template. From a podman perspective, all this new feature does is set the new ContainerHostname field in common's libnetwork NetworkOptions. The only true way to test this is to start a container with a macvlan network and dhcp ipam driver, then check the contents of the DHCP Discover packet.

We don't have any DHCP tests here, that should all be tested in netavark as we already have a working DHCP setup there

What you can and should test IMO is that your config field is working by setting that and then checking the hostname in the container (i.e. without any DHCP going on). That does not cover the code path passing the right thing to netavark but at least it should cover your basic logic here in podman

libpod/container.go Show resolved Hide resolved
libpod/container.go Outdated Show resolved Hide resolved
libpod/container.go Outdated Show resolved Hide resolved
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 27, 2024
@gtjoseph
Copy link
Author

What you can and should test IMO is that your config field is working by setting that and then checking the hostname in the container (i.e. without any DHCP going on). That does not cover the code path passing the right thing to netavark but at least it should cover your basic logic here in podman

Test created.

@gtjoseph gtjoseph force-pushed the main-pass-hostname-to-netavark branch from aa649e7 to fa6eba9 Compare November 28, 2024 20:46
Copy link
Contributor

openshift-ci bot commented Nov 28, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: gtjoseph
Once this PR has been reviewed and has the lgtm label, please assign lsm5 for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 28, 2024
@gtjoseph gtjoseph requested a review from Luap99 November 28, 2024 20:49
@gtjoseph gtjoseph force-pushed the main-pass-hostname-to-netavark branch from fa6eba9 to 44d3c3b Compare November 29, 2024 15:57
@gtjoseph gtjoseph force-pushed the main-pass-hostname-to-netavark branch from 44d3c3b to 2f722c8 Compare November 29, 2024 17:23
@gtjoseph
Copy link
Author

Force push to fix gofmt issues and rebase to current main.

@gtjoseph gtjoseph force-pushed the main-pass-hostname-to-netavark branch from 2f722c8 to 5e2d38d Compare November 29, 2024 19:30
@gtjoseph
Copy link
Author

gtjoseph commented Nov 29, 2024

Holy Moly...checking for typos in comments. What a concept. :)
If CI is going to check that, shouldn't a local make check it, as well as other gofmt issues? That way we can catch them without needing to push and wait for CI.

--EDIT--
Duh. make validate

@gtjoseph gtjoseph force-pushed the main-pass-hostname-to-netavark branch from 5e2d38d to c6a5ff2 Compare November 29, 2024 20:29
@gtjoseph
Copy link
Author

I don't think the 4 failing tests are related to my change but if they are, let me know and I'll try and track them down. "testing-farm:fedora-rawhide-x86_64:cockpit-revdeps" at least looks like it has dependency issues when doing "dnf install".

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 4, 2024
Passing the hostname allows netavark to include it in DHCP lease
requests which, in an environment where DDNS is used, can cause
DNS entries to be created automatically.

* The current Hostname() function in container.go was updated to
check the new `container_name_as_hostname` option in the
CONTAINERS table of containers.conf.  If set and no hostname
was configured for the container, it causes the hostname to be
set to a version of the container's name with the characters not
valid for a hostname removed.  If not set (the default), the original
behavior of setting the hostname to the short container ID is
preserved.

* Because the Hostname() function can return the host's hostname
if the container isn't running in a private UTS namespace, and we'd
NEVER want to send _that_ in a DHCP request for a container, a new
function NetworkHostname() was added which functions like Hostname()
except that it will return an empty string instead of the host's
hostname if the container is not running in a private UTS namespace.

* networking_common.getNetworkOptions() now uses NetworkHostname()
to set the ContainerHostname member of the NetworkOptions structure.
That member was added to the structure in a corresponding commit in
common/libnetwork/types/network.go.

* Added test to containers_conf_test.go

Signed-off-by: George Joseph <g.devel@wxy78.net>
@gtjoseph gtjoseph force-pushed the main-pass-hostname-to-netavark branch from c6a5ff2 to bf5cb60 Compare December 5, 2024 16:34
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 5, 2024
@gtjoseph
Copy link
Author

gtjoseph commented Dec 5, 2024

Rebased and, since the containers/common#2254 dependency was merged, the temporary DO NOT MERGE commit has been removed. Still waiting on netavark which is waiting on an upstream package PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge/release-note-label-needed Enforce release-note requirement, even if just None do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants