Skip to content

OCPBUGS-80989: Skip to fetch resource if model not found and load the other resources in list-page#16230

Open
vikram-raj wants to merge 1 commit intoopenshift:mainfrom
vikram-raj:ocpbugs-80989
Open

OCPBUGS-80989: Skip to fetch resource if model not found and load the other resources in list-page#16230
vikram-raj wants to merge 1 commit intoopenshift:mainfrom
vikram-raj:ocpbugs-80989

Conversation

@vikram-raj
Copy link
Copy Markdown
Member

@vikram-raj vikram-raj commented Mar 31, 2026

Descriptions:
If any model is not found, then the Resources list page does not show any resources, instead display a error message Error loading Model does not exist.

Before:

image

After:
image

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced handling of unavailable resource models. When resource definitions cannot be found, the system now gracefully skips fetch operations without setting error states, instead of previously returning errors. This eliminates unnecessary error notifications and improves application stability, resilience, and the overall user experience when encountering missing or unknown resource model definitions.

@openshift-ci-robot openshift-ci-robot added jira/severity-moderate Referenced Jira bug's severity is moderate for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Mar 31, 2026
@openshift-ci-robot
Copy link
Copy Markdown
Contributor

@vikram-raj: This pull request references Jira Issue OCPBUGS-80989, which is invalid:

  • expected the bug to target the "4.22.0" version, but no target version was set

Comment /jira refresh to re-evaluate validity if changes to the Jira bug are made, or edit the title of this pull request to link to a different bug.

The bug has been updated to refer to the pull request using the external bug tracker.

Details

In response to this:

Descriptions:
If any model is not found, then the Resources list page does not show any resources, instead display a error message Error loading Model does not exist

  • Changes in this PR
  • If model is missing, it now skips fetch/watch and returns:
    • data: [] for list or {} for single
    • loaded: true
    • loadError: undefined
  • It no longer throws/returns NoModelError in this hook.
  • Also added model lookup fallback by group + kind when version mismatches, which helps avoid false missing-model cases.

I also updated the related tests in:

  • packages/console-dynamic-plugin-sdk/src/utils/k8s/hooks/tests/useK8sWatchResources.spec.tsx

so unknown models assert skip behavior (loadError: undefined) instead of "Model does not exist".

Before:

image

After:
image

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci openshift-ci bot requested review from cajieh and jhadvig March 31, 2026 12:14
@openshift-ci openshift-ci bot added component/sdk Related to console-plugin-sdk approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Mar 31, 2026
@vikram-raj
Copy link
Copy Markdown
Member Author

/jira refresh

@openshift-ci-robot openshift-ci-robot added jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. and removed jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Mar 31, 2026
@openshift-ci-robot
Copy link
Copy Markdown
Contributor

@vikram-raj: This pull request references Jira Issue OCPBUGS-80989, which is valid. The bug has been moved to the POST state.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (4.22.0) matches configured target version for branch (4.22.0)
  • bug is in the state ASSIGNED, which is one of the valid states (NEW, ASSIGNED, POST)
Details

In response to this:

/jira refresh

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 31, 2026

📝 Walkthrough

Walkthrough

The changes modify how useK8sWatchResources handles unknown Kubernetes resource models. The implementation now skips fetching for unresolvable models rather than returning an error, with loadError set to undefined. The caching logic using usePrevious and useRef was removed in favor of direct allK8sModels usage. A fallback resolution mechanism was added that attempts additional matching when initial lookup fails, parsing the model reference into components and searching by kind and API group. Tests were updated to reflect the new non-error behavior.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
frontend/packages/console-dynamic-plugin-sdk/src/utils/k8s/hooks/useK8sWatchResources.ts (1)

55-63: Fallback model resolution logic is sound.

The approach correctly handles version mismatches by:

  1. Normalizing core'' to match the inverse of getReferenceForModel
  2. Filtering candidates by kind + apiGroup
  3. Preferring exact version match, falling back to first candidate

Consider adding a brief inline comment explaining why core is normalized to empty string, as this inverts the convention in k8s-ref.ts and may confuse future maintainers.

