Skip to content

Conversation

@alokdangre
Copy link
Contributor

@alokdangre alokdangre commented Jan 23, 2026

Summary

  • Visual support for displaying authenticated users per cluster in TopBar.
  • Implemented individual cluster logout functionality.
  • Added SelfSubjectReview API support for fetching user info.
  • Fixed multi-cluster selection state bug in useSelectedClusters hook.
  • Improved logout UX to persist view on remaining clusters.

Related Issue

Fixes #4082

Changes

  • Updated TopBar.tsx component, clusterApi

Steps to Test

  1. select multiple clusters to view
  2. click on user menu,
  3. click on logout options

Screenshots (if applicable)

Screen.Recording.2026-01-23.145438.mp4

@k8s-ci-robot k8s-ci-robot added the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Jan 23, 2026
@k8s-ci-robot k8s-ci-robot requested a review from ashu8912 January 23, 2026 09:24
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jan 23, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot requested a review from yolossn January 23, 2026 09:24
@k8s-ci-robot
Copy link
Contributor

Welcome @alokdangre!

It looks like this is your first PR to kubernetes-sigs/headlamp 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/headlamp has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jan 23, 2026
@alokdangre alokdangre force-pushed the feature/multi-cluster-user-logout branch from 4fa5f4b to a9ece5c Compare January 23, 2026 09:31
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Jan 23, 2026
@illume illume requested a review from Copilot January 24, 2026 20:18
Copy link
Contributor

@illume illume left a comment

Choose a reason for hiding this comment

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

Thanks for this!

Can you please check the git commit guidelines in the development documentation and update your commit message? You can compare your message to other ones.

The frontend tests are failing in the GitHub check. Can you please try running the tests locally? Also, can you please add a storybook state for this?

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds multi-cluster-aware user identity display and logout behavior in the TopBar, including a hook fix to keep multi-cluster selection derived from the URL in sync.

Changes:

  • Updated TopBar to fetch/display per-cluster authenticated user info and provide per-cluster (and “logout all”) actions.
  • Added SelfSubjectReview-based user info fetching (getClusterUserInfo) in the v1 cluster API layer.
  • Fixed useSelectedClusters to react to pathname changes (not only cluster changes) for correct multi-cluster state updates.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
frontend/src/lib/k8s/index.ts Updates useSelectedClusters to recompute when location.pathname changes.
frontend/src/lib/k8s/api/v1/clusterApi.ts Adds ClusterUserInfo + getClusterUserInfo() using the SelfSubjectReview API with fallback behavior.
frontend/src/components/App/TopBar.tsx Implements multi-cluster user menu UX, per-cluster logout, and queries user info for selected clusters.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@alokdangre alokdangre force-pushed the feature/multi-cluster-user-logout branch from a9ece5c to a61d03c Compare January 25, 2026 11:45
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 25, 2026
@alokdangre alokdangre requested review from Copilot and illume January 25, 2026 11:47
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@alokdangre alokdangre force-pushed the feature/multi-cluster-user-logout branch from a61d03c to 0c38f12 Compare January 25, 2026 11:59
@illume illume requested a review from Copilot January 25, 2026 13:23
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@alokdangre
Copy link
Contributor Author

@illume sorry for that test error, i forgot to take snapshot, i have also added the requested changes

@alokdangre
Copy link
Contributor Author

@illume ptal

@alokdangre alokdangre force-pushed the feature/multi-cluster-user-logout branch from 142c9cd to 160e43d Compare January 30, 2026 16:21
@alokdangre alokdangre requested a review from illume January 30, 2026 16:23
@illume illume requested a review from Copilot January 30, 2026 21:01
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 22 out of 22 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (2)

frontend/src/components/App/TopBar.stories.tsx:138

  • The new SelfSubjectReview call in PureTopBar triggers a POST to /apis/authentication.k8s.io/v1/selfsubjectreviews whenever cluster is set. The TwoCluster story sets cluster: 'ak8s-desktop' but doesn’t register an MSW handler, which will be reported as an unhandled request by the Storybook test harness (see frontend/src/storybook.test.tsx unhandled request assertion). Add an MSW handler for this story (or define a default handler at the story/file level).
export const TwoCluster = PureTemplate.bind({});
TwoCluster.args = {
  appBarActions: [],
  logout: () => {},
  cluster: 'ak8s-desktop',
  clusters: { 'ak8s-desktop': '', 'ak8s-desktop2': '' },
};

frontend/src/setupTests.ts:71

  • This file mocks window.localStorage when it’s missing/non-functional, but beforeEach calls localStorage.clear() (the global identifier). In environments where localStorage isn’t attached to the global scope (even if window.localStorage is defined), this will still throw. To make the setup robust, either set globalThis.localStorage = window.localStorage when mocking, or update the beforeEach to call window.localStorage.clear() (guarded by globalThis.window).
  if (!window.localStorage || typeof window.localStorage.getItem !== 'function') {
    Object.defineProperty(window, 'localStorage', {
      value: {
        getItem: vi.fn(() => null),
        setItem: vi.fn(),
        removeItem: vi.fn(),
        clear: vi.fn(),
        length: 0,
        key: vi.fn(),
      },
      writable: true,
    });
  }
}

