fix: replace bare except with Exception handler in Kubernetes client init (#1265)

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 #1264

Signed-off-by: Parth Agrawal <parth.agrawal4002@gmail.com>
Co-authored-by: Paige Patton <64206430+paigerube14@users.noreply.github.com>
This commit is contained in:
Parth Agrawal
2026-05-28 14:08:21 -04:00
committed by GitHub
co-authored by Paige Patton
parent e7ea0ee4c5
commit c0cf47dfed
+4 -2
View File
@@ -223,8 +223,10 @@ def main(options, command: Optional[str]) -> int:
# krkn-lib-kubernetes init
kubecli = KrknKubernetes(kubeconfig_path=kubeconfig_path)
ocpcli = KrknOpenshift(kubeconfig_path=kubeconfig_path)
except:
kubecli.initialize_clients(None)
except Exception as e:
logging.error("Failed to initialize Kubernetes clients: %s" % e)
kubecli = KrknKubernetes(kubeconfig_path=None)
ocpcli = KrknOpenshift(kubeconfig_path=None)
distribution = "kubernetes"
if ocpcli.is_openshift():