Skip to content

Commit d21949e

Browse files
committed
feat(deploy): render Helm images, mark default-valued images, link crds and werf charts
Four gaps of the deployment graph, closed together. Images named from a default value keep their Image; the edge says so. A Dockerfile FROM / COPY --from filled by an ARG default (an ARG chain names each ARG) carries default_of, as do compose `${X:-d}` images and `docker build -t ${IMAGE:-x}` tags. An override found in the repository adds its own edge: compose build.args and --build-arg make the Image the build names DEPEND_ON the base they choose {override_of}; compose's .env replacing an inline default marks the effective edge override_of and keeps the default as {ref: image_default}, an image the service does not run. Helm template images render (helm_template.c): a bounded Go text/template + Sprig evaluator over the vendored gotmpl grammar, with values read the way Helm reads them (go-yaml v2 scalars, float64 numbers, Helm's coalesce). Each templated container image renders from its chart family's defaults -- include / define helpers, with / range / if, subchart values under their alias, global -- and the object USES it {default_of: the values keys read}; the chart DEPLOYS it. A value that does not render (a .Release field, lookup, a missing define, a field of a missing map, a function not modelled) names no Image; a rendered value is checked against the image reference grammar first. Releases render their charts with their values: a Flux HelmRelease's spec.values, a kustomize helmCharts entry's valuesFile + valuesInline (a chart in chartHome now links locally), a Terraform helm_release's values + set (literals only; set_sensitive is never read) -- each image that differs is the release's own DEPLOYS {override_of}. A release of a chart outside the repository names images by convention only where its values' `repository` names a registry host {inferred: values}; a host-less one names none. A chart DEPLOYS the CRDs of its crds/ {phase: crds}. A werf `.helm` dir beside werf.yaml is a chart named after the werf project. Incremental runs: a werf.yaml edit and a werf chart's values / templates decline like a Chart.yaml chart's; a release's values file (a kustomize valuesFile, a Terraform file()) declines too -- Terraform's now IMPORTS {local_name: values} it, like kustomize's valuesFile. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 9f85f10 commit d21949e

14 files changed

Lines changed: 5976 additions & 129 deletions

‎Makefile.cbm‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ PIPELINE_SRCS = \
537537
src/pipeline/pass_compile_commands.c \
538538
src/pipeline/pass_infrascan.c \
539539
src/pipeline/pass_k8s.c \
540+
src/pipeline/helm_template.c \
540541
src/pipeline/pass_operator.c \
541542
src/pipeline/pass_shell.c \
542543
src/pipeline/pass_terraform.c \

‎internal/cbm/cbm.h‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,9 @@ typedef struct {
719719
* from the URL `name`; a HelmRelease whose chartRef names it deploys the
720720
* chart there.
721721
* CBM_K8S_FACT_IMAGE: object def_index runs its container `container`
722-
* (NULL: unnamed) from image `name` (a literal reference); via "container".
722+
* (NULL: unnamed) from image `name` (a literal reference, or a Helm
723+
* template's placeholder `<...>`, which names none); via "container";
724+
* `line` the image's line, start_line / end_line the container's.
723725
* CBM_K8S_FACT_ENV: object def_index sets environment variable `name` in
724726
* its container `container` (NULL: unnamed) at `line`; via = where the
725727
* value comes from ("value", or the valueFrom kind) -- never the value.
@@ -758,6 +760,8 @@ typedef struct {
758760
const char *url; /* DEPLOY (kustomize): the chart repository */
759761
const char *release; /* DEPLOY (kustomize): the release name */
760762
int line;
763+
int start_line; /* IMAGE: the container mapping's first line */
764+
int end_line; /* IMAGE: its last line */
761765
} CBMK8sFact;
762766

763767
typedef struct {

‎internal/cbm/extract_k8s.c‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,12 +1487,18 @@ static void k8s_container(k8s_walk_t *w, const char *path, TSNode container) {
14871487
const char *cname = k8s_text(w, container, "name");
14881488
cname = cname && cname[0] && !strstr(cname, "{{") ? cname : NULL;
14891489
const char *image = k8s_text(w, container, "image");
1490-
if (k8s_image_literal(image)) {
1490+
/* a Helm template's image is its skeleton placeholder: pass_k8s.c renders it */
1491+
if (k8s_image_literal(image) || (image && strchr(image, '<'))) {
1492+
TSNode iv = k8s_child(w, container, "image");
14911493
CBMK8sFact f = {.fact = CBM_K8S_FACT_IMAGE,
14921494
.def_index = w->def_index,
14931495
.name = image,
14941496
.container = cname,
1495-
.via = "container"};
1497+
.via = "container",
1498+
.line =
1499+
ts_node_is_null(iv) ? 0 : (int)ts_node_start_point(iv).row + SKIP_ONE,
1500+
.start_line = (int)ts_node_start_point(container).row + SKIP_ONE,
1501+
.end_line = (int)ts_node_end_point(container).row + SKIP_ONE};
14961502
cbm_k8sfact_push(&w->ctx->result->k8s_facts, w->ctx->arena, f);
14971503
}
14981504
k8s_iter_t env = k8s_iter(k8s_child(w, container, "env"));

0 commit comments

Comments
 (0)