Skip to content

Conversation

@feloy
Copy link
Contributor

@feloy feloy commented Dec 15, 2025

Part of #21

On activation, the extension tries to connect to the Kubernetes Dashboard extension, to get its subscriber

@feloy feloy requested review from a team and benoitf as code owners December 15, 2025 13:15
@feloy feloy requested review from axel7083 and simonrey1 and removed request for a team December 15, 2025 13:15
@feloy feloy force-pushed the chore/use-dashboard-api branch from 5fa3d5c to 9f6fd32 Compare December 15, 2025 13:17
@coderabbitai
Copy link

coderabbitai bot commented Dec 15, 2025

Warning

Rate limit exceeded

@feloy has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 7 minutes and 27 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between db8e487 and 516fd2a.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (6)
  • __mocks__/@podman-desktop/api.js (1 hunks)
  • packages/extension/package.json (1 hunks)
  • packages/extension/src/contexts-extension.ts (3 hunks)
  • packages/extension/src/manager/_manager-module.ts (1 hunks)
  • packages/extension/src/manager/dashboard-states-manager.spec.ts (1 hunks)
  • packages/extension/src/manager/dashboard-states-manager.ts (1 hunks)
📝 Walkthrough

Walkthrough

Introduces a new DashboardStatesManager class that lazily acquires and manages the Kubernetes Dashboard extension API subscriber. The manager is integrated into the extension's dependency injection container and lifecycle. Supporting mocks, tests, and a new development dependency are added to support the feature.

Changes

Cohort / File(s) Change Summary
Mock setup
__mocks__/@podman-desktop/api.js
Adds extensions object to mock export with onDidChange and getExtension mocked functions
Dependencies
packages/extension/package.json
Adds dev dependency "@podman-desktop/kubernetes-dashboard-extension-api" version "0.2.0-next.202512131506-f6c0d06"
Manager implementation
packages/extension/src/manager/dashboard-states-manager.ts
New injectable class implementing Disposable that lazily acquires KubernetesDashboardSubscriber from redhat.kubernetes-dashboard extension via onDidChange listener; provides getSubscriber() getter and proper disposal of all subscriptions
Manager tests
packages/extension/src/manager/dashboard-states-manager.spec.ts
New test suite covering scenarios where dashboard extension is not installed and installed, validating subscriber acquisition, lifecycle management, and proper disposal
Manager registration and integration
packages/extension/src/manager/_manager-module.ts, packages/extension/src/contexts-extension.ts
Registers DashboardStatesManager as singleton in IoC container; initializes manager in ContextsExtension during activation and adds to subscriptions

Sequence Diagram

sequenceDiagram
    participant CE as ContextsExtension
    participant DSM as DashboardStatesManager
    participant EA as extensions API
    participant KDEA as redhat.kubernetes-dashboard<br/>(KubernetesDashboardExtensionApi)
    participant KDS as KubernetesDashboardSubscriber

    CE->>DSM: init()
    DSM->>EA: onDidChange(listener)
    Note over DSM: Listener registered,<br/>awaiting extension availability
    
    rect rgb(200, 220, 255)
    Note over KDEA,KDS: Extension becomes available
    EA->>DSM: onDidChange callback
    DSM->>EA: getExtension('redhat.kubernetes-dashboard')
    EA-->>DSM: extension found
    DSM->>KDEA: extension.exports
    KDEA-->>DSM: KubernetesDashboardSubscriber
    DSM->>DSM: Store subscriber
    Note over DSM: Subscriber now accessible<br/>via getSubscriber()
    end
    
    rect rgb(255, 220, 200)
    Note over CE: Cleanup phase
    CE->>DSM: dispose()
    DSM->>DSM: Iterate subscriptions
    DSM->>EA: onDidChangeDisposable.dispose()
    DSM->>KDS: subscriber?.dispose()
    Note over DSM: All resources cleaned up
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Requires understanding the lazy acquisition pattern and subscription lifecycle
  • New manager implementation with proper Disposable pattern implementation
  • Integration into existing DI container and extension lifecycle
  • Test coverage validates multiple scenarios (extension not installed and installed with async handling)
  • Pay close attention to:
    • Subscription disposal logic in DashboardStatesManager to ensure no memory leaks
    • Mock completeness in test setup for extensions API
    • Correct placement of manager initialization relative to other managers in contexts-extension.ts

Pre-merge checks

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: integrating the Kubernetes Dashboard API into the extension.
Description check ✅ Passed The description is related to the changeset, explaining the purpose of connecting to the Kubernetes Dashboard extension on activation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link

@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: 2

🧹 Nitpick comments (4)
packages/extension/src/manager/_manager-module.ts (1)

24-24: Typo in filename: dashoboard should be dashboard.

The import path contains a typo. Consider renaming the file to dashboard-states-manager.ts for consistency with the test file naming (dashboard-states-manager.spec.ts).

-import { DashboardStatesManager } from '/@/manager/dashoboard-states-manager';
+import { DashboardStatesManager } from '/@/manager/dashboard-states-manager';
packages/extension/src/contexts-extension.ts (1)

33-33: Typo in import path: dashoboard should be dashboard.

Same typo as noted in _manager-module.ts. This will need to be updated once the file is renamed.

packages/extension/src/manager/dashboard-states-manager.spec.ts (1)

20-20: Typo in import path.

Consistent with other files - update after renaming the source file.

packages/extension/src/manager/dashoboard-states-manager.ts (1)

26-27: Typo in filename: dashoboard-states-manager.ts should be dashboard-states-manager.ts.

The filename contains a typo. This should be renamed to match the test file naming convention (dashboard-states-manager.spec.ts).

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ba411e0 and 5fa3d5c.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (6)
  • __mocks__/@podman-desktop/api.js (1 hunks)
  • packages/extension/package.json (1 hunks)
  • packages/extension/src/contexts-extension.ts (3 hunks)
  • packages/extension/src/manager/_manager-module.ts (1 hunks)
  • packages/extension/src/manager/dashboard-states-manager.spec.ts (1 hunks)
  • packages/extension/src/manager/dashoboard-states-manager.ts (1 hunks)
🔇 Additional comments (6)
packages/extension/src/manager/_manager-module.ts (1)

30-30: LGTM!

The singleton binding follows the established pattern for other managers in this module.

__mocks__/@podman-desktop/api.js (1)

87-90: LGTM!

The mock additions for extensions.onDidChange and extensions.getExtension align with the API surface used by DashboardStatesManager and follow the existing mock patterns in this file.

packages/extension/package.json (1)

27-27: Verify the use of "next" version tag.

Using "next" as the version tag means this dependency will receive the latest pre-release version on each install, which could introduce unexpected breaking changes. Consider whether a pinned version would be more appropriate for stability, or confirm this is intentional for tracking the latest API during development.

packages/extension/src/contexts-extension.ts (1)

67-69: LGTM!

The initialization flow correctly retrieves the manager from the IoC container, initializes it, and registers it for disposal via the extension subscriptions.

packages/extension/src/manager/dashboard-states-manager.spec.ts (1)

27-53: LGTM!

The test suite for the "not installed" scenario properly validates that the subscriber is undefined and that disposal cleanup occurs correctly.

packages/extension/src/manager/dashoboard-states-manager.ts (1)

46-55: LGTM!

The dispose() method correctly cleans up all subscriptions, and getSubscriber() provides appropriate read access to the subscriber.

@feloy feloy force-pushed the chore/use-dashboard-api branch from 9f6fd32 to 58145d2 Compare December 15, 2025 13:18
Copy link

@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

♻️ Duplicate comments (1)
packages/extension/src/manager/dashoboard-states-manager.ts (1)

31-44: Missing initial check for already-installed extension.

