Skip to content

Commit

Permalink
netdog: adjust variant files and symlink
Browse files Browse the repository at this point in the history
  • Loading branch information
jmt-lab committed Apr 29, 2024
1 parent 48b8871 commit e0b18ac
Show file tree
Hide file tree
Showing 34 changed files with 67 additions and 71 deletions.
4 changes: 4 additions & 0 deletions packages/netdog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ source-groups = [
# RPM BuildRequires
[build-dependencies]
glibc = { path = "../glibc" }

[dependencies]
wicked = { path = "../wicked" }
systemd = { path = "../systemd" }
66 changes: 30 additions & 36 deletions packages/netdog/netdog.spec
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
%undefine _debugsource_packages

Name: %{_cross_os}netdog
Version: 0.1.0
Version: 0.1.1
Release: 0%{?dist}
Summary: Bottlerocket network configuration helper
License: Apache-2.0 OR MIT
URL: https://github.com/bottlerocket-os/bottlerocket

Source2: netdog-tmpfiles.conf
Source0: netdog-tmpfiles.conf

Source10: run-netdog.mount
Source11: write-network-status.service
Expand All @@ -18,44 +18,38 @@ Source13: disable-udp-offload.service
Source20: 00-resolved.conf

BuildRequires: %{_cross_os}glibc-devel
Requires: %{_cross_os}netdog
Requires: %{_cross_os}hostname-reverse-dns
Requires: (%{_cross_os}hostname-imds if %{_cross_os}variant-platform(aws))
Requires: (%{_cross_os}netdog-systemd-networkd if %{_cross_os}image-feature(systemd-networkd))
Requires: (%{_cross_os}netdog-wicked if %{_cross_os}image-feature(no-systemd-networkd))

%description
%{summary}.

%package -n %{_cross_os}netdog-common
Summary: Common configuration for Bottlerocket's network configuration helper
%description -n %{_cross_os}netdog-common
%{summary}.

%package -n %{_cross_os}netdog-systemd-networkd
%package systemd-networkd
Summary: Bottlerocket network configuration helper
Provides: %{_cross_os}netdog = 2:
Requires: %{_cross_os}netdog-common
Requires: %{name}
Requires: %{_cross_os}systemd-networkd
Requires: %{_cross_os}systemd-resolved
Supplements: %{_cross_os}systemd-networkd
Conflicts: (%{_cross_os}netdog-wicked or %{_cross_os}image-feature(no-systemd-networkd))
%description -n %{_cross_os}netdog-systemd-networkd
%{summary}.

%package -n %{_cross_os}netdog-wicked
%package wicked
Summary: Bottlerocket network configuration helper
Provides: %{_cross_os}netdog = 1:
Requires: %{_cross_os}netdog-common
Requires: %{name}
Requires: %{_cross_os}wicked
Supplements: %{_cross_os}wicked
Conflicts: (%{_cross_os}netdog-systemd-networkd or %{_cross_os}image-feature(systemd-networkd))
%description -n %{_cross_os}netdog-wicked
%{summary}.

%package -n %{_cross_os}hostname-reverse-dns
Summary: Reverse DNS Hostname detector
Supplements: %{_cross_os}netdog-common
%description -n %{_cross_os}hostname-reverse-dns
%{summary}

%package -n %{_cross_os}hostname-imds
Summary: IMDS Hostname detector
Supplements: %{_cross_os}netdog-common
%description -n %{_cross_os}hostname-imds
%{summary}

Expand All @@ -66,7 +60,7 @@ Supplements: %{_cross_os}netdog-common
%build
mkdir bin

echo "** Build Dogtag Hostname Helpers"
echo "** Build Dogtag Hostname Detectors"
%cargo_build --manifest-path %{_builddir}/sources/Cargo.toml \
-p dogtag \
--bins \
Expand All @@ -83,16 +77,16 @@ echo "** Build Netdog Binaries"
--target-dir=${HOME}/.cache/wicked

%install
install -d %{buildroot}%{_cross_libexecdir}/hostname-resolvers
install -p -m 0755 ${HOME}/.cache/dogtag/%{__cargo_target}/release/20-imds %{buildroot}%{_cross_libexecdir}/hostname-resolvers/20-imds
install -p -m 0755 ${HOME}/.cache/dogtag/%{__cargo_target}/release/10-reverse-dns %{buildroot}%{_cross_libexecdir}/hostname-resolvers/10-reverse-dns
install -d %{buildroot}%{_cross_libexecdir}/hostname-detectors
install -p -m 0755 ${HOME}/.cache/dogtag/%{__cargo_target}/release/20-imds %{buildroot}%{_cross_libexecdir}/hostname-detectors/20-imds
install -p -m 0755 ${HOME}/.cache/dogtag/%{__cargo_target}/release/10-reverse-dns %{buildroot}%{_cross_libexecdir}/hostname-detectors/10-reverse-dns

install -d %{buildroot}%{_cross_bindir}
install -p -m 0755 ${HOME}/.cache/networkd/%{__cargo_target}/release/netdog %{buildroot}%{_cross_bindir}/netdog-systemd-networkd
install -p -m 0755 ${HOME}/.cache/wicked/%{__cargo_target}/release/netdog %{buildroot}%{_cross_bindir}/netdog-wicked

install -d %{buildroot}%{_cross_tmpfilesdir}
install -p -m 0644 %{S:2} %{buildroot}%{_cross_tmpfilesdir}/netdog.conf
install -p -m 0644 %{S:0} %{buildroot}%{_cross_tmpfilesdir}/netdog.conf

install -d %{buildroot}%{_cross_unitdir}
install -p -m 0644 %{S:10} %{S:11} %{S:12} %{S:13} %{buildroot}%{_cross_unitdir}
Expand All @@ -101,29 +95,29 @@ install -d %{buildroot}%{_cross_libdir}
install -d %{buildroot}%{_cross_libdir}/systemd/resolved.conf.d
install -p -m 0644 %{S:20} %{buildroot}%{_cross_libdir}/systemd/resolved.conf.d

%post -n %{_cross_os}netdog-wicked -p <lua>
posix.link("%{_cross_bindir}/netdog-wicked", "%{_cross_bindir}/netdog")

%post -n %{_cross_os}netdog-systemd-networkd -p <lua>
posix.link("%{_cross_bindir}/netdog-systemd-networkd", "%{_cross_bindir}/netdog")

%files -n %{_cross_os}hostname-reverse-dns
%{_cross_libexecdir}/hostname-resolvers/10-reverse-dns
%post wicked -p <lua>
posix.symlink("netdog-wicked", "%{_cross_bindir}/netdog")

%files -n %{_cross_os}hostname-imds
%{_cross_libexecdir}/hostname-resolvers/20-imds
%post systemd-networkd -p <lua>
posix.symlink("netdog-systemd-networkd", "%{_cross_bindir}/netdog")

%files -n %{_cross_os}netdog-common
%files
%{_cross_tmpfilesdir}/netdog.conf
%{_cross_unitdir}/generate-network-config.service
%{_cross_unitdir}/disable-udp-offload.service
%{_cross_unitdir}/run-netdog.mount

%files -n %{_cross_os}netdog-systemd-networkd
%files -n %{_cross_os}hostname-reverse-dns
%{_cross_libexecdir}/hostname-detectors/10-reverse-dns

%files -n %{_cross_os}hostname-imds
%{_cross_libexecdir}/hostname-detectors/20-imds

%files systemd-networkd
%{_cross_bindir}/netdog-systemd-networkd
%{_cross_unitdir}/write-network-status.service
%dir %{_cross_libdir}/systemd/resolved.conf.d
%{_cross_libdir}/systemd/resolved.conf.d/00-resolved.conf

%files -n %{_cross_os}netdog-wicked
%files wicked
%{_cross_bindir}/netdog-wicked
3 changes: 0 additions & 3 deletions packages/os/os.spec
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,6 @@ install -p -m 0644 \
%{S:113} %{S:114} %{S:119} %{S:122} \
%{buildroot}%{_cross_unitdir}



%if %{with nvidia_flavor}
sed -e 's|PREFIX|%{_cross_prefix}|g' %{S:115} > link-kernel-modules.service
sed -e 's|PREFIX|%{_cross_prefix}|g' %{S:116} > load-kernel-modules.service
Expand All @@ -533,7 +531,6 @@ install -p -m 0644 %{S:201} %{buildroot}%{_cross_tmpfilesdir}/host-containers.co
install -p -m 0644 %{S:202} %{buildroot}%{_cross_tmpfilesdir}/thar-be-updates.conf
install -p -m 0644 %{S:203} %{buildroot}%{_cross_tmpfilesdir}/bootstrap-containers.conf


install -d %{buildroot}%{_cross_udevrulesdir}
install -p -m 0644 %{S:300} %{buildroot}%{_cross_udevrulesdir}/80-ephemeral-storage.rules
install -p -m 0644 %{S:301} %{buildroot}%{_cross_udevrulesdir}/81-ebs-volumes.rules
Expand Down
1 change: 0 additions & 1 deletion packages/release/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,4 @@ selinux-policy = { path = "../selinux-policy" }
shim = { path = "../shim" }
systemd = { path = "../systemd" }
util-linux = { path = "../util-linux" }
wicked = { path = "../wicked" }
xfsprogs = { path = "../xfsprogs" }
9 changes: 6 additions & 3 deletions sources/dogtag/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

Current version: 0.1.0

dogtag resolves the hostname of a bottlerocket server/instance. It's used to generate settings.network.hostname. To accomplish this, it uses a set of standalone binaries in /var/bottlerocket/dogtag that resolve the hostname via different methods.
dogtag detects the hostname of a bottlerocket server/instance. It's used to generate settings.network.hostname.
To accomplish this, it uses a set of standalone binaries in /usr/libexec/hostname-detectors that detect the hostname via different methods.

Currently, bottlerocket ships with two hostname resolver binaries:
Currently, bottlerocket ships with two hostname detector binaries:

20-imds - Fetches hostname from EC2 Instance Metadata Service
10-reverse-dns - Uses reverse DNS lookup to resolve the hostname

dogtag runs the resolvers in /var/bottlerocket/dogtag in reverse alphanumerical order until one of them returns a hostname, at which point it will exit early and print the returned hostname to stdout.
dogtag runs the detectors in /usr/libexec/hostname-detectors in reverse alphanumerical order until one of them returns a hostname,
at which point it will exit early and print the returned hostname to stdout. If none of the detectors detect the hostname the
ip address is returned.

## Colophon

Expand Down
18 changes: 11 additions & 7 deletions sources/dogtag/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
/*!
dogtag resolves the hostname of a bottlerocket server/instance. It's used to generate settings.network.hostname. To accomplish this, it uses a set of standalone binaries in /var/bottlerocket/dogtag that resolve the hostname via different methods.
dogtag detects the hostname of a bottlerocket server/instance. It's used to generate settings.network.hostname.
To accomplish this, it uses a set of standalone binaries in /usr/libexec/hostname-detectors that detect the hostname via different methods.
Currently, bottlerocket ships with two hostname resolver binaries:
Currently, bottlerocket ships with two hostname detector binaries:
20-imds - Fetches hostname from EC2 Instance Metadata Service
10-reverse-dns - Uses reverse DNS lookup to resolve the hostname
dogtag runs the resolvers in /var/bottlerocket/dogtag in reverse alphanumerical order until one of them returns a hostname, at which point it will exit early and print the returned hostname to stdout.
dogtag runs the detectors in /usr/libexec/hostname-detectors in reverse alphanumerical order until one of them returns a hostname,
at which point it will exit early and print the returned hostname to stdout. If none of the detectors detect the hostname the
ip address is returned.
*/
use argh::FromArgs;
use log::debug;
Expand All @@ -15,7 +18,7 @@ use std::net::IpAddr;
use std::{path::PathBuf, process};
use walkdir::WalkDir;

const DOGTAG_BIN_PATH: &str = "/usr/libexec/hostname-resolvers";
const DOGTAG_BIN_PATH: &str = "/usr/libexec/hostname-detectors";

/// Cli defines the standard cmdline interface for all hostname handlers
#[derive(FromArgs)]
Expand All @@ -28,10 +31,10 @@ pub struct Cli {

pub type Result<T> = std::result::Result<T, error::Error>;

/// find_hostname will utilize the helpers located in /var/bottlerocket/dogtag/ to try and discover the hostname
/// find_hostname will utilize the helpers located in /usr/libexec/hostname-detectors to try and discover the hostname
pub async fn find_hostname(ip_addr: IpAddr) -> Result<String> {
debug!(
"attempting to discover hostname helpers in {}",
"attempting to discover hostname detectors in {}",
DOGTAG_BIN_PATH
);
// We want to do reverse sort as we want to prioritize higher numbers first
Expand Down Expand Up @@ -64,7 +67,8 @@ pub async fn find_hostname(ip_addr: IpAddr) -> Result<String> {
}
}
}
Err(error::Error::NoHelper {})
// If we fail to find a hostname return the provided ip address sanitized
Ok(ip_addr.to_string().replace(':', "-"))
}

