Skip to content

Commit

Permalink
OCPBUGS-19008: Always add ignition to set hostname on /etc/hostname
Browse files Browse the repository at this point in the history
Regardless of how IPA got to the point of finding a hostname
we need it to match the hostname after its provisioned.
  • Loading branch information
derekhiggins authored and openshift-cherrypick-robot committed Feb 21, 2024
1 parent 726ddd3 commit 8db1401
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions hardware_manager/ironic_coreos_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CoreOSInstallHardwareManager(hardware.HardwareManager):
HARDWARE_MANAGER_NAME = 'CoreOSInstallHardwareManager'
HARDWARE_MANAGER_VERSION = '1'

_fixed_hostname = None
_firstboot_hostname = None

def evaluate_hardware_support(self):
try:
Expand Down Expand Up @@ -80,6 +80,10 @@ def _fix_hostname(self):

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 @@ -97,7 +101,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 @@ -143,15 +147,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

0 comments on commit 8db1401

Please sign in to comment.