Skip to content

Commit

Permalink
restore clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
simonccc committed Apr 2, 2024
1 parent 4bc1db3 commit ec64de4
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions lib/verb_etcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,7 @@ def list_snapshots():
# restore
if cmd == 'restore':

# need to check this file exists
if not os.path.isfile(token_fname):
kmsg_err(kname, f'{token_fname} not found exiting.')
exit(0)

k3stoken = open(token_fname, "r")
#token = k3stoken.read().rstrip()
token = k3stoken.read()

# passed snapshot
# assign passed snapshot argument
snapshot = sys.argv[3]

# check passed snapshot name exists
Expand All @@ -109,13 +100,21 @@ def list_snapshots():
print(snapshots)
exit()

# removes all nodes apart from image and master
if (workers >= 1 or masters == 3 ):
k3s_rm_cluster(restore = True)
# check token file exists
if not os.path.isfile(token_fname):
kmsg_err(kname, f'{token_fname} not found exiting.')
exit(0)

# do we need to check this output?
# get token value
token = open(token_fname, "r").read()

# info
kmsg_sys(kname,f'restoring {snapshot}')

# remove all nodes apart from image and master
if (workers >= 1 or masters == 3 ):
k3s_rm_cluster(restore = True)

# define restore command
restore_cmd = f'systemctl stop k3s && rm -rf /var/lib/rancher/k3s/server/db/ && k3s server --cluster-reset --cluster-reset-restore-path={snapshot} --token={token} {s3_string} ; systemctl start k3s'

Expand All @@ -140,14 +139,16 @@ def list_snapshots():

# delete extra nodes in the restored cluster
nodes = kubectl('get nodes').split()

# for each of returned nodes from kubectl
for node in nodes:

# if matches cluster name and not master node
if ( re.search((cname + '-'), node) and (node != ( cname + '-m1'))):
kmsg_sys(kname, ('removing stale node '+ node))
if re.search(f'{cname}-', node) and (node != f'{cname}-m1'):
kmsg_sys(kname, f'removing stale node {node}')

# need to check this..
kubectl('delete node ' + node)
kubectl(f'delete node {node}')

# run k3s update
k3s_update_cluster()

0 comments on commit ec64de4

Please sign in to comment.