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

Bug 1996535: Improve detect namespace hook and fix redirect loop and e2e tests #9844

Conversation

jerolimov
Copy link
Member

@jerolimov jerolimov commented Aug 19, 2021

Fixes:
https://bugzilla.redhat.com/show_bug.cgi?id=1996535
https://issues.redhat.com/browse/ODC-6267

Analysis / Root cause:
This is an follow up for PR 9386 and this work is based on @nemesis09 work in PR 9846

  1. The new user preferences introduce a change in the hook which detects the current / active namespace which can result in an endless loop after the user creates a new project.
  2. Cluster settings page crashs in some edge cases when a project is created while the cluster settings page is open. (I could reproduce this always with my crc, but not on a cluster. It depends on the installed operators etc.) The new code is introduced in 4.9 so that we don't need a backport for this.

Solution Description:

  1. Cleanup the namespace hook. Ensure that it doesn't result in an rerendering or redirect loop.

    • if an URL contains a namespace (or the info all namespaces) known at the beginning
      • saved as current namespace
      • the url-based namespace is returned (with loaded: false)
      • set to the redux state
    • if the URL doesn't contain a namespace (or the info all namespaces) the hooks
      • doesn't have a known current namespace and returns loaded: false
      • waits for the preferred and last namespace user settings, and also for flag if project or namespaces are used
      • when all three infos are loaded (remember: the url doesn't contain any namespace info)
        • the preferred or last namespace is set as current namespace
        • the redux state is set and (in setActiveNamespace) the user will be redirected to this namespace
    • whenever the url changes, the hook checks if this new url contains a namespace
      • if that url contains a namespace the current namespace (context value) stores this namespace
      • the redux state is set (which might redirect to this namespace again, but this should not happen since the url contains that namespace already)
      • LAST NAMESPACE is not updated automatically at the moment!!
    • and finally: setNamespace (available as context value)
      • updates the current namespace (context value)
      • the last namespace!! which is only used when there is no preference and the user returns later to an url without namespace.
      • the redux state is set (which will also automatically redirect the user to a new URL)
  2. Fix the crash in frontend/public/module/k8s/cluster-settings.ts with an additional ?. check.

Screen shots / Gifs for design review:
Recording of multiple namespace tests (4 mb)

namespace-tests.mp4

Unit test coverage report:
Tests changed and passes.

Test setup:
Test everything which is aligned to the following features and mix them:

  • Switch namespaces
  • Create a namespace
  • Set preferred namespace
  • Return to an URL with and without namespace in it

Browser conformance:

  • Chrome
  • Firefox
  • Safari
  • Edge

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 19, 2021
@openshift-ci openshift-ci bot added component/core Related to console core functionality component/sdk Related to console-plugin-sdk component/topology Related to topology approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/i18n Indicates issue or PR relates to internationalization or has content that needs to be translated needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Aug 19, 2021
@jerolimov jerolimov force-pushed the user-preferences-extension-test branch from 6fb3135 to 6f396b1 Compare August 21, 2021 18:23
@openshift-ci openshift-ci bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 21, 2021
@jerolimov jerolimov force-pushed the user-preferences-extension-test branch 2 times, most recently from 9f5885b to 43fbe96 Compare August 21, 2021 21:15
@jerolimov
Copy link
Member Author

/uncc abhinandan13jan vojtechszocs

@jerolimov jerolimov force-pushed the user-preferences-extension-test branch 2 times, most recently from 1aaf0d6 to cd3ea84 Compare August 22, 2021 10:41
@jerolimov jerolimov changed the title [WIP] User preferences extension test Improve detect namespace hook and fix redirect loop and e2e tests Aug 22, 2021
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 22, 2021
@jerolimov
Copy link
Member Author

/cc @nemesis09 @christianvogt

@jerolimov jerolimov changed the title Improve detect namespace hook and fix redirect loop and e2e tests Bug 1996535: Improve detect namespace hook and fix redirect loop and e2e tests Aug 23, 2021
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 23, 2021

@jerolimov: An error was encountered querying GitHub for users with public email (gamore@redhat.com) for bug 1996535 on the Bugzilla server at https://bugzilla.redhat.com. No known errors were detected, please see the full error message for details.

Full error message. non-200 OK status code: 403 Forbidden body: "{\n \"documentation_url\": \"https://docs.github.com/en/free-pro-team@latest/rest/overview/resources-in-the-rest-api#secondary-rate-limits\",\n \"message\": \"You have exceeded a secondary rate limit. Please wait a few minutes before you try again.\"\n}\n"

Please contact an administrator to resolve this issue, then request a bug refresh with /bugzilla refresh.

In response to this:

Bug 1996535: Improve detect namespace hook and fix redirect loop and e2e tests

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/test-infra repository.

@jerolimov
Copy link
Member Author

/bugzilla refresh

@openshift-ci openshift-ci bot added the bugzilla/severity-urgent Referenced Bugzilla bug's severity is urgent for the branch this PR is targeting. label Aug 23, 2021
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 23, 2021

@jerolimov: This pull request references Bugzilla bug 1996535, which is valid.

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

No GitHub users were found matching the public email listed for the QA contact in Bugzilla (gamore@redhat.com), skipping review request.

In response to this:

/bugzilla 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 kubernetes/test-infra repository.

@openshift-ci openshift-ci bot added the bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. label Aug 23, 2021
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 23, 2021

@jerolimov: This pull request references Bugzilla bug 1996535, which is valid.

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

No GitHub users were found matching the public email listed for the QA contact in Bugzilla (gamore@redhat.com), skipping review request.

In response to this:

Bug 1996535: Improve detect namespace hook and fix redirect loop and e2e tests

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/test-infra repository.

@@ -64,28 +47,31 @@ export const useValuesForNamespaceContext = () => {
}
// Only run this hook after all resources have loaded.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [resourcesLoaded, useProjects]);
}, [resourcesLoaded]);
Copy link
Member

