From: Sage Weil Date: Tue, 25 May 2021 20:10:49 +0000 (-0400) Subject: mgr/cephadm: convert host addr if non-IP to IP X-Git-Tag: v17.1.0~1812^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=781bfa14ffc9aa37eb85635a59af1f202999e874;p=ceph.git mgr/cephadm: convert host addr if non-IP to IP Previously we allowed the host.addr to be a DNS name (short or fqdn). This is problematic because of the inconsistent way that docker and podman handle /etc/hosts, and undesirable because relying on external DNS is an external source of failure for the cluster without any benefit in return (simply updating DNS is not sufficient to make ceph behave). So: update any non-IP to an IP as soon as we start up (presumably on upgrade). If we get a loopback address (127.0.0.1 or 127.0.1.1), then wait and hope that the next instance of the manager has better luck. Signed-off-by: Sage Weil --- diff --git a/src/pybind/mgr/cephadm/inventory.py b/src/pybind/mgr/cephadm/inventory.py index b79ca235788..c2ce50db8c8 100644 --- a/src/pybind/mgr/cephadm/inventory.py +++ b/src/pybind/mgr/cephadm/inventory.py @@ -1,5 +1,6 @@ import datetime from copy import copy +import ipaddress import json import logging from typing import TYPE_CHECKING, Dict, List, Iterator, Optional, Any, Tuple, Set, Mapping, cast, \ @@ -11,6 +12,8 @@ from ceph.deployment.service_spec import ServiceSpec, PlacementSpec from ceph.utils import str_to_datetime, datetime_to_str, datetime_now from orchestrator import OrchestratorError, HostSpec, OrchestratorEvent, service_to_daemon_types +from .utils import resolve_ip + if TYPE_CHECKING: from .module import CephadmOrchestrator @@ -28,6 +31,7 @@ class Inventory: def __init__(self, mgr: 'CephadmOrchestrator'): self.mgr = mgr + adjusted_addrs = False # load inventory i = self.mgr.get_store('inventory') if i: @@ -36,6 +40,22 @@ class Inventory: for k, v in self._inventory.items(): if 'hostname' not in v: v['hostname'] = k + + # convert legacy non-IP addr? + try: + ipaddress.ip_address(v.get('addr')) + except ValueError: + ip = resolve_ip(cast(str, v.get('addr'))) + try: + ipaddress.ip_address(ip) + if not ip.startswith('127.0.'): + self.mgr.log.info(f"inventory: adjusted host {v['hostname']} addr '{v['addr']}' -> '{ip}'") + v['addr'] = ip + adjusted_addrs = True + except ValueError: + pass + if adjusted_addrs: + self.save() else: self._inventory = dict() logger.debug('Loaded inventory %s' % self._inventory)