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

Add a new setting for configuring hostname #1664

Merged
merged 6 commits into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,13 @@ These settings can be changed at any time.

#### Network settings

* `settings.network.hostname`: The desired hostname of the system.
**Important note for all Kubernetes variants:** Changing this setting at runtime (not via user data) can cause issues with kubelet registration, as hostname is closely tied to the identity of the system for both registration and certificates/authorization purposes.

Most users don't need to change this setting as the following defaults work for the majority of use cases.
If this setting isn't set we attempt to use DNS reverse lookup for the hostname.
If the lookup is unsuccessful, the IP of the node is used in the format `ip-X-X-X-X`.

bcressey marked this conversation as resolved.
Show resolved Hide resolved
##### Proxy settings

These settings will configure the proxying behavior of the following services:
Expand Down
4 changes: 4 additions & 0 deletions Release.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,7 @@ version = "1.1.4"
"migrate_v1.1.3_kubelet-cpu-manager.lz4",
]
"(1.1.3, 1.1.4)" = []
"(1.1.4, 1.1.5)" = [
"migrate_v1.1.5_hostname-setting.lz4",
"migrate_v1.1.5_hostname-setting-metadata.lz4",
]
1 change: 1 addition & 0 deletions packages/release/hostname-env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
HOSTNAME={{settings.network.hostname}}
7 changes: 6 additions & 1 deletion packages/release/release.spec
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ Source99: release-tmpfiles.conf

Source200: motd.template
Source201: proxy-env
Source202: hostname-env

Source1000: eth0.xml
Source1001: multi-user.target
Source1002: configured.target
Source1003: preconfigured.target
Source1004: activate-configured.service
Source1005: activate-multi-user.service
Source1011: set-hostname.service

# Mounts for writable local storage.
Source1006: var.mount
Expand Down Expand Up @@ -108,7 +110,7 @@ EOF
install -d %{buildroot}%{_cross_unitdir}
install -p -m 0644 \
%{S:1001} %{S:1002} %{S:1003} %{S:1004} %{S:1005} \
%{S:1006} %{S:1007} %{S:1008} %{S:1009} %{S:1010} \
%{S:1006} %{S:1007} %{S:1008} %{S:1009} %{S:1010} %{S:1011} \
%{S:1015} %{S:1040} %{S:1041} %{S:1060} %{S:1061} %{S:1062} \
%{buildroot}%{_cross_unitdir}

Expand All @@ -129,6 +131,7 @@ install -p -m 0644 ${LICENSEPATH}.mount %{buildroot}%{_cross_unitdir}
install -d %{buildroot}%{_cross_templatedir}
install -p -m 0644 %{S:200} %{buildroot}%{_cross_templatedir}/motd
install -p -m 0644 %{S:201} %{buildroot}%{_cross_templatedir}/proxy-env
install -p -m 0644 %{S:202} %{buildroot}%{_cross_templatedir}/hostname-env

