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

OCPBUGS-19008: Always add ignition to set hostname on /etc/hostname #106

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions hardware_manager/ironic_coreos_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CoreOSInstallHardwareManager(hardware.HardwareManager):
HARDWARE_MANAGER_NAME = 'CoreOSInstallHardwareManager'
HARDWARE_MANAGER_VERSION = '1'

_fixed_hostname = None
_firstboot_hostname = None
_dbus = None

def evaluate_hardware_support(self):
Expand Down Expand Up @@ -86,6 +86,10 @@ def _fix_hostname(self):
current = current.strip()
LOG.debug('The current hostname is %s', current)
if current not in ('localhost', 'localhost.localdomain'):
# Regardless of whether the hostname had been previously set or it gets set below
# we need to make sure if matches the name when the node boot so always set firstboot
# in ignition
self._firstboot_hostname = current
return

new = os.getenv('IPA_DEFAULT_HOSTNAME')
Expand All @@ -103,7 +107,7 @@ def _fix_hostname(self):
# IPA is run in a container, /etc/hostname is not updated there
with open('/etc/hostname', 'wt') as fp:
fp.write(new)
self._fixed_hostname = new
self._firstboot_hostname = new

@property
def dbus(self):
Expand Down Expand Up @@ -156,15 +160,15 @@ def start_assisted_install(self, node, ports):
LOG.info('Succesfully installed using the assisted agent')

def _add_firstboot_hostname_fix(self, ignition):
if not self._fixed_hostname:
if not self._firstboot_hostname:
return ignition

if isinstance(ignition, str):
ignition = json.loads(ignition)
elif not ignition:
ignition = {}

encoded = urlparse.quote(self._fixed_hostname)
encoded = urlparse.quote(self._firstboot_hostname)

files = ignition.setdefault('storage', {}).setdefault('files', [])
files.append({
Expand Down