Skip to content
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
22 changes: 22 additions & 0 deletions helm/private/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ func loadTemplatePatterns(path string) (map[string][]string, error) {
return data, nil
}

// Flag type for a list of values passed as mutiple arguments.
type valuesList []string

// Provide the flag.Value interface in the simplest possible way.
func (vs *valuesList) Set(value string) error {
*vs = append(*vs, value)
return nil
}

// Provide the flag.Value interface in the simplest possible way.
func (vs *valuesList) String() string {
return fmt.Sprint(*vs)
}

func main() {
// Get the file path for args
argsRlocation := os.Getenv("RULES_HELM_HELM_RUNNER_ARGS_FILE")
Expand All @@ -92,11 +106,14 @@ func main() {

internalArgs, helmArgs := parseArgsUpToDashDash(argv)

var values valuesList

// Setup flags for helm, chart, registry_url, and image_pushers
rawHelmPath := flag.String("helm", "", "Path to helm binary")
rawHelmPluginsPath := flag.String("helm_plugins", "", "The path to helm plugins.")
rawChartPath := flag.String("chart", "", "Path to Helm .tgz file")
rawImagePushers := flag.String("image_pushers", "", "Comma-separated list of image pusher executables")
flag.Var(&values, "values", "Extra Values files (maye be used mutiple times).")

// Parse command line arguments
flag.CommandLine.Parse(internalArgs)
Expand Down Expand Up @@ -131,6 +148,11 @@ func main() {
}
}

for _, value := range values {
// Translate to correct path and forward to helm.
helmArgs = append(helmArgs, "--values", helm_utils.GetRunfile(value))
}

var imagePushers []string
if *rawImagePushers != "" {
for _, pusher := range strings.Split(*rawImagePushers, ",") {
Expand Down
13 changes: 12 additions & 1 deletion helm/private/template.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ def _helm_template_test_impl(ctx):
ctx.label,
))

if ctx.attr.installer and ctx.files.values:
fail("values is not supported with installer")

template_patterns = None
if ctx.attr.template_patterns:
template_patterns = ctx.actions.declare_file("{}.template_patterns.json".format(ctx.label.name))
Expand All @@ -38,6 +41,10 @@ def _helm_template_test_impl(ctx):
args.add("-chart", rlocationpath(pkg_info.chart, ctx.workspace_name))
args.add("-helm", rlocationpath(toolchain.helm, ctx.workspace_name))
args.add("-helm_plugins", rlocationpath(toolchain.helm_plugins, ctx.workspace_name))

for values in ctx.files.values:
args.add("--values", rlocationpath(values, ctx.workspace_name))

args.add("--")
args.add("template")
args.add(rlocationpath(pkg_info.chart, ctx.workspace_name))
Expand All @@ -47,7 +54,7 @@ def _helm_template_test_impl(ctx):
content = args,
)

runfiles = runfiles.merge(ctx.runfiles([
runfiles = runfiles.merge(ctx.runfiles(ctx.files.values + [
args_file,
ctx.executable._runner,
toolchain.helm,
Expand Down Expand Up @@ -108,6 +115,10 @@ helm_template_test = rule(
"template_patterns": attr.string_list_dict(
doc = "A mapping of template paths to regex patterns required to match.",
),
"values": attr.label_list(
doc = "Values files to pass to `helm template --values`.",
allow_files = [".yml", ".yaml"],
),
"_copier": attr.label(
cfg = "exec",
executable = True,
Expand Down
8 changes: 8 additions & 0 deletions tests/template_with_values/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@ helm_template(
helm_template_test(
name = "template_with_values_template_test",
chart = ":template_with_values",
template_patterns = {
"template-with-values/templates/deployment.yaml": [
" replicas: 10\\b", # overriden by template_values.yaml
],
},
values = [
":template_values.yaml",
],
)