install -d %{buildroot}%{_cross_udevrulesdir}
install -p -m 0644 %{S:1016} %{buildroot}%{_cross_udevrulesdir}/61-mount-cdrom.rules
Expand Down Expand Up @@ -163,9 +166,11 @@ ln -s %{_cross_unitdir}/preconfigured.target %{buildroot}%{_cross_unitdir}/defau
%{_cross_unitdir}/*-kernels.mount
%{_cross_unitdir}/*-licenses.mount
%{_cross_unitdir}/var-lib-bottlerocket.mount
%{_cross_unitdir}/set-hostname.service
%dir %{_cross_templatedir}
%{_cross_templatedir}/motd
%{_cross_templatedir}/proxy-env
%{_cross_templatedir}/hostname-env
%{_cross_udevrulesdir}/61-mount-cdrom.rules

%changelog
14 changes: 14 additions & 0 deletions packages/release/set-hostname.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=Sets the hostname
After=settings-applier.service
Requires=settings-applier.service

[Service]
Type=oneshot
EnvironmentFile=/etc/network/hostname.env
ExecStart=/usr/bin/netdog set-hostname '${HOSTNAME}'
RemainAfterExit=true
StandardError=journal+console

[Install]
WantedBy=preconfigured.target
15 changes: 15 additions & 0 deletions sources/Cargo.lock

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

2 changes: 2 additions & 0 deletions sources/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ members = [
"api/migration/migrations/v1.1.2/control-container-v0-5-1",
"api/migration/migrations/v1.1.3/kubelet-cpu-manager-state",
"api/migration/migrations/v1.1.3/kubelet-cpu-manager",
"api/migration/migrations/v1.1.5/hostname-setting",
"api/migration/migrations/v1.1.5/hostname-setting-metadata",

"bottlerocket-release",

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "hostname-setting-metadata"
version = "0.1.0"
authors = ["Zac Mrowicki <[email protected]>"]
license = "Apache-2.0 OR MIT"
edition = "2018"
publish = false
# Don't rebuild crate just because of changes to README.
exclude = ["README.md"]

[dependencies]
migration-helpers = { path = "../../../migration-helpers" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#![deny(rust_2018_idioms)]

use migration_helpers::common_migrations::{AddMetadataMigration, SettingMetadata};
use migration_helpers::{migrate, Result};
use std::process;

/// We added a new setting and generator for configuring hostname
fn run() -> Result<()> {
migrate(AddMetadataMigration(&[SettingMetadata {
metadata: &["setting-generator", "affected-services"],
setting: "settings.network.hostname",
}]))
}

// Returning a Result from main makes it print a Debug representation of the error, but with Snafu
// we have nice Display representations of the error, so we wrap "main" (run) and print any error.
// https://github.com/shepmaster/snafu/issues/110
fn main() {
if let Err(e) = run() {
eprintln!("{}", e);
process::exit(1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "hostname-setting"
version = "0.1.0"
authors = ["Zac Mrowicki <[email protected]>"]
license = "Apache-2.0 OR MIT"
edition = "2018"
publish = false
# Don't rebuild crate just because of changes to README.
exclude = ["README.md"]

[dependencies]
migration-helpers = { path = "../../../migration-helpers" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#![deny(rust_2018_idioms)]

use migration_helpers::common_migrations::AddPrefixesMigration;
use migration_helpers::{migrate, Result};
use std::process;

/// We added a new setting and generator for configuring hostname
fn run() -> Result<()> {
migrate(AddPrefixesMigration(vec![
"settings.network.hostname",
"services.hostname",
"configuration-files.hostname",
]))
}

// Returning a Result from main makes it print a Debug representation of the error, but with Snafu
// we have nice Display representations of the error, so we wrap "main" (run) and print any error.
// https://github.com/shepmaster/snafu/issues/110
fn main() {
if let Err(e) = run() {
eprintln!("{}", e);
process::exit(1);
}
}
1 change: 1 addition & 0 deletions sources/api/netdog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ publish = false
exclude = ["README.md"]

[dependencies]
argh = "0.1.4"
dns-lookup = "1.0"
ipnet = { version = "2.0", features = ["serde"] }
envy = "0.4"
Expand Down
13 changes: 9 additions & 4 deletions sources/api/netdog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ Current version: 0.1.0

## Introduction

netdog is a small helper program for wicked, to apply network settings received from DHCP. It also
contains a subcommand `node-ip` that returns the node's current IP address in JSON format; this
subcommand is intended for use as a settings generator.
netdog is a small helper program for wicked, to apply network settings received from DHCP. It
generates `/etc/resolv.conf`, generates and sets the hostname, and persists the current IP to a
file.

It generates `/etc/resolv.conf`, sets the hostname, and persists the current IP to file.
It contains two subcommands meant for use as settings generators:
* `node-ip`: returns the node's current IP address in JSON format
* `generate-hostname`: returns the node's hostname in JSON format (it is the resolved IP or the IP
in format "ip-x-x-x-x" if resolving fails)
bcressey marked this conversation as resolved.
Show resolved Hide resolved

The subcommand `set-hostname` sets the hostname for the system.

## Colophon

Expand Down
Loading