📝 Suggested documentation
 if (!resourceModel && modelReference?.split('~').length === 3) {
   const { group, version, kind } = getGroupVersionKindForReference(modelReference);
+  // Normalize 'core' → '' to match K8sModel.apiGroup convention (inverse of getReferenceForModel)
   const normalizedGroup = group === 'core' ? '' : group;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@frontend/packages/console-dynamic-plugin-sdk/src/utils/k8s/hooks/useK8sWatchResources.ts`
around lines 55 - 63, The fallback model resolution works but lacks a clarifying
comment about normalizing group 'core' to ''—add a brief inline comment next to
the normalization line (where normalizedGroup is assigned) explaining that this
inverts the "core" → '' convention used by
getReferenceForModel/getReferenceForModel in k8s-ref.ts so lookups match
allK8sModels; reference modelReference, getGroupVersionKindForReference,
normalizedGroup, and allK8sModels in the comment to make intent clear for future
maintainers.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@frontend/packages/console-dynamic-plugin-sdk/src/utils/k8s/hooks/useK8sWatchResources.ts`:
- Around line 128-133: The plural hook useK8sWatchResources currently treats
missing models by setting loadError: undefined, which differs from
useK8sWatchResource's behavior; update the branch that checks
reduxIDs?.[key]?.noModel inside useK8sWatchResources so it sets loadError to new
NoModelError() (same class used by useK8sWatchResource) while preserving data
and loaded values, ensuring consumers see the same error representation across
both hooks (refer to reduxIDs, resources, loadError and NoModelError in the
function).

---

Nitpick comments:
In
`@frontend/packages/console-dynamic-plugin-sdk/src/utils/k8s/hooks/useK8sWatchResources.ts`:
- Around line 55-63: The fallback model resolution works but lacks a clarifying
comment about normalizing group 'core' to ''—add a brief inline comment next to
the normalization line (where normalizedGroup is assigned) explaining that this
inverts the "core" → '' convention used by
getReferenceForModel/getReferenceForModel in k8s-ref.ts so lookups match
allK8sModels; reference modelReference, getGroupVersionKindForReference,
normalizedGroup, and allK8sModels in the comment to make intent clear for future
maintainers.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 4a2c19a0-e6a9-4488-a841-bc12a7079b27

📥 Commits

Reviewing files that changed from the base of the PR and between 2e67298 and 57c6b95.

📒 Files selected for processing (2)
  • frontend/packages/console-dynamic-plugin-sdk/src/utils/k8s/hooks/__tests__/useK8sWatchResources.spec.tsx
  • frontend/packages/console-dynamic-plugin-sdk/src/utils/k8s/hooks/useK8sWatchResources.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (1)
**

⚙️ CodeRabbit configuration file

-Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity.

Files:

  • frontend/packages/console-dynamic-plugin-sdk/src/utils/k8s/hooks/useK8sWatchResources.ts
  • frontend/packages/console-dynamic-plugin-sdk/src/utils/k8s/hooks/__tests__/useK8sWatchResources.spec.tsx
🔇 Additional comments (2)
frontend/packages/console-dynamic-plugin-sdk/src/utils/k8s/hooks/__tests__/useK8sWatchResources.spec.tsx (1)

368-420: Test updates correctly reflect the new silent-skip semantics.

The assertions now expect loadError: undefined instead of an error object, and the test descriptions clearly communicate the behavioral change. The tests validate that no API calls are made when models are unknown, which is the intended optimization.

frontend/packages/console-dynamic-plugin-sdk/src/utils/k8s/hooks/useK8sWatchResources.ts (1)

50-53: Simplified model resolution by removing ref caching — good trade-off.

Replacing the usePrevious/useRef caching pattern with direct allK8sModels usage reduces complexity. Since model definitions rarely change at runtime, the potential for extra recomputations is minimal compared to the maintenance burden of the previous approach.

Also applies to: 77-77

Comment on lines 128 to 133
if (reduxIDs?.[key]?.noModel) {
acc[key] = {
data: resources[key].isList ? [] : {},
loaded: true,
loadError: new NoModelError(),
loadError: undefined,
};
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.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify current NoModelError usage in useK8sWatchResource and any consumers checking for it
rg -n "NoModelError" --type ts -C 3

Repository: openshift/console

Length of output: 2813


🏁 Script executed:

#!/bin/bash
# Check consumers of both hooks and their return type expectations
echo "=== Searching for useK8sWatchResources (plural) usage ==="
rg -n "useK8sWatchResources" --type ts -A 2 | head -40

echo -e "\n=== Searching for useK8sWatchResource (singular) usage ==="
rg -n "useK8sWatchResource[^s]" --type ts -A 2 | head -40

Repository: openshift/console

Length of output: 7774


🏁 Script executed:

#!/bin/bash
# Check type definitions for return types
echo "=== Type definition for useK8sWatchResources ==="
rg -n "type UseK8sWatchResources|interface.*useK8sWatchResources" --type ts -A 5

echo -e "\n=== Type definition for useK8sWatchResource ==="
rg -n "type UseK8sWatchResource[^s]|interface.*useK8sWatchResource[^s]" --type ts -A 5

Repository: openshift/console

Length of output: 1615


🏁 Script executed:

#!/bin/bash
# Check if consumers explicitly check for NoModelError
rg -n "NoModelError|instanceof.*NoModelError" --type ts | grep -v "import\|export\|class NoModelError"

Repository: openshift/console

Length of output: 194


🏁 Script executed:

#!/bin/bash
# Check WatchK8sResult and WatchK8sResults type definitions
rg -n "type WatchK8sResult|interface WatchK8sResult" --type ts -A 5

Repository: openshift/console

Length of output: 2130


🏁 Script executed:

#!/bin/bash
# Check how consumers handle the loadError from useK8sWatchResource
rg -n "loadError.*NoModelError|instanceof.*NoModelError" --type ts

Repository: openshift/console

Length of output: 43


API inconsistency with useK8sWatchResource (singular hook).

The singular hook useK8sWatchResource returns new NoModelError() when a model is not found (line 60), while this plural hook returns loadError: undefined. This divergence in error semantics creates an inconsistent contract for consumers:

Hook Missing model behavior
useK8sWatchResource [data, loaded, new NoModelError()]
useK8sWatchResources { data, loaded: true, loadError: undefined }

Though the type system allows both (using any), this inconsistency can confuse developers switching between hooks or extending the SDK. Consider aligning both to return the same error representation.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@frontend/packages/console-dynamic-plugin-sdk/src/utils/k8s/hooks/useK8sWatchResources.ts`
around lines 128 - 133, The plural hook useK8sWatchResources currently treats
missing models by setting loadError: undefined, which differs from
useK8sWatchResource's behavior; update the branch that checks
reduxIDs?.[key]?.noModel inside useK8sWatchResources so it sets loadError to new
NoModelError() (same class used by useK8sWatchResource) while preserving data
and loaded values, ensuring consumers see the same error representation across
both hooks (refer to reduxIDs, resources, loadError and NoModelError in the
function).

@vikram-raj vikram-raj changed the title OCPBUGS-80989: Skip to fetch resource if model not found and load the other resources in useK8sWatchResources hook OCPBUGS-80989: Skip to fetch resource if model not found and load the other resources in list-page Apr 2, 2026
@openshift-ci openshift-ci bot added the component/core Related to console core functionality label Apr 2, 2026
@vikram-raj vikram-raj requested a review from cajieh April 2, 2026 11:48
@openshift-ci-robot
Copy link
Copy Markdown
Contributor

@vikram-raj: This pull request references Jira Issue OCPBUGS-80989, which is valid.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (4.22.0) matches configured target version for branch (4.22.0)
  • bug is in the state POST, which is one of the valid states (NEW, ASSIGNED, POST)

The bug has been updated to refer to the pull request using the external bug tracker.

Details

In response to this:

Descriptions:
If any model is not found, then the Resources list page does not show any resources, instead display a error message Error loading Model does not exist.

Before:

image

After:
image

Summary by CodeRabbit

  • Bug Fixes
  • Enhanced handling of unavailable resource models. When resource definitions cannot be found, the system now gracefully skips fetch operations without setting error states, instead of previously returning errors. This eliminates unnecessary error notifications and improves application stability, resilience, and the overall user experience when encountering missing or unknown resource model definitions.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@cajieh
Copy link
Copy Markdown
Contributor

cajieh commented Apr 2, 2026

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Apr 2, 2026
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Apr 2, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cajieh, vikram-raj

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@vikram-raj
Copy link
Copy Markdown
Member Author

/retest

@yapei
Copy link
Copy Markdown
Contributor

yapei commented Apr 3, 2026

Screenshot 2026-04-03 at 5 09 19 PM

The fix looks good to me
/verified by @yapei

@openshift-ci-robot openshift-ci-robot added the verified Signifies that the PR passed pre-merge verification criteria label Apr 3, 2026
@openshift-ci-robot
Copy link
Copy Markdown
Contributor

@yapei: This PR has been marked as verified by @yapei.

Details

In response to this:

Screenshot 2026-04-03 at 5 09 19 PM

The fix looks good to me
/verified by @yapei

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-merge-bot
Copy link
Copy Markdown
Contributor

/retest-required

Remaining retests: 0 against base HEAD 89b5685 and 2 for PR HEAD 42ab08d in total

@cajieh
Copy link
Copy Markdown
Contributor

cajieh commented Apr 3, 2026

/test e2e-gcp-console

@openshift-merge-bot
Copy link
Copy Markdown
Contributor

/retest-required

Remaining retests: 0 against base HEAD e672e69 and 1 for PR HEAD 42ab08d in total

@openshift-merge-bot
Copy link
Copy Markdown
Contributor

/retest-required

Remaining retests: 0 against base HEAD 2d40d21 and 0 for PR HEAD 42ab08d in total

@openshift-merge-bot
Copy link
Copy Markdown
Contributor

/hold

Revision 42ab08d was retested 3 times: holding

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 4, 2026
@cajieh
Copy link
Copy Markdown
Contributor

cajieh commented Apr 4, 2026

/cancel hold

@cajieh
Copy link
Copy Markdown
Contributor

cajieh commented Apr 4, 2026

/test e2e-gcp-console

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Apr 4, 2026

@vikram-raj: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-gcp-console 42ab08d link true /test e2e-gcp-console

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. component/core Related to console core functionality component/sdk Related to console-plugin-sdk do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. jira/severity-moderate Referenced Jira bug's severity is moderate for the branch this PR is targeting. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged. verified Signifies that the PR passed pre-merge verification criteria

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants