From 08e2124144f646b9eb6fe2460673e6f42fb1e6ac Mon Sep 17 00:00:00 2001 From: Allen Porter Date: Sat, 29 Jun 2024 16:09:28 -0700 Subject: [PATCH] Add a pass through --registry-config flag (#735) Add a flag `--registry-config` that can be used as a pass through to the helm command. #717 #301 --- flux_local/helm.py | 25 ++++++++++++++++--------- flux_local/tool/selector.py | 5 +++++ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/flux_local/helm.py b/flux_local/helm.py index 180d1dca..5e4bc2ff 100644 --- a/flux_local/helm.py +++ b/flux_local/helm.py @@ -63,6 +63,7 @@ HELM_BIN = "helm" +DEFAULT_REGISTRY_CONFIG = "/dev/null" def _chart_name(release: HelmRelease, repo: HelmRepository | None) -> str: @@ -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: @@ -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", @@ -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, @@ -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( @@ -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 diff --git a/flux_local/tool/selector.py b/flux_local/tool/selector.py index 26260d1f..e0a50837 100644 --- a/flux_local/tool/selector.py +++ b/flux_local/tool/selector.py @@ -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] @@ -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"), )