Skip to content

Commit

Permalink
Add support to kube-apiserver and kube-token options to authenticate: #…
Browse files Browse the repository at this point in the history
…20 (#21)

* Implements #20

* Fix error with _insecure_skip_tls_verify
  • Loading branch information
micafer authored Jan 9, 2025
1 parent d3bd9ef commit f006773
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
4 changes: 4 additions & 0 deletions pyhelm3/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def __init__(
insecure_skip_tls_verify: bool = False,
kubeconfig: t.Optional[pathlib.Path] = None,
kubecontext: t.Optional[str] = None,
kubeapiserver: t.Optional[str] = None,
kubetoken: t.Optional[str] = None,
unpack_directory: t.Optional[str] = None
):
self._command = command or Command(
Expand All @@ -63,6 +65,8 @@ def __init__(
insecure_skip_tls_verify = insecure_skip_tls_verify,
kubeconfig = kubeconfig,
kubecontext = kubecontext,
kubeapiserver = kubeapiserver,
kubetoken = kubetoken,
unpack_directory = unpack_directory
)

Expand Down
26 changes: 10 additions & 16 deletions pyhelm3/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ def __init__(
insecure_skip_tls_verify: bool = False,
kubeconfig: t.Optional[pathlib.Path] = None,
kubecontext: t.Optional[str] = None,
kubeapiserver: t.Optional[str] = None,
kubetoken: t.Optional[str] = None,
unpack_directory: t.Optional[str] = None
):
self._logger = logging.getLogger(__name__)
Expand All @@ -154,6 +156,8 @@ def __init__(
self._insecure_skip_tls_verify = insecure_skip_tls_verify
self._kubeconfig = kubeconfig
self._kubecontext = kubecontext
self._kubeapiserver = kubeapiserver
self._kubetoken = kubetoken
self._unpack_directory = unpack_directory

def _log_format(self, argument):
Expand All @@ -174,6 +178,12 @@ async def run(self, command: t.List[str], input: t.Optional[bytes] = None) -> by
command.extend(["--kubeconfig", self._kubeconfig])
if self._kubecontext:
command.extend(["--kube-context", self._kubecontext])
if self._kubeapiserver:
command.extend(["--kube-apiserver", self._kubeapiserver])
if self._kubetoken:
command.extend(["--kube-token", self._kubetoken])
if self._insecure_skip_tls_verify:
command.append("--kube-insecure-skip-tls-verify")
# 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 Expand Up @@ -545,8 +555,6 @@ async def install_or_upgrade(
command.append("--dry-run")
if force:
command.append("--force")
if self._insecure_skip_tls_verify:
command.append("--insecure-skip-tls-verify")
if namespace:
command.extend(["--namespace", namespace])
if no_hooks:
Expand Down Expand Up @@ -627,8 +635,6 @@ async def pull(
command = ["pull", chart_ref, "--destination", destination, "--untar"]
if devel:
command.append("--devel")
if self._insecure_skip_tls_verify:
command.append("--insecure-skip-tls-verify")
if repo:
command.extend(["--repo", repo])
if version:
Expand All @@ -649,8 +655,6 @@ async def repo_add(self, name: str, url: str):
Returns the new repo list on success.
"""
command = ["repo", "add", name, url, "--force-update"]
if self._insecure_skip_tls_verify:
command.append("--insecure-skip-tls-verify")
await self.run(command)

async def repo_update(self, *names: str):
Expand Down Expand Up @@ -755,8 +759,6 @@ async def show_chart(
command = ["show", "chart", chart_ref]
if devel:
command.append("--devel")
if self._insecure_skip_tls_verify:
command.append("--insecure-skip-tls-verify")
if repo:
command.extend(["--repo", repo])
if version:
Expand All @@ -780,8 +782,6 @@ async def show_crds(
# command = ["show", "crds", chart_ref]
# if devel:
# command.append("--devel")
# if self._insecure_skip_tls_verify:
# command.append("--insecure-skip-tls-verify")
# if repo:
# command.extend(["--repo", repo])
# if version:
Expand Down Expand Up @@ -840,8 +840,6 @@ async def show_readme(
command = ["show", "readme", chart_ref]
if devel:
command.append("--devel")
if self._insecure_skip_tls_verify:
command.append("--insecure-skip-tls-verify")
if repo:
command.extend(["--repo", repo])
if version:
Expand All @@ -862,8 +860,6 @@ async def show_values(
command = ["show", "values", chart_ref]
if devel:
command.append("--devel")
if self._insecure_skip_tls_verify:
command.append("--insecure-skip-tls-verify")
if repo:
command.extend(["--repo", repo])
if version:
Expand Down Expand Up @@ -914,8 +910,6 @@ async def template(
]
if devel:
command.append("--devel")
if self._insecure_skip_tls_verify:
command.append("--insecure-skip-tls-verify")
if is_upgrade:
command.append("--is-upgrade")
if namespace:
Expand Down

0 comments on commit f006773

Please sign in to comment.