Skip to main content

Module observe

Module observe 

Source
Expand description

Builds the planner input from Kanidm and Kubernetes lists. Observe the world the token planner decides on.

observe reads Kanidm (tokens on the dedicated account) and the Kubernetes API (Deployment template, ReplicaSets, pods, owned config Secrets) with live list calls, never the controller cache, and returns a TokenWorld. Everything that interprets objects is a pure function over k8s_openapi values so it can be tested from fixtures.

The in-use scan is the safety net for revocation: missing a consumer revokes a live token. It therefore errs toward counting:

  • Pods are scanned across the namespace, not by label. A pod counts when it is not Succeeded/Failed (Terminating pods count) and carries a token-id annotation that can name one of our tokens (on the account, on one of our config Secrets, or unparsable), carries our UID label, or mounts a config Secret we identify as ours. Another server’s pods in the same namespace carry the annotation too but are not ours.
  • A mounted Secret is ours when it is an owned Secret, when its name has the content-addressed shape <cr>-<10 hex> (so a Secret that was already deleted is still recognised), or when a pod with our UID label projects its radius.toml key. Every such name is reported in Consumer::config_secrets even if the Secret no longer exists, so the planner sees an unresolved reference instead of nothing.
  • ReplicaSets count while they have replicas, found through the Deployment owner reference or our UID label.
  • Annotation values are passed to the planner raw.

Structs§

DrainObservation
What the finalizer needs from Kubernetes: our Deployment (a foreign one of the same name is not ours to wait for or delete) and every ReplicaSet or pod that still uses one of our config Secrets or tokens.
Observation
The planner input plus the bearer the current template runs with.
ObservedObjects
Everything read from the API and Kanidm for one observation.
SecretScope
Names of config Secrets that are ours.

Functions§

build_world
Assemble the planner input from already-read objects. Pure.
config_secrets
Config Secrets of ours that spec mounts, sorted and unique.
is_our_replicaset
Is this ReplicaSet ours: controlled by our Deployment, or labelled with our UID (the Deployment template label, so it also finds ReplicaSets whose Deployment is already gone)?
observe
Observe Kanidm and Kubernetes for one reconcile.
observe_drain
Kubernetes-only scan used during deletion; reads no Kanidm state.
observed_secret
An owned config Secret as planner input.
observed_tokens
Tokens on the account as planner input.
owned_secrets
Keep only Secrets controlled by this CR. The UID label alone is not ownership: a foreign Secret carrying our label is ignored.
pod_consumer
Consumer for a pod, or None when the pod is finished (Succeeded or Failed) or has nothing to do with us. Terminating pods count: their containers may still authenticate until they exit.
replicaset_consumer
Consumer for one of our ReplicaSets, or None when it has no replicas.
replicaset_has_replicas
A ReplicaSet counts only while it wants or has replicas.
secret_bearer
The bearer stored in a config Secret, if present and non-empty UTF-8.
template_ref
What the Deployment pod template points at.