Skip to content

Commit fd46186

Browse files
committed
add template output to helm_install rule
1 parent 55b02a6 commit fd46186

1 file changed

Lines changed: 31 additions & 4 deletions

File tree

helm/private/rules/install.bzl

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ _ATTRS = {
4545
"namespace": attr.string(
4646
doc = "Namespace scope for this reques.",
4747
),
48+
"template_output": attr.output(
49+
doc = "Filename to dump the rendered chart",
50+
),
4851
}
4952

5053
def _impl(ctx):
@@ -69,10 +72,21 @@ def _impl(ctx):
6972
is_executable = True,
7073
)
7174

72-
return DefaultInfo(
73-
executable = executable,
74-
runfiles = ctx.runfiles(runfiles),
75-
)
75+
result = [DefaultInfo(executable = executable, runfiles = ctx.runfiles(runfiles), files = depset())]
76+
77+
if ctx.outputs.template_output:
78+
template_command = _build_template_command(ctx)
79+
ctx.actions.run_shell(
80+
inputs = [ctx.file.chart],
81+
outputs = [ctx.outputs.template_output],
82+
arguments = [ctx.outputs.template_output.path],
83+
tools = ctx.toolchains["@slamdev_rules_helm//helm:toolchain_type"].default.files,
84+
progress_message = "Rendering chart " + ctx.outputs.template_output.short_path,
85+
command = template_command + " > $1",
86+
)
87+
result += [OutputGroupInfo(template = depset([ctx.outputs.template_output]))]
88+
89+
return result
7690

7791
def _build_helm_command(ctx):
7892
args = [ctx.var["HELM_RUNFILES_BIN"]]
@@ -100,6 +114,19 @@ def _build_helm_command(ctx):
100114
args.extend(["--namespace", ctx.attr.namespace])
101115
return " ".join(args)
102116

117+
def _build_template_command(ctx):
118+
args = [ctx.var["HELM_BIN"]]
119+
args += ["template"]
120+
args += [ctx.attr.release_name]
121+
args += [ctx.file.chart.path]
122+
if ctx.attr.disable_openapi_validation:
123+
args += ["--disable-openapi-validation"]
124+
if ctx.attr.namespace:
125+
args += ["--namespace", ctx.attr.namespace]
126+
if ctx.attr.no_hooks:
127+
args += ["--no-hooks"]
128+
return " ".join(args)
129+
103130
install = rule(
104131
doc = _DOC,
105132
implementation = _impl,

0 commit comments

Comments
 (0)