Summary
In run_kraken.py around line 231, a bare except: clause is used when initializing
the Kubernetes clients (KrknKubernetes and KrknOpenshift). This is a well-known
Python anti-pattern that silently catches all exceptions, including SystemExit,
KeyboardInterrupt, and NameError making failures invisible and extremely hard
to debug.
The Problem
The original code:
try:
kubeconfig_path = str(kubeconfig_path)
kubecli = KrknKubernetes(kubeconfig_path=kubeconfig_path)
ocpcli = KrknOpenshift(kubeconfig_path=kubeconfig_path)
except:
kubecli.initialize_clients(None) # NameError if kubecli was never assigned
Four issues with this:
- Bare
except: catches everything, including KeyboardInterrupt and SystemExit,
which should never be swallowed.
- Silent failure, if
KrknKubernetes() raises an exception, the error is swallowed
with no log message. You get zero feedback about what went wrong.
NameError in the except block, if the exception is raised before kubecli is
assigned, then kubecli.initialize_clients(None) raises a NameError. That
secondary exception is also silently lost.
kubeconfig_path bare expression kubeconfig_path on its own does nothing useful;
it was likely intended as an existence check but has no effect.
Expected Behaviour
- Catch only specific, expected exceptions (e.g.
Exception)
- Log a clear error message when client initialization fails
- Exit gracefully with a non-zero code instead of proceeding with an undefined
kubecli
Proposed Fix
try:
kubeconfig_path = str(kubeconfig_path)
kubecli = KrknKubernetes(kubeconfig_path=kubeconfig_path)
ocpcli = KrknOpenshift(kubeconfig_path=kubeconfig_path)
except Exception as e:
logging.error(
"Failed to initialize Kubernetes client with kubeconfig %s: %s",
kubeconfig_path, e,
)
return -1
Steps to Reproduce
- Provide an invalid or inaccessible kubeconfig path in
config.yaml
- Run
python run_kraken.py
- No error is logged execution continues with an undefined
kubecli, leading to
a confusing AttributeError or NameError later in the run
Impact
- Makes debugging initialization failures very difficult
- Can cause misleading secondary errors far from the actual root cause
- Violates PEP 8 and Python best practices
Summary
In
run_kraken.pyaround line 231, a bareexcept:clause is used when initializingthe Kubernetes clients (
KrknKubernetesandKrknOpenshift). This is a well-knownPython anti-pattern that silently catches all exceptions, including
SystemExit,KeyboardInterrupt, andNameErrormaking failures invisible and extremely hardto debug.
The Problem
The original code:
Four issues with this:
except:catches everything, includingKeyboardInterruptandSystemExit,which should never be swallowed.
KrknKubernetes()raises an exception, the error is swallowedwith no log message. You get zero feedback about what went wrong.
NameErrorin the except block, if the exception is raised beforekubecliisassigned, then
kubecli.initialize_clients(None)raises aNameError. Thatsecondary exception is also silently lost.
kubeconfig_pathbare expressionkubeconfig_pathon its own does nothing useful;it was likely intended as an existence check but has no effect.
Expected Behaviour
Exception)kubecliProposed Fix
Steps to Reproduce
config.yamlpython run_kraken.pykubecli, leading toa confusing
AttributeErrororNameErrorlater in the runImpact