]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: convert host addr if non-IP to IP
authorSage Weil <sage@newdream.net>
Tue, 25 May 2021 20:10:49 +0000 (16:10 -0400)
committerSage Weil <sage@newdream.net>
Thu, 27 May 2021 16:00:20 +0000 (12:00 -0400)
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 <sage@newdream.net>
src/pybind/mgr/cephadm/inventory.py

index b79ca23578868ff7afb19154a0ae76db07be8c7f..c2ce50db8c86b929179b0a199e87677ac825e1ab 100644 (file)
@@ -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)