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

Feature flag MultiClusterHub and disable Web Terminal #9340

Merged

Conversation

abhinandan13jan
Copy link
Contributor

@abhinandan13jan abhinandan13jan commented Jun 24, 2021

Addresses

Commit 1 -> https://issues.redhat.com/browse/ODC-5924 // Create feature flag for MultiClusterHub CR with Running status
Commit 2 -> https://issues.redhat.com/browse/ODC-5927 // Disable Web terminal based on MCH feature flag

Description

Assumes structure of SERVER_FLAGS to be SERVER_FLAGS.clusters: string [ ] where presence of more than one entry defines multiCluster to be enabled
Creates a function isMultiClusterEnabled which reads data from SERVER_FLAGS for the presence of multiple clusters and returns accordingly.
Updates Web terminal to read the presence of multiple clusters and render accordindly.

PR Testing

  • Install Web-terminal operator and check for the Cloudshell masthead icon. /terminal route should be available.
    Sometimes it doesn't work in localhost. You may need to manually set useCloudShellAvailable to true for testing purpose.
  • Manually set window.SERVER_FLAGS.clusters = [ 'clustera', 'clusterb'] . This data must exist before render.
  • Reload, CloudShell masthead icon should disappear.
  • /terminal route should be unavailable/redirected.

Screenshot

Screencast from 07-01-2021 03_13_02 PM (1)

Test

Added test-suite for utility useMCHDetection in console-app
Updated test-suite for CloudShellTab

Browser Conformance

Chrome

@openshift-ci openshift-ci bot added the component/core Related to console core functionality label Jun 24, 2021
Comment on lines 9 to 10
const flags = useSelector((state: RootState) => getFlagsObject(state));
const isMCHAvailable = flags[MCH_AVAILABILITY_FLAG];
Copy link
Contributor

Choose a reason for hiding this comment

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

useFlag instead?

const { t } = useTranslation();

