-
Notifications
You must be signed in to change notification settings - Fork 671
CONSOLE-4945: Add Disk, Network, CPU and VM counts to node overview #16000
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
Open
jeff-phillips-18
wants to merge
1
commit into
openshift:main
Choose a base branch
from
jeff-phillips-18:node-overview-inventory
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
frontend/packages/console-app/src/components/nodes/NodeBareMetalUtils.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import { | ||
| K8sGroupVersionKind, | ||
| K8sResourceKind, | ||
| WatchK8sResult, | ||
| } from '@console/dynamic-plugin-sdk/src'; | ||
| import { useFlag } from '@console/dynamic-plugin-sdk/src/utils/flags'; | ||
| import { useK8sWatchResource } from '@console/dynamic-plugin-sdk/src/utils/k8s/hooks'; | ||
| import { K8sKind } from '@console/internal/module/k8s'; | ||
|
|
||
| export const BAREMETAL_FLAG = 'BAREMETAL'; | ||
|
|
||
| export const BareMetalHostModel: K8sKind = { | ||
| label: 'Bare Metal Host', | ||
| labelPlural: 'Bare Metal Hosts', | ||
| apiVersion: 'v1alpha1', | ||
| apiGroup: 'metal3.io', | ||
| plural: 'baremetalhosts', | ||
| abbr: 'BMH', | ||
| namespaced: true, | ||
| kind: 'BareMetalHost', | ||
| id: 'baremetalhost', | ||
| crd: true, | ||
| }; | ||
|
|
||
| export const BareMetalHostGroupVersionKind: K8sGroupVersionKind = { | ||
| group: 'metal3.io', | ||
| kind: 'BareMetalHost', | ||
| version: 'v1alpha1', | ||
| }; | ||
|
|
||
| export const useIsBareMetalPluginActive = () => useFlag(BAREMETAL_FLAG); | ||
|
|
||
| export const useWatchBareMetalHost = (nodeName: string): WatchK8sResult<K8sResourceKind> => { | ||
| const isBareMetalPluginActive = useIsBareMetalPluginActive(); | ||
|
|
||
| const [bareMetalHosts, bareMetalHostsLoaded, bareMetalHostsLoadError] = useK8sWatchResource< | ||
| K8sResourceKind[] | ||
| >( | ||
| isBareMetalPluginActive | ||
| ? { | ||
| isList: true, | ||
| groupVersionKind: BareMetalHostGroupVersionKind, | ||
| fieldSelector: `metadata.name=${nodeName}`, | ||
| } | ||
| : undefined, | ||
| ); | ||
|
|
||
| return [bareMetalHosts?.[0], bareMetalHostsLoaded, bareMetalHostsLoadError]; | ||
| }; | ||
|
|
||
| export const metricsFromBareMetalHosts = ( | ||
| bareMetalHost?: K8sResourceKind, | ||
| ): { disks?: number; nics?: number; cpus?: number } => ({ | ||
| disks: bareMetalHost?.status?.hardware?.storage?.length, | ||
| nics: bareMetalHost?.status?.hardware?.nics?.length, | ||
| cpus: bareMetalHost?.status?.hardware?.cpu?.count, | ||
| }); | ||
68 changes: 68 additions & 0 deletions
68
frontend/packages/console-app/src/components/nodes/NodeVmUtils.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import { | ||
| K8sGroupVersionKind, | ||
| K8sResourceKind, | ||
| WatchK8sResult, | ||
| } from '@console/dynamic-plugin-sdk/src'; | ||
| import { useFlag } from '@console/dynamic-plugin-sdk/src/utils/flags'; | ||
| import { useK8sWatchResource } from '@console/dynamic-plugin-sdk/src/utils/k8s/hooks'; | ||
| import { K8sKind } from '@console/internal/module/k8s'; | ||
|
|
||
| export const VirtualMachineModel: K8sKind = { | ||
| label: 'VirtualMachine', | ||
| labelPlural: 'VirtualMachines', | ||
| apiVersion: 'v1', | ||
| apiGroup: 'kubevirt.io', | ||
| plural: 'virtualmachines', | ||
| abbr: 'VM', | ||
| namespaced: true, | ||
| kind: 'VirtualMachine', | ||
| id: 'virtualmachine', | ||
| crd: true, | ||
| }; | ||
|
|
||
| // TODO: Remove VMI retrieval and VMs count column if/when the plugin is able to add the VMs count column | ||
| export const VirtualMachineInstanceGroupVersionKind: K8sGroupVersionKind = { | ||
| group: 'kubevirt.io', | ||
| kind: 'VirtualMachineInstance', | ||
| version: 'v1', | ||
| }; | ||
|
|
||
| export const useIsKubevirtPluginActive = () => { | ||
| const kubevirtFeature = useFlag('KUBEVIRT_DYNAMIC'); | ||
|
|
||
| return ( | ||
| Array.isArray(window.SERVER_FLAGS?.consolePlugins) && | ||
| window.SERVER_FLAGS.consolePlugins.includes('kubevirt-plugin') && | ||
| kubevirtFeature | ||
| ); | ||
| }; | ||
|
|
||
| // Return all matching VMIs, if no nodeName is given, return all VMIs. | ||
| export const filterVirtualMachineInstancesByNode = (vmis: K8sResourceKind[], nodeName?: string) => | ||
| vmis?.filter((vm) => !nodeName || vm.status?.nodeName === nodeName) ?? []; | ||
|
|
||
| // Watch VMIs and return all matching VMIs by nodeName if given, if not, return all VMIs. | ||
| export const useWatchVirtualMachineInstances = ( | ||
| nodeName?: string, | ||
| ): WatchK8sResult<K8sResourceKind[]> => { | ||
| const isKubevirtPluginActive = useIsKubevirtPluginActive(); | ||
|
|
||
| const [ | ||
| virtualMachineInstances, | ||
| virtualMachineInstancesLoaded, | ||
| virtualMachineInstancesLoadError, | ||
| ] = useK8sWatchResource<K8sResourceKind[]>( | ||
| isKubevirtPluginActive | ||
| ? { | ||
| isList: true, | ||
| groupVersionKind: VirtualMachineInstanceGroupVersionKind, | ||
| } | ||
| : undefined, | ||
| ); | ||
|
|
||
| return [ | ||
| filterVirtualMachineInstancesByNode(virtualMachineInstances, nodeName), | ||
| virtualMachineInstancesLoaded, | ||
| virtualMachineInstancesLoadError, | ||
| ]; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
...tend/packages/console-app/src/components/nodes/node-dashboard/BareMetalInventoryItems.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| import type { FC } from 'react'; | ||
| import { useContext } from 'react'; | ||
| import { | ||
| DescriptionListDescription, | ||
| DescriptionListGroup, | ||
| DescriptionListTerm, | ||
| } from '@patternfly/react-core'; | ||
| import { useTranslation } from 'react-i18next'; | ||
| import { Link } from 'react-router-dom-v5-compat'; | ||
| import { | ||
| BareMetalHostModel, | ||
| metricsFromBareMetalHosts, | ||
| useIsBareMetalPluginActive, | ||
| useWatchBareMetalHost, | ||
| } from '@console/app/src/components/nodes/NodeBareMetalUtils'; | ||
| import { resourcePathFromModel } from '@console/internal/components/utils/resource-link'; | ||
| import { DASH } from '@console/shared/src'; | ||
| import { InventoryItem } from '@console/shared/src/components/dashboard/inventory-card/InventoryItem'; | ||
| import { NodeDashboardContext } from './NodeDashboardContext'; | ||
|
|
||
| type BareMetalInventoryItemsProps = { | ||
| loaded: boolean; | ||
| loadError?: unknown; | ||
| title: string; | ||
| itemsTitle?: string; | ||
| count: number | undefined; | ||
| linkTo?: string; | ||
| }; | ||
|
|
||
| const BareMetalInventoryItem: FC<BareMetalInventoryItemsProps> = ({ | ||
| loaded, | ||
| loadError, | ||
| title, | ||
| itemsTitle, | ||
| count, | ||
| linkTo, | ||
| }) => { | ||
| return ( | ||
| <DescriptionListGroup> | ||
| <DescriptionListTerm>{title}</DescriptionListTerm> | ||
| <DescriptionListDescription> | ||
| {!loaded ? ( | ||
| <InventoryItem title={title} isLoading count={0} /> | ||
| ) : loadError || count === undefined ? ( | ||
| DASH | ||
| ) : linkTo ? ( | ||
| <Link to={linkTo}> | ||
| <InventoryItem title={itemsTitle ?? title} isLoading={false} count={count} /> | ||
| </Link> | ||
| ) : ( | ||
| <InventoryItem title={itemsTitle ?? title} isLoading={false} count={count} /> | ||
| )} | ||
| </DescriptionListDescription> | ||
| </DescriptionListGroup> | ||
| ); | ||
| }; | ||
|
|
||
| const BareMetalInventoryItems: FC = () => { | ||
| const { obj } = useContext(NodeDashboardContext); | ||
| const { t } = useTranslation(); | ||
|
|
||
| const showBareMetal = useIsBareMetalPluginActive(); | ||
|
|
||
| const [bareMetalHost, bareMetalHostLoaded, bareMetalHostLoadError] = useWatchBareMetalHost( | ||
| obj.metadata.name, | ||
| ); | ||
|
|
||
| if (!showBareMetal) { | ||
| return null; | ||
| } | ||
|
|
||
| const { disks, nics, cpus } = metricsFromBareMetalHosts(bareMetalHost); | ||
|
|
||
| return ( | ||
| <> | ||
| <BareMetalInventoryItem | ||
| loaded={bareMetalHostLoaded} | ||
| loadError={bareMetalHostLoadError || !bareMetalHost} | ||
| title={t('console-app~Disk')} | ||
| count={disks} | ||
| linkTo={ | ||
| bareMetalHost | ||
| ? `${resourcePathFromModel( | ||
| BareMetalHostModel, | ||
| bareMetalHost.metadata.name, | ||
| bareMetalHost.metadata.namespace, | ||
| )}/disks` | ||
| : undefined | ||
| } | ||
| /> | ||
| <BareMetalInventoryItem | ||
| loaded={bareMetalHostLoaded} | ||
| loadError={bareMetalHostLoadError || !bareMetalHost} | ||
| title={t('console-app~Network')} | ||
| itemsTitle={t('console-app~NIC')} | ||
| count={nics} | ||
| linkTo={ | ||
| bareMetalHost | ||
| ? `${resourcePathFromModel( | ||
| BareMetalHostModel, | ||
| bareMetalHost.metadata.name, | ||
| bareMetalHost.metadata.namespace, | ||
| )}/nics` | ||
| : undefined | ||
| } | ||
| /> | ||
| <BareMetalInventoryItem | ||
| loaded={bareMetalHostLoaded} | ||
| loadError={bareMetalHostLoadError || !bareMetalHost} | ||
| title={t('console-app~CPU')} | ||
| count={cpus} | ||
| /> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| export default BareMetalInventoryItems; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: openshift/console
Length of output: 43
🏁 Script executed:
Repository: openshift/console
Length of output: 88
🏁 Script executed:
Repository: openshift/console
Length of output: 88
🏁 Script executed:
# Look for baremetal-related configuration or documentation fd -e md -e ts -e tsx baremetal frontend/packages --type fRepository: openshift/console
Length of output: 1873
🏁 Script executed:
Repository: openshift/console
Length of output: 2473
🏁 Script executed:
# Check the complete NodeBareMetalUtils.ts file cat -n frontend/packages/console-app/src/components/nodes/NodeBareMetalUtils.tsRepository: openshift/console
Length of output: 2213
🏁 Script executed:
Repository: openshift/console
Length of output: 9649
🏁 Script executed:
Repository: openshift/console
Length of output: 13262
🏁 Script executed:
Repository: openshift/console
Length of output: 2958
🏁 Script executed:
Repository: openshift/console
Length of output: 43
🏁 Script executed:
Repository: openshift/console
Length of output: 191
🏁 Script executed:
Repository: openshift/console
Length of output: 164
🏁 Script executed:
Repository: openshift/console
Length of output: 43
🏁 Script executed:
Repository: openshift/console
Length of output: 7969
🏁 Script executed:
Repository: openshift/console
Length of output: 43
🏁 Script executed:
Repository: openshift/console
Length of output: 285
🏁 Script executed:
# Check the watch hook type definitions to understand namespace behavior cat -n frontend/packages/console-dynamic-plugin-sdk/src/utils/k8s/hooks/k8s-watch-types.tsRepository: openshift/console
Length of output: 1076
🏁 Script executed:
# Look at the watcher implementation head -100 frontend/packages/console-dynamic-plugin-sdk/src/utils/k8s/hooks/k8s-watcher.tsRepository: openshift/console
Length of output: 3090
Add
namespaceparameter touseWatchBareMetalHost—BMH is a namespaced resource but the hook watches cluster-wide.Line 33: The hook signature omits the namespace parameter, and line 40–44 doesn't scope the watch to any namespace. Since
BareMetalHostModelis markednamespaced: true(line 19), the resource watch should explicitly includenamespacein the resource config; otherwise,useK8sWatchResourcequeries all namespaces and relies only onfieldSelector: metadata.nameto filter results. This can fail if multiple BMH resources with identical names exist across namespaces.Update the hook to accept and pass the namespace:
Update the call site in
BareMetalInventoryItems.tsxline 64 to pass the namespace from the node context.🤖 Prompt for AI Agents