Skip to content

Commit

Permalink
kube: storedparameters
Browse files Browse the repository at this point in the history
  • Loading branch information
karmab committed Apr 9, 2024
1 parent 4fb6118 commit dee05fd
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 22 deletions.
3 changes: 2 additions & 1 deletion kvirt/cluster/hypershift/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ def handle_baremetal_iso(config, plandir, cluster, data, baremetal_hosts=[]):


def scale(config, plandir, cluster, overrides):
storedparameters = overrides.get('storedparameters', True)
provider = config.type
plan = cluster
data = {'cluster': cluster, 'kube': cluster, 'kubetype': 'hypershift', 'namespace': 'clusters', 'assisted': False,
Expand Down Expand Up @@ -173,7 +174,7 @@ def scale(config, plandir, cluster, overrides):
with open(f"{clusterdir}/ignition.sh", 'w') as f:
f.write(ignitionscript)
call(f'bash {clusterdir}/ignition.sh', shell=True)
if os.path.exists(f"{clusterdir}/kcli_parameters.yml"):
if storedparameters and os.path.exists(f"{clusterdir}/kcli_parameters.yml"):
with open(f"{clusterdir}/kcli_parameters.yml", 'r') as install:
installparam = safe_load(install)
data.update(installparam)
Expand Down
1 change: 1 addition & 0 deletions kvirt/cluster/hypershift/kcli_plan_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@ cloud_storage: true
image_overrides:
ipv6: false
dualstack: false
storedparameters: true
34 changes: 16 additions & 18 deletions kvirt/cluster/k3s/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ def update_ip_alias(config, nodes):


def scale(config, plandir, cluster, overrides):
storeparameters = overrides.get('storeparameters', True)
storedparameters = overrides.get('storedparameters', True)
provider = config.type
plan = cluster
data = {'cluster': cluster, 'domain': 'karmalabs.corp', 'image': 'ubuntu2004', 'kube': cluster, 'kubetype': 'k3s',
'sdn': 'flannel', 'extra_scripts': [], 'cloud_native': False, 'ctlplanes': 1, 'workers': 0}
data['basedir'] = '/workdir' if container_mode() else '.'
cluster = data['cluster']
clusterdir = os.path.expanduser(f"~/.kcli/clusters/{cluster}")
if storeparameters and os.path.exists(f"{clusterdir}/kcli_parameters.yml"):
if storedparameters and os.path.exists(f"{clusterdir}/kcli_parameters.yml"):
with open(f"{clusterdir}/kcli_parameters.yml", 'r') as install:
installparam = safe_load(install)
data.update(installparam)
Expand All @@ -68,7 +68,7 @@ def scale(config, plandir, cluster, overrides):
first_info = config.k.info(f'{cluster}-ctlplane-0') or config.k.info(f'{cluster}-master-0')
data['first_ip'] = first_info.get('private_ip') or first_info.get('ip')
pprint(f"Scaling on client {client}")
if storeparameters and os.path.exists(clusterdir):
if os.path.exists(clusterdir):
with open(f"{clusterdir}/kcli_parameters.yml", 'w') as paramfile:
safe_dump(data, paramfile)
vmrules_all_names = []
Expand Down Expand Up @@ -114,7 +114,6 @@ def create(config, plandir, cluster, overrides):
data = safe_load(open(f'{plandir}/kcli_plan_default.yml'))
data.update(overrides)
fix_typos(data)
storeparameter = data['storeparameter']
cloud_dns = data['cloud_dns']
data['cloud_lb'] = overrides.get('cloud_lb', provider in cloud_providers and data['ctlplanes'] > 1)
cloud_lb = data['cloud_lb']
Expand Down Expand Up @@ -197,20 +196,19 @@ def create(config, plandir, cluster, overrides):
first_info = config.k.info(f'{cluster}-ctlplane-0')
first_ip = first_info.get('private_ip') or first_info.get('ip')
data['first_ip'] = first_ip
if storeparameter:
with open(f"{clusterdir}/kcli_parameters.yml", 'w') as p:
installparam = overrides.copy()
installparam['client'] = config.client
installparam['cluster'] = cluster
installparam['api_ip'] = api_ip
installparam['first_ip'] = first_ip
installparam['plan'] = plan
installparam['kubetype'] = 'k3s'
installparam['image'] = image
if not cloud_lb and ctlplanes > 1:
installparam['virtual_router_id'] = virtual_router_id
installparam['auth_pass'] = auth_pass
safe_dump(installparam, p, default_flow_style=False, encoding='utf-8', allow_unicode=True)
with open(f"{clusterdir}/kcli_parameters.yml", 'w') as p:
installparam = overrides.copy()
installparam['client'] = config.client
installparam['cluster'] = cluster
installparam['api_ip'] = api_ip
installparam['first_ip'] = first_ip
installparam['plan'] = plan
installparam['kubetype'] = 'k3s'
installparam['image'] = image
if not cloud_lb and ctlplanes > 1:
installparam['virtual_router_id'] = virtual_router_id
installparam['auth_pass'] = auth_pass
safe_dump(installparam, p, default_flow_style=False, encoding='utf-8', allow_unicode=True)
for role in ['ctlplanes', 'workers']:
if (role == 'ctlplanes' and ctlplanes == 1) or (role == 'workers' and workers == 0):
continue
Expand Down
2 changes: 1 addition & 1 deletion kvirt/cluster/k3s/kcli_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ cloud_storage: true
cloud_dns: false
cloud_native: false
extra_scripts: []
storeparameter: true
storedparameters: true
3 changes: 2 additions & 1 deletion kvirt/cluster/kubeadm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@


def scale(config, plandir, cluster, overrides):
storedparameters = overrides.get('storedparameters', True)
plan = cluster
data = {'cluster': cluster, 'sslip': False, 'kube': cluster, 'kubetype': 'generic', 'image': 'centos8stream',
'extra_scripts': []}
Expand Down Expand Up @@ -56,7 +57,7 @@ def scale(config, plandir, cluster, overrides):
first_info = config.k.info(f'{cluster}-ctlplane-0')
first_ip = first_info.get('private_ip') or first_info.get('ip')
data['first_ip'] = first_ip
if os.path.exists(f"{clusterdir}/kcli_parameters.yml"):
if storedparameters and os.path.exists(f"{clusterdir}/kcli_parameters.yml"):
with open(f"{clusterdir}/kcli_parameters.yml", 'r') as install:
installparam = safe_load(install)
data.update(installparam)
Expand Down
1 change: 1 addition & 0 deletions kvirt/cluster/kubeadm/kcli_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ token:
async: false
cloud_dns: false
registry: false
storedparameters: true
3 changes: 2 additions & 1 deletion kvirt/cluster/openshift/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ def process_baremetal_rules(config, cluster, baremetal_hosts, vmrules=[], overri


def scale(config, plandir, cluster, overrides):
storedparameters = overrides.get('storedparameters', True)
plan = cluster
client = config.client
provider = config.type
Expand All @@ -633,7 +634,7 @@ def scale(config, plandir, cluster, overrides):
os.mkdir(clusterdir)
ignition_version = overrides['ignition_version']
create_ignition_files(config, plandir, cluster, domain, api_ip=api_ip, ignition_version=ignition_version)
if os.path.exists(f"{clusterdir}/kcli_parameters.yml"):
if storedparameters and os.path.exists(f"{clusterdir}/kcli_parameters.yml"):
with open(f"{clusterdir}/kcli_parameters.yml", 'r') as install:
installparam = safe_load(install)
data.update(installparam)
Expand Down

0 comments on commit dee05fd

Please sign in to comment.