Skip to content

Commit a222715

Browse files
authored
Merge pull request DeusData#2677 from DeusData/feat/deploy-graph-gaps
feat(deploy): render Helm images, mark default-valued images, link crds and werf charts
2 parents 4c80d89 + 5cdbe9b commit a222715

19 files changed

Lines changed: 8621 additions & 131 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 \

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ The install script placed beside the binary is **reported, not deleted**: uninst
333333
- `INFRA_MAPS`: a Kubernetes Service to each workload whose pod labels carry every `key: value` of the Service's selector, within one namespace
334334
- `CONNECTS_TO`: a Kubernetes workload or compose service to the Service its containers' environment addresses (`PRODUCT_CATALOG_SERVICE_ADDR: productcatalogservice:3550`, a URL's host, `<svc>.<ns>.svc...`, a bare name on an `*_ADDR` / `*_HOST` / `*_URL` / ... key; compose: the project's `.env` interpolated): a Kubernetes Service of the same bundle and namespace, or a compose service of the same file. The edge keeps `via: env`, `key` and `container`, never the value
335335
- `USAGE` with `ref: image`: a Kubernetes workload (any pod template: containers, initContainers, CronJobs, custom resources) or a docker compose service to the `Image` it runs
336+
- Helm templates are rendered for their images: with the chart's values (the `Chart` `DEPLOYS` them, `default_of`: the values keys read) and with each release's (a Flux HelmRelease, a kustomize `helmCharts` entry, a Terraform `helm_release`: `override_of`). An image the render cannot know is left out, never guessed: after a change of values it does not run exactly, a `tpl` or include it cannot look into, a release value it cannot read, or a work budget it runs past. Known limit: each template file renders on its own, while Helm renders a chart's files with one shared `.Values` (a subchart's is its parent's `.Values.<alias>`), so a chart that changes `.Values` in one file and reads it in another can still show a wrong image
336337
- `DEPLOYS`: what puts manifests, kustomizations or charts on a cluster, to what it puts there: a Flux Kustomization or Argo Application to the kustomizations / manifests / chart of its path, a Flux HelmRelease to its chart (`spec.chart` or `chartRef` → OCIRepository), a shell command or Make recipe (`kubectl apply -f/-k`, `kustomize build | kubectl apply`, `helm install/upgrade/template`), a Go installer loading a chart with the Helm SDK, a Terraform `helm_release`, a Terraform `kubernetes_*` resource the object it declares (a `Resource` like a manifest's, `ecosystem: terraform`, when its name is a literal), a kustomization inflating a chart (`helmCharts`; its values file an `IMPORTS`). A chart outside the repository is an external `Chart`, keyed by its publisher when its repository URL is stated (`__chart__<repository>/<name>`, the same node in every project, the URL in `repository`), else one per project and name; the edge says `via` (`flux`, `argo`, `helmrelease`, `kubectl`, `kustomize`, `helm`, `helm-sdk`, `terraform`, `helmcharts`, ...)
337338
- `DEPENDS_ON`: a Helm chart to the charts it declares (the local chart for a resolvable `file://` repository, otherwise an external `Chart`; the edge keeps `repository`), and a `go.mod` / `requirements.txt` file to an external `Package`; a Dockerfile to the `Image`s it builds on (`via: from`, `copy-from`); an `Image` to the Dockerfile it is built from (`via: build`; `tool`: `skaffold`, `compose`, `docker-build` for `docker` / `podman` / `nerdctl` / `buildah` build commands in scripts, Make and CI); a compose service to the services its `depends_on` / `links` name
338339
- `CONFIGURES`: code reading an environment variable to the shared `EnvVar` of that name (`strategy: env_access`); a Kubernetes container, compose service or Dockerfile (`ENV` of the image) setting one to that container's own `EnvVar` (`strategy: env_set`, with `source`: `value`, `configMapKeyRef`, `secretKeyRef`, `fieldRef`, ..., `compose`, `dockerfile`; values are never stored); and that container's `EnvVar` to the code reading the name inside the files its image is built from (`strategy: env_read`, with `dockerfile`): the image's files are the sources its Dockerfile's `COPY` / `ADD` put into it, less the context's `.dockerignore`

‎internal/cbm/cbm.h‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,9 @@ typedef struct {
734734
* from the URL `name`; a HelmRelease whose chartRef names it deploys the
735735
* chart there.
736736
* CBM_K8S_FACT_IMAGE: object def_index runs its container `container`
737-
* (NULL: unnamed) from image `name` (a literal reference); via "container".
737+
* (NULL: unnamed) from image `name` (a literal reference, or a Helm
738+
* template's placeholder `<...>`, which names none); via "container";
739+
* `line` the image's line, start_line / end_line the container's.
738740
* CBM_K8S_FACT_ENV: object def_index sets environment variable `name` in
739741
* its container `container` (NULL: unnamed) at `line`; via = where the
740742
* value comes from ("value", or the valueFrom kind) -- never the value.
@@ -773,6 +775,8 @@ typedef struct {
773775
const char *url; /* DEPLOY (kustomize): the chart repository */
774776
const char *release; /* DEPLOY (kustomize): the release name */
775777
int line;
778+
int start_line; /* IMAGE: the container mapping's first line */
779+
int end_line; /* IMAGE: its last line */
776780
} CBMK8sFact;
777781

778782
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)