Skip to content

Commit

Permalink
Refactor config / main for iso cluster deployment
Browse files Browse the repository at this point in the history
Signed-off-by: Salvatore Daniele <[email protected]>
  • Loading branch information
SalDaniele committed May 17, 2024
1 parent 8b3531b commit c0aaefd
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 41 deletions.
22 changes: 17 additions & 5 deletions cda.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from assistedInstaller import AssistedClientAutomation
from assistedInstallerService import AssistedInstallerService
from clustersConfig import ClustersConfig
from clusterDeployer import ClusterDeployer
from clusterDeployer import ClusterDeployer, IsoDeployer
from arguments import parse_args
import argparse
import host
Expand All @@ -13,15 +13,13 @@
from virtualBridge import VirBridge


def main_deploy(args: argparse.Namespace) -> None:
cc = ClustersConfig(args.config, args.worker_range)

def main_deploy_openshift(cc: ClustersConfig, args: argparse.Namespace) -> None:
# Make sure the local virtual bridge base configuration is correct.
local_bridge = VirBridge(host.LocalHost(), cc.local_bridge_config)
local_bridge.configure(api_port=None)

# microshift does not use assisted installer so we don't need this check
if args.url == cc.ip_range[0] and cc.kind == "openshift":
if args.url == cc.ip_range[0]:
ais = AssistedInstallerService(cc.version, args.url, cc.proxy, cc.noproxy)
ais.start()
else:
Expand All @@ -47,6 +45,20 @@ def main_deploy(args: argparse.Namespace) -> None:
ais.stop()


def main_deploy_iso(cc: ClustersConfig, args: argparse.Namespace) -> None:
id = IsoDeployer(cc, args.steps)
id.deploy()


def main_deploy(args: argparse.Namespace) -> None:
cc = ClustersConfig(args.config, args.worker_range)

if cc.kind == "openshift":
main_deploy_openshift(cc, args)
else:
main_deploy_iso(cc, args)


def main_snapshot(args: argparse.Namespace) -> None:
args = parse_args()
cc = ClustersConfig(args.config, args.worker_range)
Expand Down
35 changes: 20 additions & 15 deletions clusterDeployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from clusterHost import ClusterHost
import dnsutil
from virshPool import VirshPool
from arguments import WORKERS_STEP, MASTERS_STEP, POST_STEP
from arguments import PRE_STEP, WORKERS_STEP, MASTERS_STEP, POST_STEP
import isoCluster


Expand Down Expand Up @@ -197,12 +197,12 @@ def need_external_network(self) -> bool:

def deploy(self) -> None:
if self._cc.masters:
if "pre" in self.steps:
if PRE_STEP in self.steps:
self._preconfig()
else:
logger.info("Skipping pre configuration.")

if self._cc.kind == "openshift":
if self._cc.kind != "microshift":
if WORKERS_STEP in self.steps or MASTERS_STEP in self.steps:
self.teardown_workers()
if MASTERS_STEP in self.steps:
Expand All @@ -226,12 +226,6 @@ def deploy(self) -> None:
microshift.deploy(self._cc.fullConfig["name"], self._cc.masters[0], self._cc.external_port, version)
else:
logger.error_and_exit("Masters must be of length one for deploying microshift")
if self._cc.kind == "iso" and MASTERS_STEP in self.steps:
if len(self._cc.masters) == 1:
self.deploy_cluster_from_iso()
else:
logger.error("Masters must be of length one for deploying from iso")
sys.exit(-1)
if POST_STEP in self.steps:
self._postconfig()
cmd = "apply -f manifests/monitoring-config.yaml"
Expand Down Expand Up @@ -635,15 +629,26 @@ def wait_for_workers(self) -> None:

time.sleep(30)

def deploy_cluster_from_iso(self) -> None:
master = self._cc.masters[0]
if master.mac is None:

class IsoDeployer:
def __init__(self, cc: ClustersConfig, steps: list[str]):
self.steps = steps
self._cc = cc
self._extra_config = ExtraConfigRunner(cc)

