Rules for manipulating helm charts. To load these rules:
load("//helm:defs.bzl", "helm_chart", ...)
chart_srcs(name, deps, srcs, additional_templates, api_version, app_version, chart_deps, chart_name, deps_conditions, description, force_repository_append, helm_chart_version, image, image_digest, image_repository, image_tag, package_name, path_to_chart, stamp, templates, values, values_repo_yaml_path, values_tag_yaml_path, version)
Customize helm chart values and configuration.
This rule should not be used directly, users should use helm_chart
macro instead. See helm_chart.
Despite, if you want to see the configuration arguments you can use to package a helm chart using helm_chart
rule, check the arguments doc below for chart_srcs
rule,
as helm_chart
is just a wrapper around chart_srcs
rule and all the arguments are propagated to chart_srcs
rule.
This rule takes chart src files and write them to bazel output dir applying some modifications.
The rule is designed to be used with a packager to produce an archived file (pkg_tar
is used).
chart_srcs(
name = "basic_chart",
chart_name = "example",
srcs = glob(["**"]),
)
You can customize the values of the chart overriding them via values
rule attribute:
chart_srcs(
name = "basic_chart",
chart_name = "example",
srcs = glob(["**"]),
values = {
"override.value": "valueoverrided",
}
)
Chart src files are not mandatory, you can specify all the chart configuration via rule attributes. In this case the rule will take care of generating the chart files for you (Chart.yaml, values.yaml, template files, chart deps...).
chart_srcs(
name = "chart",
chart_name = "example",
version = "v1.0.0",
app_version = "v2.3.4",
api_version = "v2",
description = "Helm chart description placed inside Chart.yaml",
image = ":oci_image",
values = {
"yaml.path.to.value": "value",
},
)
Stamp variables are supported in values attribute. To enable the use of stamp variables enable them via stamp attribute and --stamp flag in bazel. You can customize stamped variables using bazel workspace status. See the Bazel workspace status docs
All values with ${} format will be replaced by stamped variables (both volatile and stable are supported).
chart_srcs(
name = "chart",
chart_name = "example",
srcs = glob(["**"]),
stamp = -1,
values = {
"stamped.value": "${STAMPED_VARIABLE}",
},
)
For compatibility reasons, some attributes are still supported but marked as deprecated. Its use is discouraged.
ATTRIBUTES
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
deps | A list of helm chart that this helm chart depends on. They will be placed inside the charts directory. The dependencies will be traced inside the Chart.yaml manifest as well. |
List of labels | optional | [] |
srcs | A list of helm chart source files. | List of labels | optional | [] |
additional_templates | [Deprecated] Use templates instead. | List of labels | optional | [] |
api_version | Helm chart manifest apiVersion. The value is replaced in the output Chart.yaml manifest. | String | optional | "" |
app_version | Helm chart manifest appVersion. The value is replaced in the output Chart.yaml manifest. | String | optional | "" |
chart_deps | [Deprecated] Chart dependencies. Use deps attribute instead. | List of labels | optional | [] |
chart_name | Name of the chart. It will be modified in the name field of the Chart.yaml | String | required | |
deps_conditions | A dictionary containing the conditions that the dependencies of the chart should met to be rendered by helm. The key has to be the name of the dependency chart. The value will be the condition that the values of the chart should have. Check helm doc for more info https://helm.sh/docs/topics/charts/#the-chartyaml-file | Dictionary: String -> String | optional | {} |
description | Helm chart manifest description. The value is replaced in the output Chart.yaml manifest. | String | optional | "" |
force_repository_append | A flag to specify if @ should be appended to the repository value in the chart values.yaml (in case image rule attribute is specified). The rules will look for the specified repository value inside the values.yaml. This is intended to meet image url with digest format: gcr.io/container@sha256:a12e258c58ab92be22e403d08c8ef7eefd6119235eddca01309fe6b21101e100 . If you have this already covered in your deployment templates, set this attr to false. If the flag is set to true, the image rule attr is provided and no values_repo_yaml_path is set, the rule will look for the default path of the repository value. .image.repository |
Boolean | optional | True |
helm_chart_version | [Deprecated] Helm chart version. Use version instead. | String | optional | "" |
image | Reference to image rule use to interpolate the image sha256 in the chart values.yaml. If provided, the sha256 of the image will be placed in the output values.yaml of the chart in the yaml path provided by values_tag_yaml_path attribute. Only oci_image rules are supported. |
Label | optional | None |
image_digest | Reference to oci_image digest file. Used internally by the macro (do not use it). | Label | optional | None |
image_repository | [Deprecated] You can use values attr dict to modify repository values. | String | optional | "" |
image_tag | [Deprecated] Use image attribute instead. | String | optional | "" |
package_name | [Deprecated] Helm chart name. Use chart_name instead. | String | optional | "" |
path_to_chart | Attribute to specify the path to the root of the chart. This attribute is mandatory if neither Chart.yaml nor values.yaml are provided, and the chart srcs attr is not empty to determinate where in the path of the source files is located the root of the helm chart. | String | optional | "" |
stamp | Whether to encode build information into the output. Possible values: - stamp = 1 : Always stamp the build information into the output, even in --nostamp builds. This setting should be avoided, since it is non-deterministic. It potentially causes remote cache misses for the target and any downstream actions that depend on the result. - stamp = 0 : Never stamp, instead replace build information by constant values. This gives good build result caching. - stamp = -1 : Embedding of build information is controlled by the --[no]stamp flag. Stamped targets are not rebuilt unless their dependencies change. |
Integer | optional | -1 |
templates | A list of files that will be added to the chart. They will be added as addition to the chart templates refernced in the srcs attribute. |
List of labels | optional | [] |
values | A dictionary of key values to be written in to the chart values. keys: yaml.path or .yaml.path values: the value to be replaced inside the Chart values.yaml. This attr supports use of stamped values. To provide a stamped value you have to use ${STAMP_VARIABLE_NAME} as value of the dict with your stamped variable key. Make sure to enable stamping in your rule with the attribute stamp . |
Dictionary: String -> String | optional | {} |
values_repo_yaml_path | [Deprecated] Yaml path used to set the repo config provided by image_repository attribute (deprecated). .image.repository |
String | optional | "" |
values_tag_yaml_path | Yaml path used to set the image sha256 inside the chart values.yaml. | String | optional | ".image.tag" |
version | Helm chart version to be placed in Chart.yaml manifest | String | optional | "" |
ChartInfo(targz, chart_name, chart_version, chart_srcs)
helm_chart
expose ChartInfo providers to be able to access info about a packaged chart. The info available is:
- The name of the chart
- The version of the chart
- The ouput sources of the chart
- The output archive file targz
FIELDS
helm_chart(name, chart_name, kwargs)
Bazel macro function to package a helm chart in to a targz archive file.
The macro is intended to be used as the public API for packaging a chart. It is a wrapper around chart_srcs
rule. All the args are propagated to chart_srcs
rule.
See chart_srcs arguments to see the available config.
To load the rule use:
load("//helm:defs.bzl", "helm_chart")
It also defines a %name%_lint test target to be able to test that your chart is well-formed (using helm lint
).
To make the output reproducible this macro does not use helm package
to package the chart into a versioned chart archive file.
It uses pkg_tar
bazel rule instead to create the archive file. Check this to find more info about it:
This macro exports some providers to share info about charts between rules. Check helm_chart providers.
The args are the same that the chart_srcs
rule, check chart_srcs.
load("//helm:defs.bzl", "helm_chart")
helm_chart(
name = "basic_chart",
chart_name = "example",
srcs = glob(["**"]),
)
helm_chart(
name = "basic_chart",
chart_name = "example",
srcs = glob(["**"]),
values = {
"override.value": "valueoverrided",
}
)
helm_chart(
name = "chart",
chart_name = "example",
version = "v1.0.0",
app_version = "v2.3.4",
api_version = "v2",
description = "Helm chart description placed inside Chart.yaml",
image = ":oci_image",
values = {
"yaml.path.to.value": "value",
},
)
PARAMETERS
Name | Description | Default Value |
---|---|---|
name | - |
none |
chart_name | - |
none |
kwargs | - |
none |