Skip to content

Commit

Permalink
add k3s check-config + misc
Browse files Browse the repository at this point in the history
  • Loading branch information
simonccc committed Aug 24, 2024
1 parent a2c41bf commit 1fa1387
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
1 change: 1 addition & 0 deletions kopsrox.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"k3s": {
"export-token" : '',
"kubeconfig" : '',
"check-config" : '',
},
"etcd": {
"snapshot" : '',
Expand Down
17 changes: 8 additions & 9 deletions lib/kopsrox_k3s.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def k3s_init_node(vmid = masterid,nodetype = 'master'):
# nodetype error check
if nodetype not in ['master', 'slave', 'worker']:
kmsg('k3s_init-node', f'{nodetype} invalid nodetye', 'err')
exit()
exit(0)

# check status of node
try:
Expand Down Expand Up @@ -103,7 +103,6 @@ def k3s_init_node(vmid = masterid,nodetype = 'master'):
init_cmd = f'{k3s_install_worker}{k3s_token_cmd} sh -s'

# run command
#print(init_cmd)
init_cmd_out = qaexec(vmid,init_cmd)

# wait until ready
Expand Down Expand Up @@ -151,7 +150,6 @@ def k3s_rm_cluster(restore = False):
continue

# remove node from cluster and proxmox
#print(vmname)
if vmname == f'{cluster_name}-m1':
destroy(vmid)
else:
Expand Down Expand Up @@ -244,6 +242,13 @@ def kubectl(cmd):
kcmd = qaexec(masterid,k3s_cmd)
return(kcmd)

# run k3s check config
def k3s_check_config():
kmsg('k3s_check-config', 'checking k3s config')
k3s_cmd = f'/usr/local/bin/k3s check-config'
kcmd = qaexec(masterid,k3s_cmd)
print(kcmd)

# export k3s token
def export_k3s_token():

Expand Down Expand Up @@ -300,12 +305,6 @@ def install_kube_vip():
print(kv_install)
exit(0)

# this should only be required for dev?
def delete_kube_vip():
print('foo')
# can only be done when master eq 1?
# reverse of install?

# return current vip master
def get_kube_vip_master():
kubevip_q = f'get nodes --selector kube-vip.io/has-ip={network_ip}'
Expand Down
12 changes: 11 additions & 1 deletion lib/kopsrox_proxmox.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,19 @@ def qaexec(vmid = masterid,cmd = 'uptime'):

# check for err-data
try:

# if err-data exists
if (pid_check['err-data']):
return(pid_check['err-data'])

# print err data warning
kmsg(kname, pid_check['err-data'].strip(), 'err')

# if there is output return that otherwise exit
if (pid_check['err-data'] and pid_check['out-data']):
return(pid_check['out-data'].strip())
else:
exit(0)

except:
try:
# this is where data gets returned for an OK command
Expand Down
8 changes: 5 additions & 3 deletions lib/verb_k3s.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/usr/bin/env python3

# functions
#from kopsrox_config import vmnames,cluster_info, cluster_id, vms, vmip, cloudinituser
from kopsrox_k3s import export_k3s_token, kubeconfig
#from kopsrox_proxmox import clone
from kopsrox_k3s import export_k3s_token, kubeconfig, k3s_check_config
from kopsrox_kmsg import kmsg

# other imports
Expand All @@ -28,3 +26,7 @@
# export kubeconfig to file
if cmd == 'kubeconfig':
kubeconfig()

# check k3s config
if cmd == 'check-config':
k3s_check_config()

0 comments on commit 1fa1387

Please sign in to comment.