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
37 changes: 31 additions & 6 deletions bazel/app_chart.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,25 @@ def _impl(ctx):

values_yaml = ctx.actions.declare_file(ctx.label.name + "-values.yaml")
source_digests = []
cmds = [
"cat {} - > {} <<EOF".format(ctx.file.values.path, values_yaml.path),

values_files = [ctx.file.values] + ctx.files.extra_values
# Use awk '1' instead of cat to concatenate values files. This ensures that
# each file ends with a newline, preventing invalid YAML if an input file
# is missing a trailing newline.
cmds = ["awk '1' {} > {}".format(ctx.file.values.path, values_yaml.path)]
if ctx.files.extra_values:
cmds.append("echo '# extra values' >> {}".format(values_yaml.path))
cmds.append("awk '1' {} >> {}".format(
" ".join([f.path for f in ctx.files.extra_values]),
values_yaml.path,
))

cmds.extend([
"cat - >> {} <<EOF".format(values_yaml.path),
"### Generated by app_chart ###",
"images:",
]
])

jq_bin = ctx.toolchains["@aspect_bazel_lib//lib:jq_toolchain_type"].jqinfo.bin

images = ctx.attr.images or {}
Expand All @@ -39,7 +53,7 @@ def _impl(ctx):
ctx.actions.run_shell(
tools = [jq_bin],
outputs = [values_yaml],
inputs = ctx.files.values + source_digests,
inputs = values_files + source_digests,
command = "\n".join(cmds),
toolchain = None,
)
Expand Down Expand Up @@ -71,7 +85,14 @@ _app_chart_backend = rule(
),
"values": attr.label(
allow_single_file = True,
doc = "The values.yaml file.",
doc = "Override the default values.yaml file.",
),
"extra_values": attr.label_list(
allow_empty = True,
allow_files = True,
default = [],
doc = "Extra values files to append to values.yaml. " +
"Use this if you only want to add additional values without changing the defaults.",
),
"templates": attr.label_list(
allow_empty = True,
Expand Down Expand Up @@ -107,6 +128,7 @@ _app_chart_backend = rule(
def app_chart(
name,
values = None,
extra_values = None,
extra_templates = None,
files = None,
images = None,
Expand All @@ -122,7 +144,9 @@ def app_chart(
Args:
name: string. Must be in the format {app}-{chart}, where chart is
robot, cloud, or cloud-per-robot.
values: file. The values.yaml file.
values: file. Override the default values.yaml file.
extra_values: list of files. Extra values files to append to values.yaml.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

TBH. I do not understand we we need 2 values files. If we need to, it should be crystal clear from the code how it would be used and why it is beneficial.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If a values file is not given, a default values file will be used. token-vendor use values in the default values file so if we want to add more values, we need to copy and extend the default. It's just a rare case that if we want to change the default, there is no longer any single SOT.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess Stefan is asking for a cleanup that migrates the other charts to use extra_values. Otherwise people will have the same problem as before: if they copy-paste the example from k8s-relay to a chart that uses values that are not in k8s-relay's values-cloud.yaml, they'll get the same error you did.

Copy link
Copy Markdown
Contributor

@ensonic ensonic Apr 30, 2026

Choose a reason for hiding this comment

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

A cleanup can be in a followup, but I like to have more details on the bazel rule that explains the need.

Eg. when I look at https://github.com/googlecloudrobotics/core/tree/main/src/app_charts/token-vendor
it does not yet have any values.yaml at all.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What is now the usecase for specifying values? If no rule is doing this anymore and everything is using extra_values, we can keep the attribute name to be called "values" and prepend the defaults?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These targets cannot be migrated to use extra_values because they override some base values.

values = "values-cloud.yaml",

values = "values.yaml",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@koonpeng Please decouple the helm_chart change from the token-vendor change: Copy the full list of required values or the subset of required values to token-vendor/values.yaml, and if you still want to make the "create a new values.yaml" flow easier for future developers, create a new PR that adds extra_values.yaml (or just changes the docs to explain where to copy the base values from for full compatibility).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Made another PR that cherry picked #672 the tv changes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@drigz Now that #672 is merged, this PR should now be a refactor will no functionality changes.

Use this if you only want to add additional values without changing the defaults.
extra_templates: list of files. Extra files for the chart's templates/ directory.
files: list of files. Extra non-template files for the chart's files/ directory.
images: dict. Images referenced by the chart.
Expand All @@ -149,6 +173,7 @@ def app_chart(
name = name,
chart = chart,
values = values,
extra_values = extra_values,
templates = native.glob([chart + "/*.yaml"], allow_empty = True) + (extra_templates or []),
files = files,
images = reversed_images,
Expand Down
2 changes: 1 addition & 1 deletion src/app_charts/akri/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ app_chart(
files = [
":akri-chart.robot",
],
values = "values-robot.yaml",
extra_values = ["values-robot.yaml"],
)

app(
Expand Down
3 changes: 0 additions & 3 deletions src/app_charts/akri/values-robot.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
domain: "example.com"
project: "my-gcp-project"
registry: "gcr.io/my-gcp-project"
robots: []

udev:
Expand Down
2 changes: 1 addition & 1 deletion src/app_charts/base/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ app_chart(
"metadata-server": "//src/go/cmd/metadata-server:metadata-server-image",
"chart-assignment-controller": "//src/go/cmd/chart-assignment-controller:chart-assignment-controller-image",
},
values = "values-robot.yaml",
extra_values = ["values-robot.yaml"],
visibility = ["//visibility:public"],
)

Expand Down
5 changes: 0 additions & 5 deletions src/app_charts/base/values-robot.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
domain: "example.com"
project: "my-gcp-project"
deploy_environment: "GCP"
registry: "gcr.io/my-gcp-project"

# Setting app_management to "false" will remove layer 2 (app-rollout/chart-assignment-controller, etc).
app_management: "true"

Expand Down
4 changes: 2 additions & 2 deletions src/app_charts/k8s-relay/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ load("//bazel:app_chart.bzl", "app_chart")
app_chart(
name = "k8s-relay-cloud",
images = {"http-relay-server": "//src/go/cmd/http-relay-server:http-relay-server-image"},
values = "values-cloud.yaml",
extra_values = ["values-cloud.yaml"],
)

app_chart(
name = "k8s-relay-robot",
images = {"http-relay-client": "//src/go/cmd/http-relay-client:http-relay-client-image"},
values = "values-robot.yaml"
extra_values = ["values-robot.yaml"],
)

app(
Expand Down
5 changes: 0 additions & 5 deletions src/app_charts/k8s-relay/values-cloud.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
domain: "example.com"
project: "my-gcp-project"
registry: "gcr.io/my-gcp-project"
robots: []

# MetricRelabelConfigs to apply to samples after scraping, but before ingestion.
prometheus:
serviceMonitor:
Expand Down
1 change: 0 additions & 1 deletion src/app_charts/platform-apps/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ app_chart(
extra_templates = [
"//src/app_charts:app_resources",
],
values = "values.yaml",
visibility = ["//visibility:public"],
)
4 changes: 0 additions & 4 deletions src/app_charts/platform-apps/values.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion src/app_charts/prometheus/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ app_chart(
images = {
"http-relay-server": "//src/go/cmd/http-relay-server:http-relay-server-image",
},
values = "values-cloud.yaml",
extra_values = ["values-cloud.yaml"],
)

app_chart(
Expand Down
5 changes: 0 additions & 5 deletions src/app_charts/prometheus/values-cloud.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
domain: "example.com"
project: "my-gcp-project"
registry: "gcr.io/my-gcp-project"
robots: []

# The default requests/limits are sufficient for small deployments with a few
# robots. For a large deployment with ~30 robots, you might need ~2CPU and
# ~12Gi mem.
Expand Down
2 changes: 1 addition & 1 deletion src/app_charts/token-vendor/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ app_chart(
images = {
"token-vendor-go": "//src/go/cmd/token-vendor:token-vendor-image",
},
values = "values-cloud.yaml",
extra_values = ["values-cloud.yaml"],
)

app(
Expand Down
9 changes: 0 additions & 9 deletions src/app_charts/token-vendor/values-cloud.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
domain: "example.com"
project: "my-gcp-project"
deploy_environment: "GCP"
registry: "gcr.io/my-gcp-project"
robots: []
region: example-gcp-region
# Token Vendor feature flags
use_tv_k8s_verbose: false

token_vendor:
resources:
requests:
Expand Down
Loading