Skip to content

knative: domain: Require cluster match for claim lookup - #1012

Open
Elvand-Lie wants to merge 1 commit into
headlamp-k8s:mainfrom
Elvand-Lie:fix/knative-clusterdomainclaim-cluster-match
Open

Elvand-Lie wants to merge 1 commit into
headlamp-k8s:mainfrom
Elvand-Lie:fix/knative-clusterdomainclaim-cluster-match

Conversation

@Elvand-Lie

Copy link
Copy Markdown

Summary

Require a ClusterDomainClaim to belong to the same cluster as the
DomainMapping before treating it as the corresponding claim.

Problem

The DomainMapping list can display resources from multiple selected clusters.
It also loads ClusterDomainClaims across those clusters.

getClusterDomainClaim() previously decided whether cluster matching was
needed from a locally created one-element array:

const clusters = [cluster];
const requireClusterMatch = clusters.length > 1;

Because that condition was always false, the lookup matched only the hostname
and target namespace.

If cluster A contained a claim for shop.example.com targeting namespace
store, an identically named DomainMapping in cluster B could incorrectly
display that claim as present. The action for creating the actually missing
claim in cluster B could consequently be hidden.

Fix

Match claims using all three relationship dimensions:

  • cluster
  • hostname
  • target namespace

The helper remains compatible with callers where the DomainMapping does not
carry a cluster directly by using the caller-provided cluster as its effective
cluster.

The lookup no longer mutates the returned claim.

Testing

Added focused tests covering:

  • rejection of a claim from another cluster;
  • successful same-cluster matching;
  • correct selection when both clusters contain the same hostname and namespace;
  • rejection and non-mutation of a clusterless claim;
  • fallback to the caller cluster when the DomainMapping has no cluster;
  • unloaded claims;
  • blank and absent DomainMapping hosts.

The cross-cluster regression test fails against the previous implementation
and passes with this change.

Verification

  • npm run tsc
  • npm run lint
  • npm run format
  • npm run test
  • npm run build
  • git diff --check

All checks passed.

@illume illume left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for this PR.

A few of the commits don't quite follow the project guidelines. We use Linux kernel style for git commits — have a look at the contributing guide and previous commits with git log.

Commits that need attention
  • knative: require cluster match for DomainMapping claims — Description must start with a capital letter — e.g. frontend: HomeButton: Fix the button not frontend: HomeButton: fix the button.
Commit guidelines
  • Use atomic commits focused on a single change.
  • Use the title format <area>: <Description of changes> — description must start with a capital letter.
  • Keep the title under 72 characters (soft requirement).
  • Explain the intention and why the change is needed.
  • Make commit titles meaningful and describe what changed.
  • Do not add code that a later commit rewrites; squash or reorder commits instead.
  • Do not include Fixes #NN in commit messages.

Good examples:

  • frontend: HomeButton: Fix so it navigates to home
  • backend: config: Add enable-dynamic-clusters flag

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The focused implementation correctly addresses the cross-cluster lookup bug and includes comprehensive regression coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Ensures DomainMappings only match ClusterDomainClaims from the same cluster.

Changes:

  • Enforces cluster, hostname, and namespace matching without mutating claims.
  • Adds focused regression and edge-case tests.
File Description
knative/​src/​utils/​domain.ts Enforces strict cluster-aware claim lookup.
knative/​src/​utils/​domain.test.ts Tests cross-cluster matching and fallback behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Looking up the ClusterDomainClaim for a DomainMapping accepted a claim
from any cluster when only one cluster was being viewed. The cluster
comparison was skipped whenever the caller passed a single-element
cluster list, so a same-host, same-namespace claim belonging to a
different cluster could be reported as the DomainMapping's claim and its
state shown as present.

The lookup also wrote the resolved cluster back onto the claim object it
had been handed, mutating data owned by the caller and the query cache.

Match on the effective cluster unconditionally, and return the claim
without decorating it. The caller cluster is still used when the
DomainMapping carries no cluster of its own.

Adds regressions for a claim from another cluster, a clusterless claim, a
DomainMapping without a cluster, and the unloaded and blank-host cases.

Signed-off-by: Elvand Lie Nababan <elvandlie@gmail.com>
@Elvand-Lie Elvand-Lie changed the title knative: require cluster match for DomainMapping claims knative: domain: Require cluster match for claim lookup Sep 29, 2026
@Elvand-Lie
Elvand-Lie force-pushed the fix/knative-clusterdomainclaim-cluster-match branch from ac146b6 to 3dd4e1d Compare September 30, 2026 15:28
@Elvand-Lie
Elvand-Lie force-pushed the fix/knative-clusterdomainclaim-cluster-match branch from 3dd4e1d to 6e529ea Compare September 30, 2026 15:49
@Elvand-Lie

Copy link
Copy Markdown
Author

@illume Rebased and revised to address the review feedback and commit-history requirements. The branch is now a single atomic commit and has been re-verified. Ready for another look.

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.

3 participants