Skip to content

Commit ec80c08

Browse files
committed
feat: add context parameter to Kubectl class and update get_secret method to use it
1 parent 046f124 commit ec80c08

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/github_actions/common/utils/kubectl.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33

44
class Kubectl(BaseCommand, CMDInterface):
5-
def __init__(self, kubectl_download_url="https://dl.k8s.io/release/v1.36.2/bin/linux/amd64/kubectl"):
5+
def __init__(self, context=None, kubectl_download_url="https://dl.k8s.io/release/v1.36.2/bin/linux/amd64/kubectl"):
66
super().__init__(None)
77
self.kubectl_download_url = kubectl_download_url
8+
self.context = context
89
self.run()
910

1011
def run(self):
@@ -16,8 +17,9 @@ def execute(self):
1617
def get_secret(self, secret_name: str, namespace: str, secret_path: str) -> str | None:
1718
try:
1819
print(f"Getting secret {secret_name} in namespace {namespace}.")
20+
context_flag = f"--context {self.context}" if self.context else ""
1921
return self.run_command(
20-
f"kubectl get secret {secret_name} --namespace {namespace} --output yaml | yq '.data.password'", capture_output=True
22+
f"kubectl get secret {secret_name} --namespace {namespace} {context_flag} --output yaml | yq '.data.password'", capture_output=True
2123
)
2224

2325
except Exception as err:

0 commit comments

Comments
 (0)