Skip to content

Commit 304e81c

Browse files
committed
refactor: remove unused import and simplify exception handling in Kubectl class
1 parent bc5c8b4 commit 304e81c

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

‎src/github_actions/common/utils/kubectl.py‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import subprocess
2-
3-
41
from ..utils.cmd import BaseCommand, CMDInterface
52

63

@@ -9,6 +6,12 @@ def __init__(self, kubectl_download_url="https://dl.k8s.io/release/v1.36.2/bin/l
96
self.kubectl_download_url = kubectl_download_url
107
self._install_kubectl()
118

9+
def execute(self):
10+
self.run()
11+
12+
def run(self):
13+
print("Kubectl is ready to use.")
14+
1215
def get_secret(self, secret_name: str, namespace: str, secret_path: str) -> str:
1316
try:
1417
print(f"Getting secret {secret_name} in namespace {namespace}.")
@@ -26,7 +29,7 @@ def get_secret(self, secret_name: str, namespace: str, secret_path: str) -> str:
2629
capture_output=True,
2730
)
2831
return result.stdout
29-
except subprocess.CalledProcessError as err:
32+
except Exception as err:
3033
raise Exception(f"getting secret {secret_name} in namespace {namespace}:\n{err}")
3134

3235
def _install_kubectl(self):
@@ -36,5 +39,5 @@ def _install_kubectl(self):
3639

3740
version = self.run_command("kubectl version --client", check=True, text=True, capture_output=True)
3841
print(f"kubectl installed successfully. Version: {version.stdout.strip()}")
39-
except subprocess.CalledProcessError as err:
42+
except Exception as err:
4043
raise Exception(f"installing kubectl:\n{err}")

0 commit comments

Comments
 (0)