Skip to content

feat(components): declare the bridge cluster identity and epoch to CMS - #1273

Merged
VLukiantsev merged 4 commits into
feat/components-ownership-fence-enforcement-b548436300from
feat/components-bridge-cluster-declaration-b548436300
Oct 16, 2026
Merged

VLukiantsev merged 4 commits into
feat/components-ownership-fence-enforcement-b548436300from
feat/components-bridge-cluster-declaration-b548436300

Conversation

@VLukiantsev

@VLukiantsev VLukiantsev commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

xmc-bridge reads the kube-system Namespace UID as its cluster identity and, from a leader-elected runnable, declares (clusterUID, --cluster-name, --ownership-epoch) to CMS via DeclareClusterEpoch at startup and on every heartbeat. The bridge does not act on the answer yet; cold standby is the next layer (#1236).

Motivation & Context

With the CMS fence in place (#1234/#1235), CMS needs to know which cluster is the active writer before the bridge sends sourced requests, and a DR takeover needs a declared, higher epoch. Split out of #1236 to keep that layer within the size limits: this slice is the declaration end to end (flags, Helm, RBAC, runnable), observable in CMS as the fence row.

Key Changes

  • ReadClusterUID: GET of the kube-system Namespace at startup; startup fails without it and there is no override. New ClusterRole/xmc-bridge-cluster-identity-<release-namespace> (namespace-suffixed so multiple installs in one cluster do not collide) grants only get on namespaces with resourceNames: [kube-system].
  • New flags --cluster-name / CLUSTER_NAME (DNS-1123 label, defaults to --release-name) and --ownership-epoch / COMPONENT_OWNERSHIP_EPOCH (>= 1, default 1); Helm values componentsDeployment.clusterName and componentsDeployment.ownershipEpoch (rendered with int64, so large epochs are not rendered in float notation; an explicit 0 is passed through for the binary to reject); README rows for both flags (moved here from feat(components): add CMS ownership metrics and DR takeover documentation #1243 so the docs ship with the flags). The existing duration checks move into validateTimings, which keeps ParseConfig within the gocyclo limit of 15 now that it also validates the cluster identity.
  • ClusterFence: leader-elected runnable (mgr.Add(fence)) that declares immediately and every defaultCMSHeartbeatInterval (5 min) and bounds each declaration with a 10s DeclareTimeout. A fenced or regressed declaration (FailedPrecondition) is logged as an error and retried at the heartbeat interval; other failures are retried after 5s. In this layer Declare is stateless.
  • CMSClient gains DeclareClusterEpoch.
  • Tests: TestReadClusterUID, TestNewClusterFence_Validation, TestClusterFence_StartDeclaresToCMS (a started fence declares to an in-process CMS so a second cluster at the same epoch is fenced out), TestClusterFence_DeclareSendsIdentity, TestClusterFence_StartBoundsHungDeclare, TestClusterFence_RetryDelay, flag/env cases in main_test.go, the RBAC template test, and test/helm/bridge_cluster_identity_test.py.

Stack Position

Assumptions

Verification & Testing

  • Commands Executed: bazel test //cmd/xmc_bridge/... //pkg/components/bridge/... plus the pre-commit affected-test set (cms, store with the Spanner emulator, actuator, kind harness unit test), golangci-lint run (v1.64.6), gofmt -l.
  • Coverage & Test Status: all pass at this layer's tip; the whole stack passes at the top, including //test/e2e:components_lifecycle_test.
  • Diff size (tools/analyze_diff_size.py): 293 prod / 382 test / 675 total / 2 doc lines.

Live Deployment & Manual Testing

Scenario Result Observation
kube-system UID discovery and leader-elected DeclareClusterEpoch ✅ PASS On startup the bridge read the kube-system Namespace UID via ClusterRole/xmc-bridge-cluster-identity, declared epoch 1 into the fence row (FenceId=1), and refreshed LastSeenTime every 5 minutes.

Related Issues / Bugs

Bug: 548436300

TAG=agy
CONV=d833b0e6-4821-48f6-8576-776d53f55a5c

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces cluster identity and fencing mechanisms to the xmc-bridge controller by adding configuration options for cluster name and ownership epoch, reading the kube-system namespace UID, and implementing a ClusterFence runnable to periodically declare the cluster's epoch to CMS. It also updates Helm templates, RBAC permissions, and tests. The feedback recommends adding a defensive nil check on the retrieved namespace object in ReadClusterUID to prevent potential nil pointer dereferences.

Comment thread pkg/components/bridge/cluster_fence.go Resolved
@VLukiantsev
VLukiantsev added this pull request to stack #1277 October 14, 2026 13:32
@VLukiantsev
VLukiantsev force-pushed the feat/components-bridge-cluster-declaration-b548436300 branch from eeba6f8 to a526ddd Compare October 14, 2026 13:54
@VLukiantsev
VLukiantsev force-pushed the feat/components-bridge-cluster-declaration-b548436300 branch 3 times, most recently from 1d76621 to 9ed5476 Compare October 15, 2026 08:07
@VLukiantsev
VLukiantsev force-pushed the feat/components-bridge-cluster-declaration-b548436300 branch 2 times, most recently from 401b6fe to 3053d60 Compare October 15, 2026 09:29
@VLukiantsev
VLukiantsev force-pushed the feat/components-bridge-cluster-declaration-b548436300 branch from 3053d60 to a4b902a Compare October 15, 2026 09:49
@VLukiantsev
VLukiantsev force-pushed the feat/components-bridge-cluster-declaration-b548436300 branch from a4b902a to 700df49 Compare October 15, 2026 10:02
@VLukiantsev
VLukiantsev force-pushed the feat/components-bridge-cluster-declaration-b548436300 branch 2 times, most recently from 0888cf6 to 4da4e70 Compare October 15, 2026 11:16
@VLukiantsev
VLukiantsev force-pushed the feat/components-bridge-cluster-declaration-b548436300 branch 2 times, most recently from 2059d84 to 6104642 Compare October 15, 2026 12:43
@VLukiantsev
VLukiantsev force-pushed the feat/components-bridge-cluster-declaration-b548436300 branch from 6104642 to 65ea951 Compare October 15, 2026 12:50
@VLukiantsev
VLukiantsev force-pushed the feat/components-bridge-cluster-declaration-b548436300 branch from 65ea951 to 0627aa1 Compare October 15, 2026 13:11
@VLukiantsev
VLukiantsev force-pushed the feat/components-bridge-cluster-declaration-b548436300 branch from 1037d72 to a5ebe27 Compare October 16, 2026 08:53
@VLukiantsev
VLukiantsev force-pushed the feat/components-bridge-cluster-declaration-b548436300 branch 3 times, most recently from 3468e16 to 63db6c3 Compare October 16, 2026 11:27
@VLukiantsev
VLukiantsev force-pushed the feat/components-bridge-cluster-declaration-b548436300 branch 2 times, most recently from 957b5de to 60db89b Compare October 16, 2026 12:18
Comment thread pkg/components/bridge/cluster_fence.go Resolved
Comment thread cmd/xmc_bridge/main.go Resolved
@VLukiantsev
VLukiantsev force-pushed the feat/components-bridge-cluster-declaration-b548436300 branch 2 times, most recently from e5a9830 to 94b7016 Compare October 16, 2026 13:26
@VLukiantsev
VLukiantsev marked this pull request as ready for review October 16, 2026 13:59
@github-actions
github-actions Bot requested a review from janzak-dev October 16, 2026 13:59
janzak-dev
janzak-dev previously approved these changes Oct 16, 2026
Comment thread pkg/components/bridge/cluster_fence.go Resolved
Comment thread pkg/components/bridge/cms_client.go Resolved
The CMS ownership fence (DeclareClusterEpoch) has no caller yet. This
layer makes xmc-bridge declare its cluster so that CMS knows which
cluster is active and a DR takeover can reassign owners:

- RunBridge reads the kube-system Namespace UID (ReadClusterUID) as a
  stable cluster UID and builds a ClusterIdentity from it, the new
  --cluster-name / CLUSTER_NAME flag (a DNS-1123 label, defaulting to
  --release-name) and --ownership-epoch / COMPONENT_OWNERSHIP_EPOCH
  (>= 1, default 1).
- A leader-elected ClusterFence runnable calls DeclareClusterEpoch
  immediately and every heartbeat interval, each call bounded by a 10s
  timeout, and retries after 5s when CMS is unreachable or rejects the
  declaration. Only the Lease holder declares.
- Helm: componentsDeployment.clusterName / ownershipEpoch values feed the
  ConfigMap, and a namespace-suffixed ClusterRole/Binding grants get on
  the kube-system Namespace only.
- The xmc-bridge README documents both flags.

The bridge does not act on the fence yet: its intents are still
unsourced, so a fenced bridge only logs a warning and keeps retrying.
Holding a fenced bridge in cold standby is the next layer.

Tests: ReadClusterUID, NewClusterFence validation, a Start heartbeat
against an in-process CMS that fences out a second cluster at the same
epoch, Declare request/err wrapping, the bounded hung declaration, the
new flags and env vars, and the RBAC template.

Bug: 548436300
TAG=agy
CONV=b2ebecbe-c04a-4fb7-a16c-d23de82ed3e5
Address review comment on #1273 by checking that the returned Namespace
object is non-nil before accessing its UID.

Comment link: #1273 (comment)
Bug: 548436300
TAG=agy
CONV=d833b0e6-4821-48f6-8576-776d53f55a5c
…idation table-driven

Fold the three ReadClusterUID error blocks and the success block into
one named table, and turn the unnamed invalid-identity loop plus the nil
CMS check into named rows, each run as a subtest. Inputs and assertions
are unchanged.

Bug: 548436300
TAG=agy
CONV=d833b0e6-4821-48f6-8576-776d53f55a5c
… an integer

- ClusterFence retries a FailedPrecondition declaration (fenced or
  regressed epoch) at the heartbeat interval and logs it as an error;
  transient failures keep the fast retry.
- The chart renders COMPONENT_OWNERSHIP_EPOCH with int64, so large
  epochs are not rendered in float notation, and passes an explicit 0
  through for xmc-bridge to reject instead of defaulting it to 1.
- Replace the map-based duration check with an explicit, ordered
  validateTimings helper that keeps ParseConfig within the gocyclo limit.

Comment links:
#1273 (comment)
#1273 (comment)
#1273 (comment)

Bug: 548436300
TAG=agy
CONV=d833b0e6-4821-48f6-8576-776d53f55a5c
@VLukiantsev
VLukiantsev force-pushed the feat/components-bridge-cluster-declaration-b548436300 branch from b21d7cf to 1c17668 Compare October 16, 2026 15:16

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Incremental PR Approval

Clean rebase detected with zero semantic patch lines changed.

Preserving prior approval by @janzak-dev on commit b21d7cf.

@VLukiantsev
VLukiantsev added this pull request to the merge queue Oct 16, 2026
Merged via the queue into main with commit ed840d2 Oct 16, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority::2-high top of mind. should not wait.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants