Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions frontend/public/components/resource-quota.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { useMemo, Suspense } from 'react';
import * as _ from 'lodash';
import { useParams } from 'react-router-dom-v5-compat';
import { useParams, Link } from 'react-router-dom-v5-compat';
import { Table as PfTable, Thead, Tbody, Tr, Th, Td } from '@patternfly/react-table';
import { OutlinedCircleIcon } from '@patternfly/react-icons/dist/esm/icons/outlined-circle-icon';
import { ResourcesAlmostEmptyIcon } from '@patternfly/react-icons/dist/esm/icons/resources-almost-empty-icon';
import { ResourcesAlmostFullIcon } from '@patternfly/react-icons/dist/esm/icons/resources-almost-full-icon';
import { ResourcesFullIcon } from '@patternfly/react-icons/dist/esm/icons/resources-full-icon';
import { UnknownIcon } from '@patternfly/react-icons/dist/esm/icons/unknown-icon';

import { useTranslation } from 'react-i18next';
import { Trans, useTranslation } from 'react-i18next';
import AppliedClusterResourceQuotaCharts from '@console/app/src/components/resource-quota/AppliedClusterResourceQuotaCharts';
import ResourceQuotaCharts from '@console/app/src/components/resource-quota/ResourceQuotaCharts';
import ClusterResourceQuotaCharts from '@console/app/src/components/resource-quota/ClusterResourceQuotaCharts';
import PaneBody from '@console/shared/src/components/layout/PaneBody';

import { FLAGS } from '@console/shared/src/constants/common';
import { useFlag } from '@console/shared/src/hooks/flag';
import { YellowExclamationTriangleIcon } from '@console/shared/src/components/status/icons';
import { DASH } from '@console/shared/src/constants/ui';
import { DetailsPage, MultiListPage } from './factory';
Expand Down Expand Up @@ -696,6 +697,13 @@ export const flatten = (resources) => _.flatMap(resources, (resource) => _.compa
export const ResourceQuotasPage = connectToFlags(FLAGS.OPENSHIFT)(
({ namespace, flags, mock, showTitle }) => {
const { t } = useTranslation();
const kubevirtFeature = useFlag('KUBEVIRT_DYNAMIC');
const isKubevirtPluginActive =
Array.isArray(window.SERVER_FLAGS.consolePlugins) &&
window.SERVER_FLAGS.consolePlugins.includes('kubevirt-plugin') &&
kubevirtFeature;
Comment on lines +700 to +704
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Guard global flag access to prevent pre-render crashes.

Line 702 dereferences window.SERVER_FLAGS.consolePlugins before validating window.SERVER_FLAGS. If that global is missing, this page can throw during render.

💡 Proposed fix
     const kubevirtFeature = useFlag('KUBEVIRT_DYNAMIC');
-    const isKubevirtPluginActive =
-      Array.isArray(window.SERVER_FLAGS.consolePlugins) &&
-      window.SERVER_FLAGS.consolePlugins.includes('kubevirt-plugin') &&
+    const consolePlugins = window.SERVER_FLAGS?.consolePlugins;
+    const isKubevirtPluginActive =
+      Array.isArray(consolePlugins) &&
+      consolePlugins.includes('kubevirt-plugin') &&
       kubevirtFeature;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/public/components/resource-quota.jsx` around lines 700 - 704, The
code reads window.SERVER_FLAGS.consolePlugins without ensuring
window.SERVER_FLAGS exists, causing render-time crashes; update the
isKubevirtPluginActive computation (referencing useFlag, kubevirtFeature, and
isKubevirtPluginActive) to first guard that window.SERVER_FLAGS is defined and
that consolePlugins is an array (e.g. check window.SERVER_FLAGS &&
Array.isArray(window.SERVER_FLAGS.consolePlugins) or use optional chaining)
before calling .includes('kubevirt-plugin') and keep the kubevirtFeature check
intact.

const quotasFeature = useFlag('KUBEVIRT_QUOTAS');

const resources = [{ kind: 'ResourceQuota', namespaced: true }];
let rowFilters = null;

Expand Down Expand Up @@ -757,6 +765,31 @@ export const ResourceQuotasPage = connectToFlags(FLAGS.OPENSHIFT)(
namespace={namespace}
flatten={flatten}
title={t(ResourceQuotaModel.labelPluralKey)}
helpText={
<div className="pf-v6-u-text-color-subtle pf-v6-u-mt-sm">
{t(
'public~Manage project capacity by limiting the number of objects and total compute resources available.',
)}
{isKubevirtPluginActive && (
<Trans t={t} ns="public">
{' '}
Use standard quotas for general container workloads. If you are running OpenShift
Virtualization, it is recommended to use{' '}
<Link
to={
quotasFeature
? '/k8s/all-namespaces/quotas'
: '/k8s/all-namespaces/virtualization-overview/settings/cluster'
}
>
Application-Aware Quota
</Link>{' '}
to handle VM infrastructure overhead and live migrations without service
interruption.
</Trans>
)}
</div>
}
rowFilters={rowFilters}
mock={mock}
showTitle={showTitle}
Expand Down
2 changes: 2 additions & 0 deletions frontend/public/locales/en/public.json
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,8 @@
"Cluster-wide {{resource}}": "Cluster-wide {{resource}}",
"Namespace {{resource}}": "Namespace {{resource}}",
"Create ResourceQuota": "Create ResourceQuota",
"Manage project capacity by limiting the number of objects and total compute resources available.": "Manage project capacity by limiting the number of objects and total compute resources available.",
" Use standard quotas for general container workloads. If you are running OpenShift Virtualization, it is recommended to use <3>Application-Aware Quota</3> to handle VM infrastructure overhead and live migrations without service interruption.": " Use standard quotas for general container workloads. If you are running OpenShift Virtualization, it is recommended to use <3>Application-Aware Quota</3> to handle VM infrastructure overhead and live migrations without service interruption.",
"Select all filters": "Select all filters",
"{{selectedCount}} of {{itemCount}}": "{{selectedCount}} of {{itemCount}}",
"Item_one": "Item",
Expand Down