Skip to content

fix: replace bare except with Exception handler in Kubernetes client initialization#1265

Open
parth-agrawall wants to merge 1 commit into
krkn-chaos:mainfrom
parth-agrawall:fix/bare-except-kubecli-initialization
Open

fix: replace bare except with Exception handler in Kubernetes client initialization#1265
parth-agrawall wants to merge 1 commit into
krkn-chaos:mainfrom
parth-agrawall:fix/bare-except-kubecli-initialization

Conversation

@parth-agrawall
Copy link
Copy Markdown

Description

The Kubernetes client initialization block in run_kraken.py used a bare except: clause that caused a NameError crash whenever initialization failed, completely hiding the original error from the user.

Root Cause

If KrknKubernetes() raised an exception before kubecli was assigned, the except handler immediately tried to call kubecli.initialize_clients(None) on an undefined variable. This replaced the real error with an unrelated NameError. The bare except: also unintentionally caught SystemExit and KeyboardInterrupt.

Changes

  • run_kraken.py: Replaced bare except: with except Exception as e
  • Added logging.error() to surface the actual initialization failure
  • Initialized both kubecli and ocpcli with kubeconfig_path=None as fallback so subsequent code referencing these variables does not crash with NameError

Testing

  • When kubeconfig initialization fails, the error is now logged clearly
  • kubecli and ocpcli are always defined after the try/except block
  • SystemExit and KeyboardInterrupt are no longer swallowed

Related Issue

Closes #1264


Signed-off-by: Parth Agrawal parth.agrawal4002@gmail.com

…init

The bare except clause in the Kubernetes client initialization block
caused a NameError crash when initialization failed. If KrknKubernetes()
raised an exception before kubecli was assigned, the except handler
attempted to call kubecli.initialize_clients(None) on an undefined
variable, masking the original error entirely.

Replaced the bare except with except Exception as e to:
- Log the actual initialization error for visibility
- Initialize both kubecli and ocpcli with None kubeconfig as fallback
  so subsequent code referencing these variables does not crash
- Avoid catching SystemExit and KeyboardInterrupt unintentionally

Fixes krkn-chaos#1264

Signed-off-by: Parth Agrawal <parth.agrawal4002@gmail.com>
@qodo-code-review
Copy link
Copy Markdown

ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one.

@paigerube14
Copy link
Copy Markdown
Collaborator

/agentic-review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: bare except clause causes NameError during Kubernetes client initialization failure in run_kraken.py

2 participants