Skip to content
Open
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
44 changes: 44 additions & 0 deletions helm/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load(
"//helm:defs.bzl",
"helm_import_repository",
)
load(
"//helm:repositories.bzl",
"helm_host_alias_repository",
Expand Down Expand Up @@ -47,6 +51,22 @@ def _helm_impl(ctx):
_register_toolchains(**toolchain_config)
_register_go_yaml()

# Separate iteration, because this can depend on the _register_toolchains called above.
# And the _register_toolchains needs to be called *after* iteration of all modules.
for module in ctx.modules:
for repository in module.tags.import_repository:
if not module.is_root:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't repositories be instantiated if it's not the root?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They can but they shouldn't for now since this would require more elaborate de-duplication based on repository URL. This approach is commonly used in module extensions to facilitate future improvements. This way, one can migrate a breaking change (for example generating the name based on repository and/or chart) completely in the root module while otherwise a change in the interface would require updating all transitive dependencies first.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like de-duplication needs to be figured out first. I would hate for someone to be unable to pull a transitive dependency because they used rules_helm and now necessary repositories are missing. Would it be reasonable to prefix the dependencies with the name of the module and then require users define the name of a hub repository where these deps are accessed that needs to be globally unique? I also am still fairly new to bzlmod but isn't it supposed to solve for issues like this in transitive dependencies?

print("Ignoring import_repository of", repository.name, "from", repository.repository, "because it's not in the root module") # buildifier: disable=print
continue
helm_import_repository(
name = repository.name,
chart_name = repository.chart_name,
repository = repository.repository,
sha256 = repository.sha256,
url = repository.url,
version = repository.version,
)

def _register_toolchains(version, helm_url_templates, plugins):
if not version in HELM_VERSIONS:
fail("{} is not a supported version ({})".format(version, HELM_VERSIONS.keys()))
Expand Down Expand Up @@ -132,10 +152,34 @@ _toolchain = tag_class(
},
)

_import_repository = tag_class(attrs = {
"name": attr.string(
doc = "Name for the import dependency",
),
"chart_name": attr.string(
doc = "Chart name to import.",
),
"repository": attr.string(
doc = "Chart repository url where to locate the requested chart.",
mandatory = True,
),
"sha256": attr.string(
doc = "The expected SHA-256 hash of the chart imported.",
),
"url": attr.string(
doc = "The url where the chart can be directly downloaded.",
),
"version": attr.string(
doc = "Specify a version constraint for the chart version to use.",
),
},
doc = "Download a chart from an existing repository. E.g. as dependency for complex charts.")

helm = module_extension(
implementation = _helm_impl,
tag_classes = {
"options": _toolchain, # deprecated: use toolchain instead and remove in next major version
"toolchain": _toolchain,
"import_repository": _import_repository,
},
)