Skip to content

feat(kubernetes): add Kubernetes workload tree representation - #72

Merged
liamcervante merged 2 commits into
mainfrom
liamcervante/kubernetes-workload-tree
Jun 24, 2026
Merged

feat(kubernetes): add Kubernetes workload tree representation#72
liamcervante merged 2 commits into
mainfrom
liamcervante/kubernetes-workload-tree

Conversation

@liamcervante

@liamcervante liamcervante commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

What

Adds an explicit Kubernetes workload representation to the resource tree — the first step of the Kubernetes workload parser work. There is no Kubernetes grouping in the tree today; this defines the tree shape every later step (parser plugin, provider plugin) depends on.

It mirrors the existing provider -> service -> resource shape:

layer value
provider kubernetes
service Kubernetes API group (apps, batch)
resource workload kind (deployment, statefulset, daemonset, replicaset, job, cronjob)

Each workload carries per-container sizing (CPU in millicores, memory in bytes — the exact base units a Kubernetes quantity reduces to, so there's no GiB-vs-GB ambiguity), annotations, and labels (stored on the base resource's Tags). Kinds with extra cost-relevant fields embed a shared workload.Workload and add their own (replicas; completions/parallelism; schedule).

Also adds the PROVIDER_KUBERNETES enum mapping (proto v1.150.0).

⚠️ This shape is subject to change

We deliberately do not know the full set of fields yet. The exact metadata and sizing fields needed to compute costs will only become clear as we build the parser and provider plugins against real manifests/charts. We're merging this now to unblock that development — it gives both plugins a concrete tree to build against, and discovering the unknowns is the point. Expect follow-up changes to the workload fields.

Flattening of anonymous embedded structs

To let kinds compose (Deployment embeds workload.Workload and adds Replicas; CronJob embeds Job embeds Workload), the reflective proto serializer (convert.go) now flattens anonymous embedded structs into the parent's attributes on both the read and write sides. resource.Resource keeps its existing dedicated handling; everything else embedded is inlined — which is simply Go's own embedding semantics applied to serialization.

Why this is forward- and backward-compatible: the embedded struct's fields are written into the same flat raw proto fields as if they'd been declared inline — there is no nesting introduced by the embedding. So the embedding is purely a Go-side organisational choice with no wire-format footprint. You could later promote the embedded Workload into a flat list of individual fields on each kind (or the reverse), and the message sent over the wire would be byte-for-byte identical. The Go composition can be refactored freely without breaking any consumer already decoding the proto.

Testing

  • pkg/tree/kubernetes_test.go — round-trips a Deployment, DaemonSet and CronJob through ToProto/FromProto, asserting base fields, embedded-base fields and kind-specific fields all survive at one flat level (including the multi-level CronJob -> Job -> Workload).
  • Full module test suite passes; gofmt/go vet clean.

Add an explicit Kubernetes provider to the resource tree, mirroring the
provider -> service -> resource shape used by the cloud providers:

- provider: kubernetes
- service: Kubernetes API group (apps, batch)
- resource: workload kind (Deployment, StatefulSet, DaemonSet,
  ReplicaSet, Job, CronJob)

Workloads share a single workload.Workload type (annotations + per-
container sizing); kinds with extra cost-relevant fields embed it and add
their own (replicas; completions/parallelism; schedule). Labels are
stored on the base resource's Tags. CPU/memory are stored in millicores
and bytes — the exact base units a Kubernetes quantity reduces to.

The reflective proto serializer now flattens anonymous embedded structs
into the parent's attributes, so embedding a shared base produces the
same flat wire message as declaring the fields inline.

Also adds the PROVIDER_KUBERNETES mapping (proto v1.150.0).
@liamcervante
liamcervante requested review from a team and liamg June 24, 2026 09:18
@liamcervante
liamcervante merged commit 47a4e6a into main Jun 24, 2026
2 checks passed
@liamcervante
liamcervante deleted the liamcervante/kubernetes-workload-tree branch June 24, 2026 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants