mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-21 12:13:55 +09:00
notContains passes whenever its path does not resolve, and also
whenever it resolves to something that simply lacks the forbidden
content. A different container at the same index qualifies, so these
guards go green the moment a sidecar is placed ahead of the workload
they were written for, while the flag or env var they forbid comes
back on the real container.
Assert the identity at that index first, in each affected case: the
container name for the Deployment-shaped ones, and for the Cilium
policy its selector, since a deny rule has no name. The selector
identifies that rule only while there is one rule to identify, so it
is paired with a length assertion, and with a second one on the
rule's toPorts, because that path carries two indexes and anchoring
the outer one alone leaves the inner free.
The anchor goes only where nothing else holds the index. A positive
contains on the same path fails on its own once a sidecar arrives
ahead of the workload, and an equal on the whole argument list fails
the same way, so neither carries a separate anchor. A negative does,
including the per-element form below: a wildcard resolving to the
sidecar's own arguments matches nothing and passes.
Several of the guards could not fail for the reason they name, and
the anchor alone would have left that hidden behind a comment saying
they were covered. contains and notContains compare elements for
equality, so a mapping is compared whole: `{name: GF_...}` never
matched an entry carrying a value beside the name, and `{port: 7473}`
would not match that port re-added with a protocol beside it, which
is how the neighbouring entry in the same list is written. Those get
`any: true`.
Equality against a rendered argument is the same failure worn
differently, and it arrives in three disguises. A prefix that never
equals an element: `--pinned-tenants=` never equalled
`--pinned-tenants=tenant-a=shard0`, and `--target-host=` never
equalled a rendered `--target-host=<value>`. One value out of many
under a name that claims the flag: `--compatibility=cilium` left the
kilo default render free to carry `--compatibility=flannel` off the
same values key, and the two `--proxy-fqdn` negatives forbade only
the FQDN the default cluster-domain produces. And a form that holds
by luck: `--gateway-api` still fails today only because that template
renders it bare, so an upstream switch to `--gateway-api=true` would
retire the guard in silence.
All of those become notMatchRegex over args[*], which matches the
flag name per element and fails on any value and on the bare form
alike. A length assertion would not have covered the prefix cases,
since an upstream bump that adds the flag while consolidating another
argument keeps the count. A wildcard that resolves to nothing still
passes, so the index anchors stay.
The whole argument list is a different instrument, answering what the
default invocation is rather than whether one flag is absent. It
fails on an argument added, removed or swapped instead of only on the
ones someone thought to enumerate, which is worth having where the
template is first-party and a failure is a deliberate change asking
to be read. flux-shard-operator gets it in `renders the default
Deployment shape`, replacing eleven individual contains that listed
exactly the same eleven elements; `--shard-cpu-limit=` was dead for
the prefix reason and is dropped rather than repaired, because that
list now covers it. The vendored ouroboros templates get no such pin:
upstream churn arrives there on its own schedule, and a whole-list
assertion would fail a test named for one flag for a reason that has
nothing to do with that flag.
Anchor every index on a path, not the outermost one. The Cilium
assertion reads spec.ingressDeny[0].toPorts[0].ports, and pinning the
rule list alone would still let the port return on a second toPorts
entry of the same rule.
Each guard was checked by rendering what it forbids onto the element
it names, and each anchor by rendering the shift it exists to catch.
The form is already used in this tree, in opensearch-operator and
dashboard. Assertions of the same shape remain in files this commit
does not touch, including one in a package it does, and stay out of
scope here.
Assisted-By: Claude <noreply@anthropic.com>
Signed-off-by: Aleksei Sviridkin <f@lex.la>
Signed-off-by: Aleksei Sviridkin <3811295@gmail.com>
182 lines
8.5 KiB
YAML
182 lines
8.5 KiB
YAML
suite: cozy-ouroboros controller defaults
|
|
templates:
|
|
- charts/ouroboros/templates/controller-deployment.yaml
|
|
- charts/ouroboros/templates/_helpers.tpl
|
|
release:
|
|
name: ouroboros
|
|
namespace: cozy-ouroboros
|
|
tests:
|
|
- it: defaults to coredns mode (host scenario; tenant overrides via apps/kubernetes)
|
|
template: charts/ouroboros/templates/controller-deployment.yaml
|
|
asserts:
|
|
- contains:
|
|
path: spec.template.spec.containers[0].args
|
|
content: --mode=coredns
|
|
|
|
- it: emits runtime-composition flags (no chart-baked --proxy-fqdn) — chart is platform-agnostic and lets controller compose the rewrite-target FQDN at startup from the auto-detected cluster-domain
|
|
template: charts/ouroboros/templates/controller-deployment.yaml
|
|
asserts:
|
|
- contains:
|
|
path: spec.template.spec.containers[0].args
|
|
content: --proxy-service-name=ouroboros-proxy
|
|
- contains:
|
|
path: spec.template.spec.containers[0].args
|
|
content: --proxy-service-namespace=cozy-ouroboros
|
|
# Match the flag name per element, not one whole element against one
|
|
# value: contains and notContains compare elements for equality, and the
|
|
# baked FQDN carries whatever controller.clusterDomain is set to, so an
|
|
# equality check against the form the default cluster-domain produces
|
|
# leaves every other value unforbidden.
|
|
- notMatchRegex:
|
|
path: spec.template.spec.containers[0].args[*]
|
|
pattern: "^--proxy-fqdn"
|
|
|
|
- it: leaves Gateway-API watching off at the parent default (consumer enables)
|
|
template: charts/ouroboros/templates/controller-deployment.yaml
|
|
asserts:
|
|
# Anchor the index before asserting on it. A negative assert passes
|
|
# whenever its path resolves to something that does not match, and a
|
|
# different container at [0] qualifies — as does an index resolving to
|
|
# nothing at all — so without this the guard goes green if a sidecar is
|
|
# ever placed ahead of the controller.
|
|
- equal:
|
|
path: spec.template.spec.containers[0].name
|
|
value: controller
|
|
# Match the flag name per element. An equality check against the bare
|
|
# form the chart renders today would go on passing if it ever rendered
|
|
# --gateway-api=true, with watching on.
|
|
- notMatchRegex:
|
|
path: spec.template.spec.containers[0].args[*]
|
|
pattern: "^--gateway-api"
|
|
|
|
- it: emits chart-default --resync=30s — host scenario inherits the upstream chart default (changed from 10m in upstream v0.7.x). The reduction is the controller's only recovery path when an Ingress watch silently dies, and 30s caps worst-case event-to-reconcile latency under broken-watch conditions. Pinning here catches a future upstream bump back to the longer value before it lands as a CI surprise.
|
|
template: charts/ouroboros/templates/controller-deployment.yaml
|
|
asserts:
|
|
- contains:
|
|
path: spec.template.spec.containers[0].args
|
|
content: --resync=30s
|
|
|
|
- it: emits chart-default --log-level=info — host scenario stays at info verbosity by upstream chart default. Tenants override to debug via apps/kubernetes wrapper (see cozystack.defaultOuroborosValues). Pinning here keeps the host quiet by default and catches a regression where the host wrapper accidentally inherits the tenant debug value.
|
|
template: charts/ouroboros/templates/controller-deployment.yaml
|
|
asserts:
|
|
- contains:
|
|
path: spec.template.spec.containers[0].args
|
|
content: --log-level=info
|
|
|
|
# The upstream chart owns this contract and tests it across every mode;
|
|
# these pins exist because cozystack is the kind of consumer the
|
|
# contract protects — helm-controller applies server-side, and
|
|
# server-side apply is the only path on which a mode-gated strategy
|
|
# breaks. Up to chart 0.8.0 the strategy was rendered only in
|
|
# external-dns mode, as type: Recreate. Switching a live release into
|
|
# that mode laid Recreate on top of the rollingUpdate block the
|
|
# apiserver defaults onto any Deployment created without one, and the
|
|
# apiserver rejected it with "spec.strategy.rollingUpdate: Forbidden:
|
|
# may not be specified when strategy `type` is 'Recreate'". A
|
|
# client-side helm upgrade clears rollingUpdate via retainKeys and
|
|
# never reproduces it, so no local render catches a regression here.
|
|
#
|
|
# cozystack pins coredns on the host and coredns-import for tenants,
|
|
# and configures external-dns nowhere, so the break is not reachable
|
|
# from any shipped configuration — this is a latent break and the pins
|
|
# are defence in depth for a user-settable value. All three modes are
|
|
# asserted, external-dns included: it is the only mode that ever
|
|
# rendered Recreate, so a bump that re-gates the block would slip past
|
|
# a coredns-only suite unnoticed.
|
|
- it: renders a no-surge RollingUpdate strategy, never Recreate — the mode-switch upgrade path is server-side-apply-only and breaks on any other shape
|
|
template: charts/ouroboros/templates/controller-deployment.yaml
|
|
asserts:
|
|
- equal:
|
|
path: spec.strategy.type
|
|
value: RollingUpdate
|
|
- equal:
|
|
path: spec.strategy.rollingUpdate.maxSurge
|
|
value: 0
|
|
- equal:
|
|
path: spec.strategy.rollingUpdate.maxUnavailable
|
|
value: 1
|
|
|
|
- it: renders that same strategy in coredns-import mode — the mode tenants actually run
|
|
template: charts/ouroboros/templates/controller-deployment.yaml
|
|
set:
|
|
ouroboros:
|
|
controller:
|
|
mode: coredns-import
|
|
asserts:
|
|
- equal:
|
|
path: spec.strategy.type
|
|
value: RollingUpdate
|
|
- equal:
|
|
path: spec.strategy.rollingUpdate.maxSurge
|
|
value: 0
|
|
- equal:
|
|
path: spec.strategy.rollingUpdate.maxUnavailable
|
|
value: 1
|
|
|
|
# The mode that rendered type: Recreate up to 0.8.0, and the only one a
|
|
# transition into which could trip the rejection. A re-gate that
|
|
# restored Recreate here while leaving the coredns paths on
|
|
# RollingUpdate would satisfy every other case in this file.
|
|
- it: renders that same strategy in external-dns mode — the one mode that previously rendered Recreate
|
|
template: charts/ouroboros/templates/controller-deployment.yaml
|
|
set:
|
|
ouroboros:
|
|
controller:
|
|
mode: external-dns
|
|
asserts:
|
|
- equal:
|
|
path: spec.strategy.type
|
|
value: RollingUpdate
|
|
- equal:
|
|
path: spec.strategy.rollingUpdate.maxSurge
|
|
value: 0
|
|
- equal:
|
|
path: spec.strategy.rollingUpdate.maxUnavailable
|
|
value: 1
|
|
|
|
- it: writes into the kube-system/coredns Corefile by default (host mode)
|
|
template: charts/ouroboros/templates/controller-deployment.yaml
|
|
asserts:
|
|
- contains:
|
|
path: spec.template.spec.containers[0].args
|
|
content: --coredns-namespace=kube-system
|
|
- contains:
|
|
path: spec.template.spec.containers[0].args
|
|
content: --coredns-configmap=coredns
|
|
- contains:
|
|
path: spec.template.spec.containers[0].args
|
|
content: --coredns-key=Corefile
|
|
|
|
- it: tenant valuesOverride flips into coredns-import mode (and runtime-composition flags carry over — tenants are the actual consumers of this mode, the host stays on coredns)
|
|
template: charts/ouroboros/templates/controller-deployment.yaml
|
|
set:
|
|
ouroboros:
|
|
controller:
|
|
mode: coredns-import
|
|
asserts:
|
|
- contains:
|
|
path: spec.template.spec.containers[0].args
|
|
content: --mode=coredns-import
|
|
- contains:
|
|
path: spec.template.spec.containers[0].args
|
|
content: --coredns-import-configmap=coredns-custom
|
|
- contains:
|
|
path: spec.template.spec.containers[0].args
|
|
content: --coredns-import-key=ouroboros.override
|
|
# Runtime-composition flags MUST be emitted in coredns-import mode
|
|
# too — this is the mode tenants actually run, so a future refactor
|
|
# in the upstream controller-deployment template that drops the
|
|
# composition block from this branch only would break tenants
|
|
# silently. The negative assert pins that no --proxy-fqdn is baked at
|
|
# render time when no clusterDomain is configured (the
|
|
# platform-agnostic default).
|
|
- contains:
|
|
path: spec.template.spec.containers[0].args
|
|
content: --proxy-service-name=ouroboros-proxy
|
|
- contains:
|
|
path: spec.template.spec.containers[0].args
|
|
content: --proxy-service-namespace=cozy-ouroboros
|
|
- notMatchRegex:
|
|
path: spec.template.spec.containers[0].args[*]
|
|
pattern: "^--proxy-fqdn"
|