Skip to content

Commit

Permalink
Add a pass through --registry-config flag (#735)
Browse files Browse the repository at this point in the history
Add a flag `--registry-config` that can be used as a pass through to the
helm command.

#717
#301
  • Loading branch information
allenporter authored Jun 29, 2024
1 parent d8c22f6 commit 08e2124
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
25 changes: 16 additions & 9 deletions flux_local/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@


HELM_BIN = "helm"
DEFAULT_REGISTRY_CONFIG = "/dev/null"


def _chart_name(release: HelmRelease, repo: HelmRepository | None) -> str:
Expand Down Expand Up @@ -126,10 +127,18 @@ class Options:
api_versions: str | None = None
"""Value of the helm --api-versions flag."""

registry_config: str | None = None
"""Value of the helm --registry-config flag."""

@property
def base_args(self) -> list[str]:
"""Helm template CLI arguments built from the options."""
return ["--registry-config", self.registry_config or DEFAULT_REGISTRY_CONFIG]

@property
def template_args(self) -> list[str]:
"""Helm template CLI arguments built from the options."""
args = []
args = self.base_args
if self.skip_crds:
args.append("--skip-crds")
if self.skip_tests:
Expand Down Expand Up @@ -159,8 +168,6 @@ def __init__(self, tmp_dir: Path, cache_dir: Path) -> None:
self._tmp_dir = tmp_dir
self._repo_config_file = self._tmp_dir / "repository-config.yaml"
self._flags = [
"--registry-config",
"/dev/null",
"--repository-cache",
str(cache_dir),
"--repository-config",
Expand Down Expand Up @@ -189,11 +196,10 @@ async def update(self) -> None:
content = yaml.dump(RepositoryConfig(repos).config, sort_keys=False)
async with aiofiles.open(str(self._repo_config_file), mode="w") as config_file:
await config_file.write(content)
await command.run(
command.Command(
[HELM_BIN, "repo", "update"] + self._flags, exc=HelmException
)
)
args = [HELM_BIN, "repo", "update"]
args.extend(Options().base_args)
args.extend(self._flags)
await command.run(command.Command(args, exc=HelmException))

async def template(
self,
Expand Down Expand Up @@ -226,6 +232,7 @@ async def template(
"--namespace",
release.namespace,
]
args.extend(self._flags)
args.extend(options.template_args)
if release.chart.version:
args.extend(
Expand All @@ -239,7 +246,7 @@ async def template(
async with aiofiles.open(values_path, mode="w") as values_file:
await values_file.write(yaml.dump(release.values, sort_keys=False))
args.extend(["--values", str(values_path)])
cmd = Kustomize([command.Command(args + self._flags, exc=HelmException)])
cmd = Kustomize([command.Command(args, exc=HelmException)])
if options.skip_resources:
cmd = cmd.skip_resources(options.skip_resources)
return cmd
5 changes: 5 additions & 0 deletions flux_local/tool/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ def add_helm_options_flags(args: ArgumentParser) -> None:
"-a",
help="Kubernetes api versions used for helm Capabilities.APIVersions",
)
args.add_argument(
"--registry-config",
help="Path to a helm registry config file",
)


def build_helm_options(**kwargs) -> helm.Options: # type: ignore[no-untyped-def]
Expand All @@ -198,6 +202,7 @@ def build_helm_options(**kwargs) -> helm.Options: # type: ignore[no-untyped-def
skip_secrets=kwargs["skip_secrets"],
kube_version=kwargs.get("kube_version"),
api_versions=kwargs.get("api_versions"),
registry_config=kwargs.get("registry_config"),
)


Expand Down

0 comments on commit 08e2124

Please sign in to comment.