pub mod error {
Expand Down
6 changes: 2 additions & 4 deletions sources/netdog/src/cli/generate_hostname.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@ use std::str::FromStr;
/// Generate hostname from installed hostname resolvers
pub(crate) struct GenerateHostnameArgs {}

/// Attempt to resolve assigned IP address, if unsuccessful use the IP as the hostname.
/// Attempt to convert the assigned IP address to a valid hostname
///
/// The result is returned as JSON. (intended for use as a settings generator)
pub(crate) async fn run() -> Result<()> {
let ip_string = fs::read_to_string(CURRENT_IP)
.context(error::CurrentIpReadFailedSnafu { path: CURRENT_IP })?;
let ip = IpAddr::from_str(&ip_string).context(error::IpFromStringSnafu { ip: &ip_string })?;

// If no hostname has been determined we return the IP address of the host, replacing invalid ipv6 chars.
let hostname = find_hostname(ip)
.await
.unwrap_or(ip_string.replace(':', "-"));
.context(error::HostnameDetectionSnafu)?;

// sundog expects JSON-serialized output
print_json(hostname)
Expand Down
3 changes: 3 additions & 0 deletions sources/netdog/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ mod error {
#[snafu(display("Failed to discern primary interface"))]
GetPrimaryInterface,

#[snafu(display("Failed to detect hostname: {}", source))]
HostnameDetection { source: dogtag::error::Error },

#[snafu(display("Failed to write hostname to '{}': {}", path.display(), source))]
HostnameWriteFailed { path: PathBuf, source: io::Error },

Expand Down
3 changes: 2 additions & 1 deletion variants/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions variants/aws-dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ grub-set-private-var = true
unified-cgroup-hierarchy = true
xfs-data-partition = true
uefi-secure-boot = true
systemd-networkd = true

[package.metadata.build-variant]
kernel-parameters = [
Expand Down
1 change: 0 additions & 1 deletion variants/aws-ecs-1-nvidia/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ included-packages = [
# core
"release",
"kernel-5.10",
"wicked",
# docker
"docker-cli",
"docker-engine",
Expand Down
1 change: 0 additions & 1 deletion variants/aws-ecs-1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ included-packages = [
# core
"release",
"kernel-5.10",
"wicked",
# docker
"docker-cli",
"docker-engine",
Expand Down
1 change: 1 addition & 0 deletions variants/aws-ecs-2-nvidia/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ grub-set-private-var = true
unified-cgroup-hierarchy = true
uefi-secure-boot = true
xfs-data-partition = true
systemd-networkd = true

[package.metadata.build-variant.image-layout]
os-image-size-gib = 4
Expand Down
1 change: 1 addition & 0 deletions variants/aws-ecs-2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ grub-set-private-var = true
unified-cgroup-hierarchy = true
uefi-secure-boot = true
xfs-data-partition = true
systemd-networkd = true

[package.metadata.build-variant]
included-packages = [
Expand Down
1 change: 0 additions & 1 deletion variants/aws-k8s-1.23-nvidia/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ included-packages = [
"cni",
"cni-plugins",
"kernel-5.10",
"wicked",
"kubelet-1.23",
"release",
"nvidia-container-toolkit-k8s",
Expand Down
1 change: 0 additions & 1 deletion variants/aws-k8s-1.23/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ included-packages = [
"cni",
"cni-plugins",
"kernel-5.10",
"wicked",
"kubelet-1.23",
"release",
]
Expand Down
1 change: 0 additions & 1 deletion variants/aws-k8s-1.24-nvidia/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ included-packages = [
"cni",
"cni-plugins",
"kernel-5.15",
"wicked",
"kubelet-1.24",
"release",
"nvidia-container-toolkit-k8s",
Expand Down
1 change: 0 additions & 1 deletion variants/aws-k8s-1.24/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ included-packages = [
"cni",
"cni-plugins",
"kernel-5.15",
"wicked",
"kubelet-1.24",
"release",
]
Expand Down
1 change: 0 additions & 1 deletion variants/aws-k8s-1.25-nvidia/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ included-packages = [
"cni-plugins",
"kernel-5.15",
"kubelet-1.25",
"wicked",
"release",
"nvidia-container-toolkit-k8s",
"nvidia-k8s-device-plugin",
Expand Down
1 change: 0 additions & 1 deletion variants/aws-k8s-1.25/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ included-packages = [
"cni",
"cni-plugins",
"kernel-5.15",
"wicked",
"kubelet-1.25",
"release",
]
Expand Down
1 change: 0 additions & 1 deletion variants/aws-k8s-1.26-nvidia/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ included-packages = [
"cni-plugins",
"kernel-5.15",
"kubelet-1.26",
"wicked",
"release",
"nvidia-container-toolkit-k8s",
"nvidia-k8s-device-plugin",
Expand Down
1 change: 0 additions & 1 deletion variants/aws-k8s-1.26/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ included-packages = [
"cni-plugins",
"kernel-5.15",
"kubelet-1.26",
"wicked",
"release",
]
kernel-parameters = [
Expand Down
Loading

0 comments on commit e0b18ac

Please sign in to comment.