Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to kube-apiserver and kube-token options to authenticate: #20 #21

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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