Skip to content

Commit

Permalink
k3s: storeparameter boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
karmab committed Apr 8, 2024
1 parent 0631633 commit bd717d4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
33 changes: 18 additions & 15 deletions kvirt/cluster/k3s/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ def update_ip_alias(config, nodes):


def scale(config, plandir, cluster, overrides):
storeparameters = overrides['storeparameters']
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 os.path.exists(f"{clusterdir}/kcli_parameters.yml"):
if storeparameters 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 @@ -67,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 os.path.exists(clusterdir):
if storeparameters and 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 @@ -113,6 +114,7 @@ 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 @@ -195,19 +197,20 @@ 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
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)
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)
for role in ['ctlplanes', 'workers']:
if (role == 'ctlplanes' and ctlplanes == 1) or (role == 'workers' and workers == 0):
continue
Expand Down
1 change: 1 addition & 0 deletions kvirt/cluster/k3s/kcli_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ cloud_storage: true
cloud_dns: false
cloud_native: false
extra_scripts: []
storeparameter: true

0 comments on commit bd717d4

Please sign in to comment.