This issue was already flagged in a previous review. The init() method only registers the onDidChange listener but doesn't check if the extension is already installed. If the dashboard extension is installed before init() is called, the subscriber won't be obtained until another extension change event fires.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5fa3d5c and 58145d2.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (6)
  • __mocks__/@podman-desktop/api.js (1 hunks)
  • packages/extension/package.json (1 hunks)
  • packages/extension/src/contexts-extension.ts (3 hunks)
  • packages/extension/src/manager/_manager-module.ts (1 hunks)
  • packages/extension/src/manager/dashboard-states-manager.spec.ts (1 hunks)
  • packages/extension/src/manager/dashoboard-states-manager.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • packages/extension/package.json
  • packages/extension/src/manager/_manager-module.ts
  • packages/extension/src/manager/dashboard-states-manager.spec.ts
  • packages/extension/src/contexts-extension.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build extension OCI image
🔇 Additional comments (1)
__mocks__/@podman-desktop/api.js (1)

87-90: LGTM!

The extensions mock is correctly structured to support the new DashboardStatesManager tests, consistent with the existing mock patterns in this file.

@feloy feloy force-pushed the chore/use-dashboard-api branch from 58145d2 to 68bb0cf Compare December 15, 2025 13:29
@feloy feloy marked this pull request as draft December 15, 2025 13:29
@feloy feloy force-pushed the chore/use-dashboard-api branch from 68bb0cf to db8e487 Compare December 15, 2025 13:55
@feloy feloy marked this pull request as ready for review December 15, 2025 13:58
@feloy feloy requested a review from benoitf December 15, 2025 13:59
@simonrey1
Copy link
Contributor

I am not sure how to review this PR, might not be the best person to do it sorry.

@feloy
Copy link
Contributor Author

feloy commented Dec 16, 2025

I am not sure how to review this PR, might not be the best person to do it sorry.

If it can help the review, here the complete context of the PR:

Podman Desktop introduced recently the possibility for extensions to provide an API (we started with the podman and docker extensions, for example podman-desktop/podman-desktop#5990).

The Kubernetes Dashboard extension, which is responsible for getting the states of the different contexts, uses this pattern to share these states with other extensions (podman-desktop/extension-kubernetes-dashboard#445). The use of the API is documented in the code added by this PR (https://github.com/podman-desktop/extension-kubernetes-dashboard/blob/37b6d0c6f12b9ef1604683fc1802c604cf7dce4c/packages/api/src/kubernetes-dashboard-extension-api.d.ts#L96-L117)

The Contexts extension needs to get access to the contexts states (reachable, number of pods/deployments), to be able to display this information in the left part of the Context information.

context-state

This first PR tries to access the extension API. Note that the Dashboard extension is not necessary for the Contexts extension to run correctly. If the Dashboard is not installed, the Contexts list won't display the state of the context, but only the data in the kubeconfig file.

Signed-off-by: Philippe Martin <phmartin@redhat.com>
@feloy feloy force-pushed the chore/use-dashboard-api branch from db8e487 to 516fd2a Compare December 16, 2025 09:32
Copy link
Contributor

@simonrey1 simonrey1 left a comment

Choose a reason for hiding this comment

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

The code added here look similar to what is documented there:

https://github.com/podman-desktop/extension-kubernetes-dashboard/blob/main/packages/api/src/kubernetes-dashboard-extension-api.d.ts#L96

Image

The extension seems to still be running OK with this change.

Image Image Image


beforeEach(() => {
vi.mocked(extensions.onDidChange).mockImplementation(f => {
setTimeout(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

question: Why is it necessary to use setTimeout here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without this, const didChangeSubscription = extensions.onDidChange is not executed yet when the callback is executed, and didChangeSubscription.dispose() fails in the callback because didChangeSubscription is undefined

Disposable: {
create: (func) => ({ dispose: func }),
},
extensions: {
Copy link
Contributor

Choose a reason for hiding this comment

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

question: the update of __mocks__/@podman-desktop/api.jsseems to be more an upstream fix than just here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I'll need to use the auto-generated mock used in other extensions. In the meantime, I'm adding the methods used when necessary

@feloy feloy merged commit b340905 into podman-desktop:main Dec 16, 2025
8 checks passed
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