🐛 Stack trace error when trying to delete non-existant k3s cluster #35

Closed
opened 2022-12-14 07:15:10 +00:00 by jessebot · 0 comments
jessebot commented 2022-12-14 07:15:10 +00:00 (Migrated from github.com)

Describe the Bug

Tried to wipe out a k3s cluster thinking I was on a different machine and just happened to catch this error, which didn't actually break anything, but gave the stack trace below. I think this has to do with the fact that I wrap the subprocess in a try/except here:
https://github.com/jessebot/smol-k8s-lab/blob/v0.10.4/smol_k8s_lab/subproc.py#L105

Then it can never actually get to the return_code = p.returncode part just below that, because p is only set in the local try block, and that block fails, because the k3s scripts are not there.

Steps to Reproduce Bug

  1. run command: smol-k8s-lab k3s -D

Output from Above Steps

In my config file, I have a log.file set and this is the output from the logs:

[07:59:24] INFO main: Logging configured
[07:59:24] INFO subproc: [green] Running:[/green] [yellow]k3s-uninstall.sh[/yellow]

[07:59:24] ERROR run_subprocess: [Errno 2] No such file or directory: 'k3s-uninstall.sh'

However, this is what outputted to the console:

smol-k8s-lab k3s -D

╭──────────────────────────────────────────── Compatibility Check ────────────────────────────────────────────╮
│ Operating System and Architechure supported ♥                                                               │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────╯


────────────────────────────────────── ☁  ʕ ᵔﻌᵔʔ Bye bye, k3s! ʕᵔﻌᵔ ʔ ☁  ──────────────────────────────────────

Traceback (most recent call last):
  File "/usr/local/bin/smol-k8s-lab", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/smol_k8s_lab/__init__.py", line 177, in main
    delete_cluster(k8s)
  File "/usr/local/lib/python3.11/site-packages/smol_k8s_lab/__init__.py", line 106, in delete_cluster
    uninstall_k3s()
  File "/usr/local/lib/python3.11/site-packages/smol_k8s_lab/k8s_distros/k3s.py", line 62, in uninstall_k3s
    subproc(['k3s-uninstall.sh'], error_ok=True, spinner=False)
  File "/usr/local/lib/python3.11/site-packages/smol_k8s_lab/subproc.py", line 79, in subproc
    output = run_subprocess(cmd, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/smol_k8s_lab/subproc.py", line 114, in run_subprocess
    return_code = p.returncode
                  ^
UnboundLocalError: cannot access local variable 'p' where it is not associated with a value

Expected behavior

smol-k8s-lab should fail gracefully and just say that k3s is not currently installed.

## Describe the Bug Tried to wipe out a k3s cluster thinking I was on a different machine and just happened to catch this error, which didn't actually break anything, but gave the stack trace below. I think this has to do with the fact that I wrap the subprocess in a try/except here: https://github.com/jessebot/smol-k8s-lab/blob/v0.10.4/smol_k8s_lab/subproc.py#L105 Then it can never actually get to the `return_code = p.returncode` part just below that, because p is only set in the local try block, and that block fails, because the k3s scripts are not there. ### Steps to Reproduce Bug 1. run command: `smol-k8s-lab k3s -D` ### Output from Above Steps In my config file, I have a `log.file` set and this is the output from the logs: ```log [07:59:24] INFO main: Logging configured [07:59:24] INFO subproc: [green] Running:[/green] [yellow]k3s-uninstall.sh[/yellow] [07:59:24] ERROR run_subprocess: [Errno 2] No such file or directory: 'k3s-uninstall.sh' ``` However, this is what outputted to the console: ``` smol-k8s-lab k3s -D ╭──────────────────────────────────────────── Compatibility Check ────────────────────────────────────────────╮ │ Operating System and Architechure supported ♥ │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ────────────────────────────────────── ☁ ʕ ᵔﻌᵔʔ Bye bye, k3s! ʕᵔﻌᵔ ʔ ☁ ────────────────────────────────────── Traceback (most recent call last): File "/usr/local/bin/smol-k8s-lab", line 8, in <module> sys.exit(main()) ^^^^^^ File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1130, in __call__ return self.main(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1055, in main rv = self.invoke(ctx) ^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1404, in invoke return ctx.invoke(self.callback, **ctx.params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/click/core.py", line 760, in invoke return __callback(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/smol_k8s_lab/__init__.py", line 177, in main delete_cluster(k8s) File "/usr/local/lib/python3.11/site-packages/smol_k8s_lab/__init__.py", line 106, in delete_cluster uninstall_k3s() File "/usr/local/lib/python3.11/site-packages/smol_k8s_lab/k8s_distros/k3s.py", line 62, in uninstall_k3s subproc(['k3s-uninstall.sh'], error_ok=True, spinner=False) File "/usr/local/lib/python3.11/site-packages/smol_k8s_lab/subproc.py", line 79, in subproc output = run_subprocess(cmd, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/smol_k8s_lab/subproc.py", line 114, in run_subprocess return_code = p.returncode ^ UnboundLocalError: cannot access local variable 'p' where it is not associated with a value ``` #### Expected behavior `smol-k8s-lab` should fail gracefully and just say that k3s is not currently installed.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
small-hack/smol-k8s-lab#35
No description provided.