Bläddra i källkod

Centralize etcd/schedulability logic for each host.

Devan Goodwin 9 år sedan
förälder
incheckning
bd43109412

+ 3 - 6
utils/src/ooinstall/cli_installer.py

@@ -212,16 +212,13 @@ deployment."""
 
 
 def print_host_summary(all_hosts, host):
-    description_tokens = []
-    masters = [ahost for ahost in all_hosts if ahost.master]
-    nodes = [ahost for ahost in all_hosts if ahost.node]
     click.echo("- %s" % host.connect_to)
     if host.master:
         click.echo("  - OpenShift Master")
     if host.node:
-        if not host.master:
+        if host.is_dedicated_node():
             click.echo("  - OpenShift Node (Dedicated)")
-        elif host.master and len(masters) == len(nodes):
+        elif host.is_schedulable_node(all_hosts):
             click.echo("  - OpenShift Node")
         else:
             click.echo("  - OpenShift Node (Unscheduled)")
@@ -231,7 +228,7 @@ def print_host_summary(all_hosts, host):
         else:
             click.echo("  - Load Balancer (HAProxy)")
     if host.master:
-        if len(masters) > 1:
+        if host.is_etcd_member(all_hosts):
             click.echo("  - Etcd Member")
         else:
             click.echo("  - Etcd (Embedded)")

+ 26 - 0
utils/src/ooinstall/oo_config.py

@@ -73,6 +73,32 @@ class Host(object):
                 d[prop] = getattr(self, prop)
         return d
 
+    def is_etcd_member(self, all_hosts):
+        """ Will this host be a member of a standalone etcd cluster. """
+        if not self.master:
+            return False
+        masters = [host for host in all_hosts if host.master]
+        if len(masters) > 1:
+            return True
+        return False
+
+    def is_dedicated_node(self):
+        """ Will this host be a dedicated node. (not a master) """
+        return self.node and not self.master
+
+    def is_schedulable_node(self, all_hosts):
+        """ Will this host be a node marked as schedulable. """
+        if not self.node:
+            return False
+        if not self.master:
+            return True
+
+        masters = [host for host in all_hosts if host.master]
+        nodes = [host for host in all_hosts if host.node]
+        if len(masters) == len(nodes):
+            return True
+        return False
+
 
 class OOConfig(object):
     default_dir = os.path.normpath(

+ 8 - 13
utils/src/ooinstall/openshift_ansible.py

@@ -58,19 +58,14 @@ def generate_inventory(hosts):
 
     base_inventory.write('\n[nodes]\n')
 
-    # TODO: It would be much better to calculate the schedulability elsewhere
-    # and store it on the Node object.
-    if set(nodes) == set(masters):
-        for node in nodes:
-            write_host(node, base_inventory, True)
-    else:
-        for node in nodes:
-            # TODO: Until the Master can run the SDN itself we have to configure the Masters
-            # as Nodes too.
-            schedulable = None
-            if node in masters:
-                schedulable = False
-            write_host(node, base_inventory, schedulable)
+    for node in nodes:
+        # Let the fact defaults decide if we're not a master:
+        schedulable = None
+
+        # If the node is also a master, we must explicitly set schedulablity:
+        if node.master:
+            schedulable = node.is_schedulable_node(hosts)
+        write_host(node, base_inventory, schedulable)
 
     if not getattr(proxy, 'preconfigured', True):
         base_inventory.write('\n[lb]\n')