Skip to content

Commit

Permalink
Merge pull request #6 from manavsg/main
Browse files Browse the repository at this point in the history
Add kube-context parameter to helm cmd
  • Loading branch information
mkjpryor authored May 14, 2024
2 parents d032154 + 4ad47c2 commit 00347c7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ from pyhelm3 import Client
client = Client()
# Specify the kubeconfig file to use
client = Client(kubeconfig = "/path/to/kubeconfig")
# Specify the kubecontext to use
client = Client(kubecontext = "kubecontext")
# Specify a custom Helm executable (by default, we expect 'helm' to be on the PATH)
client = Client(executable = "/path/to/helm")

Expand Down
2 changes: 2 additions & 0 deletions pyhelm3/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def __init__(
history_max_revisions: int = 10,
insecure_skip_tls_verify: bool = False,
kubeconfig: t.Optional[pathlib.Path] = None,
kubecontext: t.Optional[str] = None,
unpack_directory: t.Optional[str] = None
):
self._command = command or Command(
Expand All @@ -61,6 +62,7 @@ def __init__(
history_max_revisions = history_max_revisions,
insecure_skip_tls_verify = insecure_skip_tls_verify,
kubeconfig = kubeconfig,
kubecontext = kubecontext,
unpack_directory = unpack_directory
)

Expand Down
4 changes: 4 additions & 0 deletions pyhelm3/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def __init__(
history_max_revisions: int = 10,
insecure_skip_tls_verify: bool = False,
kubeconfig: t.Optional[pathlib.Path] = None,
kubecontext: t.Optional[str] = None,
unpack_directory: t.Optional[str] = None
):
self._logger = logging.getLogger(__name__)
Expand All @@ -152,6 +153,7 @@ def __init__(
self._history_max_revisions = history_max_revisions
self._insecure_skip_tls_verify = insecure_skip_tls_verify
self._kubeconfig = kubeconfig
self._kubecontext = kubecontext
self._unpack_directory = unpack_directory

def _log_format(self, argument):
Expand All @@ -170,6 +172,8 @@ async def run(self, command: t.List[str], input: t.Optional[bytes] = None) -> by
command = [self._executable] + command
if self._kubeconfig:
command.extend(["--kubeconfig", self._kubeconfig])
if self._kubecontext:
command.extend(["--kube-context", self._kubecontext])
# The command must be made up of str and bytes, so convert anything that isn't
shell_formatted_command = shlex.join(
part if isinstance(part, (str, bytes)) else str(part)
Expand Down

0 comments on commit 00347c7

Please sign in to comment.