Skip to content

fix(deploy): compare resource quantities by value in the read-only drift check (OK-170) - #183

Merged
stks01 merged 2 commits into
mainfrom
fix/ok-170-drift-quantities
Nov 26, 2026
Merged

stks01 merged 2 commits into
mainfrom
fix/ok-170-drift-quantities

Conversation

@stks01

@stks01 stks01 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Why

deploy/kubernetes/verify-ok-shared-readonly.sh compares every rendered field of an object the gates do not admit with the live object by exact JSON equality. The API server and operators such as CNPG normalise resource quantities, so a rendered 0.5 read back as 500m, or 1024Mi as 1Gi, reports DRIFT on an unchanged object. That STOPs G0 of the ok-shared window when nothing has changed (OK-170).

What changes

  • Value comparison at known locations only. Quantities are compared by exact decimal value only where Kubernetes resource requirements live. Everywhere else the comparison stays exact.
    • Pod-template container, initContainer and ephemeralContainer resources.requests|limits for Deployment, StatefulSet, DaemonSet, ReplicaSet, Job, CronJob and Pod, including List items.
    • CNPG postgresql.cnpg.io Cluster spec.resources.
    • One predicate serves both stages.
  • No precision is lost. Rendered YAML floats keep their source text at quantity paths. Live JSON numbers keep their text. Arithmetic uses Decimal, with enough precision for binary suffixes.
  • Fails closed. Unparseable, missing, null, boolean or list values still report DRIFT, as do a changed value and 1G vs 1Gi.

Tests

deploy/kubernetes/verify-ok-shared-readonly.test.ts: 70 tests pass.

  • Normalisation is accepted on a Deployment container and a CNPG Cluster.
  • Real changes, precision-hiding cases, invalid values, free-form CRD resources and foreign or misplaced paths all report DRIFT.
  • Mutation cases show the value comparison, the precision guard and the string-key guard each fail when removed.

Scope of this evidence

  • Applies to: the non-admitted drift check only. Admitted objects go through the admission gate and are unchanged.
  • Shown in: this PR's tests, and an offline run of both script stages on today's ok-shared-live render.
    • The predicate matches only the four CNPG Cluster ok-console-db quantity paths. Today's results are unchanged.
    • A live cpu: 0.1 against a rendered 100m reads unchanged. 101m reads DRIFT.
  • Follow-ups:
    • Some defensive guards in the path predicate have no test that fails when they are removed: the CNPG spec-only pin, the container-array name check, the typed ClusterList branch, and index-type checks. In each case the surviving variant either crashes (fail closed) or value-compares quantities the server would treat as equal anyway.
    • Quantity fields the server normalises outside the predicate are still compared exactly and could false-STOP in a future render: Pod-level spec.resources, volumeClaimTemplates, PVCs, and CNPG Pooler and pvcTemplate. None appears today.
    • Keys added live under requests/limits that the render lacks are not reported. This is existing behaviour.

Refs OK-170.

@stks01
stks01 merged commit ab7e0f5 into main Nov 26, 2026
2 checks passed
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.

1 participant