if len(self._cc.masters) != 1:
logger.error("Masters must be of length one for deploying from iso")
sys.exit(-1)

self._master = self._cc.masters[0]
if self._master.mac is None:
logger.error_and_exit(f"No MAC address provided for cluster {self._cc.name}, exiting")
if master.ip is None:
if self._master.ip is None:
logger.error_and_exit(f"No IP address provided for cluster {self._cc.name}, exiting")
if master.name is None:
if self._master.name is None:
logger.error_and_exit(f"No name provided for cluster {self._cc.name}, exiting")
if not self._cc.network_api_port or self._cc.network_api_port == "auto":
logger.error_and_exit(f"Network API port with connection to {self._cc.name} must be specified, exiting")

isoCluster.IPUIsoBoot(self._cc, master, self._cc.install_iso)
def deploy(self):
isoCluster.IPUIsoBoot(self._cc, self._master, self._cc.install_iso)
47 changes: 26 additions & 21 deletions clustersConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ class ClustersConfig:
masters: list[NodeConfig] = []
workers: list[NodeConfig] = []
configured_workers: list[NodeConfig] = []
local_bridge_config: BridgeConfig
remote_bridge_config: BridgeConfig
local_bridge_config: Optional[BridgeConfig] = None
remote_bridge_config: Optional[BridgeConfig] = None
full_ip_range: tuple[str, str]
ip_range: tuple[str, str]
hosts: list[HostConfig] = []
Expand Down Expand Up @@ -201,6 +201,30 @@ def __init__(self, yaml_path: str, worker_range: common.RangeList):
self.configured_workers = [NodeConfig(self.name, **w) for w in cc["workers"]]
self.workers = [NodeConfig(self.name, **w) for w in worker_range.filter_list(cc["workers"])]

if self.kind == "openshift":
self.configure_ip_range()

# creates hosts entries for each referenced node name
node_names = {x["name"] for x in cc["hosts"]}
for node in self.all_nodes():
if node.node not in node_names:
cc["hosts"].append({"name": node.node})
node_names.add(node.node)

if not self.is_sno():
self.api_vip = {'ip': cc["api_vip"]}
self.ingress_vip = {'ip': cc["ingress_vip"]}

for e in cc["hosts"]:
self.hosts.append(HostConfig(self.network_api_port, **e))

for c in cc["preconfig"]:
self.preconfig.append(ExtraConfigArgs(**c))
for c in cc["postconfig"]:
self.postconfig.append(ExtraConfigArgs(**c))

def configure_ip_range(self) -> None:
cc = self.fullConfig
# Reserve IPs for AI, masters and workers.
ip_mask = cc["ip_mask"]
ip_range = cc["ip_range"].split("-")
Expand Down Expand Up @@ -230,25 +254,6 @@ def __init__(self, yaml_path: str, worker_range: common.RangeList):
self.local_bridge_config = BridgeConfig(ip=self.ip_range[0], mask=ip_mask, dynamic_ip_range=dynamic_ip_range)
self.remote_bridge_config = BridgeConfig(ip=ip_range[1], mask=ip_mask)

# creates hosts entries for each referenced node name
node_names = {x["name"] for x in cc["hosts"]}
for node in self.all_nodes():
if node.node not in node_names:
cc["hosts"].append({"name": node.node})
node_names.add(node.node)

if not self.is_sno():
self.api_vip = {'ip': cc["api_vip"]}
self.ingress_vip = {'ip': cc["ingress_vip"]}

for e in cc["hosts"]:
self.hosts.append(HostConfig(self.network_api_port, **e))

for c in cc["preconfig"]:
self.preconfig.append(ExtraConfigArgs(**c))
for c in cc["postconfig"]:
self.postconfig.append(ExtraConfigArgs(**c))

def get_last_ip(self) -> str:
hostconn = host.LocalHost()
last_ip = "0.0.0.0"
Expand Down

0 comments on commit c0aaefd

Please sign in to comment.