beforeEach(() => {
  // Clears the database and adds some testing data.
  // Jest will wait for this promise to resolve before running tests.
  localStorage.clear();
});

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@illume illume left a comment

Choose a reason for hiding this comment

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

🎉 thanks!

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alokdangre, illume

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 30, 2026
Copy link
Contributor

@joaquimrocha joaquimrocha left a comment

Choose a reason for hiding this comment

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

I think this commit needs to be separated in several, even if within the same PR.
@illume was this what you had in mind in the issue that this PR relates too (it's not clear from the title and there's no body)?

I personally wonder why someone who want to log out from a single cluster that they are viewing as part of a group. I understand "Log out from all clusters" and I like that we have this option (we should have a confirmation by the user though), but not sure that having multiple "Log out from XYZ" is a good idea in terms of UX. What would be the use case?
I think a more expected approach is that users who want to log out from a certain cluster would use the context menu in the home table or click the cluster, then log out while viewing it.

@illume
Copy link
Contributor

illume commented Feb 2, 2026

I think this commit needs to be separated in several, even if within the same PR.

@alokdangre yes, breaking this change up into small changes would make it easier to review/test and understand.

Are you able to break it up into separate commits?

Maybe using your list of changes as a rough guide? (or maybe you would have a better idea on how to break it up)

  • Visual support for displaying authenticated users per cluster in TopBar.
  • Implemented individual cluster logout functionality.
  • Added SelfSubjectReview API support for fetching user info.
  • Fixed multi-cluster selection state bug in useSelectedClusters hook.
  • Improved logout UX to persist view on remaining clusters.

I personally wonder why someone who want to log out from a single cluster that they are viewing as part of a group. I understand "Log out from all clusters" and I like that we have this option (we should have a confirmation by the user though), but not sure that having multiple "Log out from XYZ" is a good idea in terms of UX. What would be the use case?
I think a more expected approach is that users who want to log out from a certain cluster would use the context menu in the home table or click the cluster, then log out while viewing it.

There is precedent for wanting to logout with only one account in a few apps when you can sign in multiple times. For example, inside MS products that allow multiple logins it's possible to select which login you want to sign-out with. I use this functionality personally in a few different websites.

But, maybe we need some more feedback on this part.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 2, 2026
@alokdangre alokdangre force-pushed the feature/multi-cluster-user-logout branch from 160e43d to ade1303 Compare February 3, 2026 06:43
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 3, 2026
@alokdangre alokdangre force-pushed the feature/multi-cluster-user-logout branch from 886c0cd to 1c189b6 Compare February 3, 2026 07:54
@illume illume modified the milestones: v0.40.0, v0.41.0 Feb 3, 2026
@alokdangre alokdangre force-pushed the feature/multi-cluster-user-logout branch 2 times, most recently from debdc58 to c1f1725 Compare February 3, 2026 14:26
Implement getClusterUserInfo in clusterApi to fetch user details using SelfSubjectReview. Export the function in apiProxy and add unit tests.

Signed-off-by: alokdangre <[email protected]>
…anges

Update useSelectedClusters to use useLocation and track pathname changes, fixing a bug where cluster selection state could become stale.

Signed-off-by: alokdangre <[email protected]>
Fetch and display authenticated user information per cluster in the user menu.
Fallback to showing the cluster name if no user info is available.
Update TopBar stories to reflect multi-user scenarios.
Update e2e tests to match the new menu item structure.

Signed-off-by: alokdangre <[email protected]>
@ashu8912
Copy link
Member

ashu8912 commented Feb 3, 2026

Hii @alokdangre the CI is failing

@alokdangre alokdangre force-pushed the feature/multi-cluster-user-logout branch from c1f1725 to a806ab8 Compare February 3, 2026 15:03
@alokdangre
Copy link
Contributor Author

Hii @alokdangre the CI is failing

fixed , snapshot added

Add logic to handle logout from specific clusters in a multi-cluster context. Update the URL to remove the logged-out cluster while persisting the view for remaining clusters.

Signed-off-by: alokdangre <[email protected]>
@alokdangre
Copy link
Contributor Author

this fail is unusuall, becuase earlier the this tests where not failing but now it fails and locally all tests passes, im figuring it out

@joaquimrocha
Copy link
Contributor

@illume ,

There is precedent for wanting to logout with only one account in a few apps when you can sign in multiple times. For example, inside MS products that allow multiple logins it's possible to select which login you want to sign-out with. I use this functionality personally in a few different websites.

Sure, but this I would say is the equivalent of logging out of a cluster from the home view, which is showing all clusters there.
In this PR we are saying that users group clusters together (which do not get saved anywhere, it's an intentional and temporary measure), and from this aggregated view they want to log out from a single cluster.

I would err on not providing this option and instead just the "Log out of these grouped clusters" if we need a log out from all while visualizing a group of clusters.

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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. frontend Issues related to the frontend kind/feature Categorizes issue or PR as related to a new feature. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WIP: Topbar: Needs to support multi cluster users

5 participants