Ownership transactions and concurrency

Documentation home · Deployment safety · Kubernetes state · Diagnostics

Orbit arbitrates competing manifests using the authoritative kube-system/orbit-deployment-owners ConfigMap. An owner is a deployment namespace/name and priority. Its persisted JSON format is described in Kubernetes state.

Resource locks

Before deciding ownership, a transaction acquires a reentrant lock for its resource and reads a fresh ownership ConfigMap snapshot. It holds that resource lock through the live-object read, mutation and synchronous owner commit. Competing writers and cleanup for that resource therefore cannot overlap. Different resources can perform those operations concurrently; no shared bookkeeping lock is held across a Kubernetes request.

Lock identities use API group, kind and name. Served API versions share the same lock. Namespace is deliberately omitted to cover legacy portable ownership keys whose namespace slot is None: their concrete namespaced identities must not escape the same arbitration. This conservatively serializes equal names of the same kind/group across namespaces. A group/kind/name with no active or waiting transaction loses its weakly referenced lock entry, so historical resources do not accumulate permanently in a lock registry. API-group aliases remain the separately documented parked limitation.

The controller still requires one active worker per OD and one controller replica with the Recreate strategy. Resource locks are local to that process; they are not distributed leases for multiple active controllers.

Fresh transaction snapshots

Each transaction uses its own complete, validated read. Background monitoring, metrics and unrelated transactions may publish newer observations without changing its decision inputs. The shared last-completed observation is informational; transactions never use it to avoid a fresh authority read. Malformed JSON, invalid aliases, missing metadata and non-404 API read failures prevent the affected transaction from starting. Confirmed 404 initializes the ConfigMap; a competing creation is resolved by reading the winner.

An independent failed observation does not revoke an in-flight transaction's already validated snapshot. A workload mutation still needs a successful ownership commit against the ConfigMap's current UID/resourceVersion. New operations need their own successful fresh reads. Monitoring and metrics make independent requests without acquiring resource locks.

Concurrent commits

A transaction constructs the desired owner map from its snapshot, changes only its target entry and compatible legacy aliases, preserves other ConfigMap data, and PATCHes with the snapshot's UID and resourceVersion. Even writing the same owner after a workload mutation checks these preconditions. Unchanged workloads with an unchanged owner priority do not issue an ownership PATCH.

Concurrent changes to different resources can conflict because all claims live in one ConfigMap. On HTTP 409, the transaction:

  1. Uses a bounded randomized delay before reading a new snapshot.
  2. Requires the ConfigMap UID and every relevant target claim/alias to match its prior decision. A takeover, priority change, alias change or ConfigMap replacement aborts that decision.
  3. Merges its target change into the newly read map, retaining unrelated owners and ConfigMap data, and retries the checked PATCH.

There are at most eight PATCH attempts per commit; jitter is at most one second per retry. A request still has the normal API connection/read timeouts. Conflict retries replay only the ownership PATCH, never the workload mutation. Exhausted conflicts or failed refreshes produce an ownership error, block pruning and require a new decision on a later reconcile.

Non-conflict write errors and lost responses are failures even if a subsequent observation contains the desired owner. The transaction becomes unusable and reloads only for observation. It does not assume success, retain a speculative claim or repeat CREATE/REPLACE/DELETE in the same transaction. A later reconcile reads current ownership and live applied-manifest receipts normally.

Nested recreation

Recreate-on-change re-enters the transaction for its checked DELETE. Reentrant transactions for the same canonical identity share state: the outer operation sees its own successful owner removal before committing the replacement. Entering a nested transaction still refreshes authority and rejects an external takeover or ConfigMap replacement before starting that nested operation. A failed nested ownership operation invalidates the enclosing decision. Deletion continues to require fresh live protection, UID and resourceVersion checks.

Costs, diagnostics and limits

An unchanged resource still requires an ownership ConfigMap read and live-object GET. The fix removes unrelated lock waiting, not these API requests or source, registry and scheduling costs. wait in ownership warnings measures the resource lock; refresh measures its authority read; operation includes object work, owner writes and any conflict retries. Counts of conflicting PATCH attempts appear under orbit_deploy_ownership_operations_total{operation="write",result="conflict"}. See slow reconciliation diagnostics.

The workload mutation, owner commit and OD status write remain separate API operations. A crash or external writer between them can leave partial progress. A detected external takeover stops the stale commit; it cannot retroactively undo an already accepted workload mutation. Applied-manifest receipts support recovery of completed writes. This change adds no atomic cross-resource transaction, distributed lock, workload-readiness gate or durable cleanup queue.