Skip to content

fix(knative): guard optional spec property access in service and domain claim lists - #1074

Open
vikash7485 wants to merge 1 commit into
headlamp-k8s:mainfrom
vikash7485:fix/knative-spec-optional-chaining
Open

vikash7485 wants to merge 1 commit into
headlamp-k8s:mainfrom
vikash7485:fix/knative-spec-optional-chaining

Conversation

@vikash7485

Copy link
Copy Markdown

Description

This PR fixes potential runtime TypeError crashes in the Knative plugin (@headlamp-k8s/knative) when rendering custom resource lists where .spec or nested .spec.ref fields are omitted or initializing.

Problem

  1. KServicesList (plugins/knative/src/components/kservices/List.tsx):
    In domainByServiceKey, the loop accesses dm.spec.ref.name and dm.spec.ref.namespace directly without optional chaining on spec or ref. When a DomainMapping resource is in a syncing or partial state (missing .spec or .spec.ref), rendering the KServices list throws TypeError: Cannot read properties of undefined (reading 'name'), causing the entire view to crash.
  2. ClusterDomainClaimsList (plugins/knative/src/components/clusterdomainclaims/List.tsx):
    The namespace column getValue accessor reads cdc.spec.namespace without optional chaining, whereas the cell renderer correctly guards with cdc.spec?.namespace. If a ClusterDomainClaim payload lacks a spec field, table sorting/filtering crashes with TypeError: Cannot read properties of undefined (reading 'namespace').

Solution

  • Applied optional chaining (dm.spec?.ref?.name and dm.spec?.ref?.namespace) in KServicesList.
  • Applied optional chaining (cdc.spec?.namespace || '') in ClusterDomainClaimsList column accessor.

How Has This Been Tested?

  • TypeScript Type Checking: Verified compilation with npx tsc --noEmit (0 errors).
  • ESLint / Formatting: Verified formatting rules pass cleanly (npx eslint).
  • Unit Testing: Verified all 22 existing unit tests pass (npx vitest run).

@vikash7485
vikash7485 force-pushed the fix/knative-spec-optional-chaining branch from 96ace82 to 02d3657 Compare August 8, 2026 14:30
@illume
illume requested a balanced review from Copilot September 29, 2026 06:49

@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 the contribution.

Could you take a look at the commit messages in this PR? We follow a Linux kernel style for git commits — see the contributing guide and git log for examples.

Commits that need attention
  • fix(knative): guard optional spec property access in service and domain claim lists — Missing area: description prefix — e.g. frontend: HomeButton: Fix so it navigates to home or backend: config: Add enable-dynamic-clusters flag.
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 null-safety changes correctly address both documented crash paths without introducing regressions.

Review effort: Balanced
Findings: None

What changed in this PR

Prevents Knative list views from crashing on partially initialized resources.

Changes:

  • Safely reads optional DomainMapping references.
  • Safely reads ClusterDomainClaim namespaces.
File Description
knative/​src/​components/​kservices/​List.tsx Guards optional DomainMapping fields.
knative/​src/​components/​clusterdomainclaims/​List.tsx Guards the namespace accessor.

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

…aim lists

Safely access optional spec and spec.ref fields in KServices and ClusterDomainClaims list views to prevent runtime TypeErrors.

Signed-off-by: vikash7485 <vikkiraj073@gmail.com>
@vikash7485
vikash7485 force-pushed the fix/knative-spec-optional-chaining branch from 02d3657 to 667e710 Compare September 30, 2026 16:55
@vikash7485
vikash7485 requested a review from illume September 30, 2026 16:56
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