if (!terminalAvailable) {
if (!terminalAvailable || (!flagLoading && isMCHAvailable)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!terminalAvailable || (!flagLoading && isMCHAvailable)) {
if (!terminalAvailable || flagLoading || isMCHAvailable) {


if (devWorkspaceFlag === false) return <Redirect to="/" />;
if (devWorkspaceFlag === false || mchFLag === true) return <Redirect to="/" />;
Copy link
Contributor

Choose a reason for hiding this comment

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

mch flag could take some time to be available but we shouldn't be showing the console while console in the meantime. We need to wait for the flag to be ready.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

noted

Comment on lines 199 to 204
{
type: 'FeatureFlag/Custom',
properties: {
detect: detectMCHAvailability,
},
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Use dynamic plugin SDK because static plugins are being migrated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

noted


export const detectMCHAvailability: FeatureDetector = async (dispatch) => {
try {
const multiclusterHubs = await k8sList(MultiClusterHubModel);
Copy link
Member

Choose a reason for hiding this comment

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

We probably want to key on the feature gate we plan to add in https://issues.redhat.com/browse/CONSOLE-2845. We'd only want to disable web terminal if the multicluster is enabled for console, which won't always be the case when ACM is installed.

@christianvogt

} catch (err) {
err?.response?.status === 404
? dispatch(setFlag(MCH_AVAILABILITY_FLAG, false))
: handleError(err, MCH_AVAILABILITY_FLAG, dispatch, detectMCHAvailability);
Copy link
Member

Choose a reason for hiding this comment

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

What is the access control for this resource? What happens for users who don't have authority to list MultiClusterHubs?

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, we would run into an undesired state for users who cannot list MCH

@christianvogt
Copy link
Contributor

cc @TheRealJon @jhadvig
We need to ensure the correct mechanism is used to raise the flag when multi cluster is enabled.

@spadgett
Copy link
Member

We need to ensure the correct mechanism is used to raise the flag when multi cluster is enabled.

The console operator will pass the backend a list of clusters, so the backend will know. Easiest might be to add something to window.SERVER_FLAGS.

@TheRealJon
Copy link
Member

TheRealJon commented Jun 29, 2021

@spadgett Good point about the RBAC issues of using MultiClusterHub as an indication of multicluster capability. That was by my suggestion. I also suggested we look for the TechPreviewNoUpgrade config on the cluster, which will also have the same RBAC problems. I agree that window.SERVER_FLAGS might be the best way to go, in which case this story is probably blocked by https://issues.redhat.com/browse/CONSOLE-2845

@abhinandan13jan
Copy link
Contributor Author

@spadgett @christianvogt @TheRealJon Keeping on hold and will update the implementation post https://issues.redhat.com/browse/CONSOLE-2845

@andrewballantyne
Copy link
Contributor

/hold

@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 Jun 29, 2021
@abhinandan13jan abhinandan13jan force-pushed the feature-flag-acm branch 2 times, most recently from 284ae5b to 76c3a5f Compare July 1, 2021 09:38
@abhinandan13jan
Copy link
Contributor Author

abhinandan13jan commented Jul 1, 2021

Updated to mock implementation using window.SERVER_FLAGS.clusters to unblock the dependant stories. Will update to reading actual data when https://issues.redhat.com/browse/CONSOLE-2845 is merged.

cc: @andrewballantyne @christianvogt @spadgett @TheRealJon

@abhinandan13jan
Copy link
Contributor Author

/retest

@christianvogt
Copy link
Contributor

@abhinandan13jan please ensure your description is up to date with the latest implementation. Including the PR testing section.

@abhinandan13jan
Copy link
Contributor Author

@abhinandan13jan please ensure your description is up to date with the latest implementation. Including the PR testing section.

Srry for the delay. Updated

Comment on lines 1 to 9
const isMultiClusterEnabled = (): boolean => {
let isAvailable = false;
// Mock implementation. needs update
const mchFlagData = window.SERVER_FLAGS.clusters;
if (mchFlagData) {
isAvailable = mchFlagData.length > 1; // to-do: update logic/flag when finalised
}
return isAvailable;
};
Copy link
Member

Choose a reason for hiding this comment

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

nit, this could be simplified with optional chaining:

Suggested change
const isMultiClusterEnabled = (): boolean => {
let isAvailable = false;
// Mock implementation. needs update
const mchFlagData = window.SERVER_FLAGS.clusters;
if (mchFlagData) {
isAvailable = mchFlagData.length > 1; // to-do: update logic/flag when finalised
}
return isAvailable;
};
const isMultiClusterEnabled = (): boolean => window.SERVER_FLAGS.clusters?.length > 1;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@abhinandan13jan
Copy link
Contributor Author

/retest

@TheRealJon
Copy link
Member

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jul 8, 2021
@@ -0,0 +1,4 @@
const isMultiClusterEnabled = (): boolean => window.SERVER_FLAGS.clusters?.length > 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this valid?
What if the hub cluster only has a one managed cluster? Won't this array contain a single item?

Should we be checking for undefined or null instead?

cc @spadgett

Copy link
Member

Choose a reason for hiding this comment

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

The cluster list will always include the hub cluster

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the clarification.

Ok so if there's one cluster it would mean that we are always targeting the hub cluster in which case the check is correct.

While maybe not correct for the web terminal which can work to access the cluster the console runs on. But that's another discussion.

@christianvogt
Copy link
Contributor

/approve

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 9, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: abhinandan13jan, christianvogt, TheRealJon

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 openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 9, 2021
@christianvogt
Copy link
Contributor

@abhinandan13jan @spadgett why the hold? Can this be merged now, it seems like it'll have no impact whether the server flag is present or not.

@andrewballantyne
Copy link
Contributor

I think this can merge now. I added the hold because of the note Abhi made but since https://issues.redhat.com/browse/CONSOLE-2845 is done separately and we are not dependent on it... I think we can unhold.

/unhold

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 9, 2021
@openshift-merge-robot openshift-merge-robot merged commit 6b93a16 into openshift:master Jul 9, 2021
@spadgett spadgett added this to the v4.9 milestone Jul 14, 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. component/core Related to console core functionality 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

6 participants