Choose a reason for hiding this comment

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

won't we need useProjects as well in the dependency list of effect?

Copy link
Member Author

Choose a reason for hiding this comment

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

As long as useProjects is pending the resourcesLoaded is false. It switches to true if everything is loaded (useProjects and 2 user settings). So the useEffect must not be called earlier.

The condition in the first line would ignore this extra call, but I think useProjects is not required here.

Copy link
Member

Choose a reason for hiding this comment

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

got it 👍

const urlNamespace = getNamespace(pathname);
const [lastNamespace, setLastNamespace, lastNamespaceLoaded] = useLastNamespace();
const urlNamespace = useUrlNamespace();
const [currentNamespace, setCurrentNamespace] = React.useState<string>(urlNamespace);
Copy link
Member

Choose a reason for hiding this comment

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

@jerolimov sorry getting confused here between what is activeNamespce vs currentNamespace, is it just a rename?

Copy link
Member Author

@jerolimov jerolimov Aug 23, 2021

Choose a reason for hiding this comment

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

That's right. Changed back to activeNamespace. This makes also more sense with the useActiveNamespace hook to consume this data. Changed the comments also that we set active namespace which means updating this internal state and the redux state.

@jerolimov jerolimov force-pushed the user-preferences-extension-test branch from cd3ea84 to 31fbda3 Compare August 23, 2021 12:11
@invincibleJai
Copy link
Member

/lgtm

verified the changes works as expected

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Aug 23, 2021
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 23, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: invincibleJai, jerolimov

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

The pull request process is described here

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

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 23, 2021

@jerolimov: All pull requests linked via external trackers have merged:

Bugzilla bug 1996535 has been moved to the MODIFIED state.

In response to this:

Bug 1996535: Improve detect namespace hook and fix redirect loop and e2e tests

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/test-infra repository.

@spadgett spadgett added this to the v4.9 milestone Aug 30, 2021
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. bugzilla/severity-urgent Referenced Bugzilla bug's severity is urgent for the branch this PR is targeting. bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. component/core Related to console core functionality component/sdk Related to console-plugin-sdk component/topology Related to topology kind/i18n Indicates issue or PR relates to internationalization or has content that needs to be translated lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants