Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor default namespace resolution #2161

Merged
merged 7 commits into from
Nov 16, 2020
Merged

Refactor default namespace resolution #2161

merged 7 commits into from
Nov 16, 2020

Conversation

andresmgot
Copy link
Contributor

Description of the change

This is the first PR, preparing a following-up to be able to store the last used namespace in the browser storage. In this PR:

  • I have decoupled the authentication flow from the namespace selection. No auth action will set/modify the cluster (or namespace) state.
  • Centralize the logic to decide a default namespace and do it only once, after fetching the namespaces information. This will be stored in the cluster.currentNamespace so components don't need to look at other places for this info.

Benefits

Getting rid of some spaghetti code :)

Possible drawbacks

The application will now wait for the API to return the existing namespaces before selecting one (which includes a minimal delay when loading the app).

Applicable issues

@@ -50,3 +51,18 @@ export default class Namespace {
export const definedNamespaces = {
all: "_all",
};

export function getCurrentNamespace(currenNS: string, availableNS: string[]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor typo, perhaps you mean currentNS here?

@andresmgot
Copy link
Contributor Author

andresmgot commented Nov 12, 2020

I am debugging an issue in the e2e test since it seems that it's clicking in the Catalog link before the default namespace is resolved, causing a 404 :)

[EDIT]

I've made sure we are not rendering the links if the namespace info has not been populated. I had to move the namespace fetching from ContextSelector to its parent Header and took the opportunity to refactor that component and remove the container.

Copy link
Contributor

@absoludity absoludity left a comment

Choose a reason for hiding this comment

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

Great to see all the defaultNamespace removal!

expect(items).not.toExist();
});

it("should skip the links the namespace info is not available", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

links if the namespace info...

authenticated={true}
cluster={""}
currentNamespace={""}
authenticated={false}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused what this test is now testing compared to the following? It looks like they are both testing that the redirect is rendered when unauthed (and that the value of the state should be irrelevant - so only one test required?)

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, the only difference is that the cluster and currentNamespace info is populated, which should be ignored. Updating the test description for being more clear.

exact={true}
path={reposPath}
component={RepoListContainer}
/>
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this a temporary route we'd added during the switch to clustered/namespaced routes? Right, then we've updated reposPath but never removed the now redundant route?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

seems so, there was no reason to keep it as special case.

@@ -50,3 +51,18 @@ export default class Namespace {
export const definedNamespaces = {
all: "_all",
};

export function getCurrentNamespace(currentNS: string, availableNS: string[]) {
if (currentNS) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't understand why we even have currentNS as an arg - why call this function if we already have the currentNS? EDIT: I see - the call-site doesn't need to check, but can just pass in the state. OK.

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, it was to avoid doing the check every time I had to call this function.

const tokenNS = Auth.defaultNamespaceFromToken(Auth.getAuthToken() || "");
if (tokenNS) {
// Return the default namespace in the token
return tokenNS;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should validate that this ns is in availableNS - we had a recent report because in Edukates the token is from a different namespace to which the user has no access.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point.

@antgamdia antgamdia linked an issue Nov 16, 2020 that may be closed by this pull request
@andresmgot andresmgot merged commit c295043 into master Nov 16, 2020
@andresmgot andresmgot deleted the namespaceRefactor branch November 26, 2020 09:55
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.

Kubeapps UI should gracefully handle token expiration
3 participants