Skip to content

Commit

Permalink
refactor: clean up unused code
Browse files Browse the repository at this point in the history
The Traefik backup relies on the normal module-backup procedure. Saving
Traefik's data inside the cluster backup is no longer required.
  • Loading branch information
DavidePrincipi committed Jan 27, 2025
1 parent fb95fc1 commit 4828180
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,6 @@ rdb.set('cluster/backup_sequence', max_backup)
if 'override' in dump['cluster'] and dump['cluster']['override']['modules']:
rdb.hset(f'cluster/override/modules', mapping=dump['cluster']['override']['modules'])

# Restore traefik configuration
if 'leader' in dump['traefik']:
tk_instance = rdb.get('cluster/default_instance/traefik')
tk_state = f"{pwd.getpwnam(tk_instance).pw_dir}/.config/state"
tk_flags = f"{tk_state}/manual_flags"
tk_configs = f"{tk_state}/configs"
tk_certs = f"{tk_state}/custom_certificates"
os.makedirs(tk_flags, exist_ok=True)
os.makedirs(tk_certs, exist_ok=True)
os.makedirs(tk_configs, exist_ok=True)
for route in dump['traefik']['leader']['routes'].keys():
with open(f'{tk_flags}/{route}', 'w') as fpm:
pass
with open(f'{tk_configs}/{route}.yml', 'w') as fpr:
fpr.write(dump['traefik']['leader']['routes'][route])
for cert in dump['traefik']['leader']['uploaded_certificates'].keys():
with open(f'{tk_certs}/{cert}.key', 'w') as fpk:
fpk.write(dump['traefik']['leader']['uploaded_certificates'][cert]['key'])
with open(f'{tk_certs}/{cert}.crt', 'w') as fpc:
fpc.write(dump['traefik']['leader']['uploaded_certificates'][cert]['crt'])
agent.run_helper('chown', '-R', '-c', f"{tk_instance}:{tk_instance}", tk_state)

# Restore subscription info, if present
if 'subscription' in dump['cluster'] and dump['cluster']['subscription']:
rdb.hset('cluster/subscription', mapping=dump['cluster']['subscription'])
Expand Down
17 changes: 1 addition & 16 deletions core/imageroot/var/lib/nethserver/cluster/bin/cluster-backup
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ rdb = agent.redis_connect(host='127.0.0.1')

VERSION = "3"

dump = { 'version': VERSION, 'modules': {}, 'vpn': {}, 'cluster': { 'node_count': 0, 'subscription': {}, 'apply_updates': {}, 'repository': {}, 'backup': {}, 'backup_repository': {}, 'user_domain': { 'ldap': {} },'override': {'modules': {} } }, 'traefik': {} }
dump = { 'version': VERSION, 'modules': {}, 'vpn': {}, 'cluster': { 'node_count': 0, 'subscription': {}, 'apply_updates': {}, 'repository': {}, 'backup': {}, 'backup_repository': {}, 'user_domain': { 'ldap': {} },'override': {'modules': {} } } }

# cluster: number of nodes
dump['cluster']['node_count'] = len(set(rdb.hvals('cluster/module_node')))
Expand Down Expand Up @@ -94,22 +94,7 @@ for m in rdb.scan_iter('module/*/backups'):
dump['modules'][uuid] = {'backups': []}
dump['modules'][uuid]['backups'] = sorted(rdb.smembers(m))

# traefik: custom route and uploaded certificates
leader_id = rdb.hget("cluster/environment", "NODE_ID")
for tk in rdb.scan_iter('module/traefik*/flags'):
tk_instance = tk.removesuffix('/flags')
dump_task_result = agent.tasks.run(tk_instance, "dump-custom-config",
data={},
endpoint="redis://cluster-leader",
)

if dump_task_result['exit_code'] == 0:
# instance on leader has a special name used during restore
if rdb.hget(f'{tk_instance}/environment', 'NODE_ID') == leader_id:
tk_name = 'leader'
else:
tk_name = tk_instance.removeprefix('module/')
dump['traefik'][tk_name] = dump_task_result['output']

# leader vpn endpoint, required to invoke the create-cluster
dump['vpn']['endpoint'] = rdb.hget(f'node/{leader_id}/vpn', 'endpoint')
Expand Down

0 comments on commit 4828180

Please sign in to comment.