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 a pass through --registry-config flag #735

Merged
merged 1 commit into from
Jun 29, 2024
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
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
Loading