Skip to content

Commit

Permalink
Merge pull request #1559 from hstastna/KSM_to_Cluster_settings
Browse files Browse the repository at this point in the history
CNV-33063: Add KSM to Cluster settings
  • Loading branch information
openshift-ci[bot] authored Oct 18, 2023
2 parents 0767d1d + bcda5a1 commit ea52dde
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 6 deletions.
3 changes: 3 additions & 0 deletions locales/en/plugin__kubevirt-plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,10 @@
"IP addresses": "IP addresses",
"It may take several minutes until the clone is done and the VirtualMachine is ready.": "It may take several minutes until the clone is done and the VirtualMachine is ready.",
"It seems that your browser does not trust the certificate of the upload proxy. {uploadProxyURL && (\n <>\n Please{' '}\n <a href={`https://${uploadProxyURL}`} rel=\"noopener noreferrer\" target=\"_blank\">\n approve this certificate\n </a>{' '}\n and try again\n </>\n )}": "It seems that your browser does not trust the certificate of the upload proxy. {uploadProxyURL && (\n <>\n Please{' '}\n <a href={`https://${uploadProxyURL}`} rel=\"noopener noreferrer\" target=\"_blank\">\n approve this certificate\n </a>{' '}\n and try again\n </>\n )}",
"Kernel Samepage Merging (KSM)": "Kernel Samepage Merging (KSM)",
"key": "key",
"Key": "Key",
"KSM is a memory-saving deduplication feature designed to fit more VirtualMachines into physical memory by sharing the data common between them. It is specifically effective for similar VirtualMachines. KSM should only be used with trusted workloads. Turning this feature on enables it for all nodes in the cluster.": "KSM is a memory-saving deduplication feature designed to fit more VirtualMachines into physical memory by sharing the data common between them. It is specifically effective for similar VirtualMachines. KSM should only be used with trusted workloads. Turning this feature on enables it for all nodes in the cluster.",
"Kubernetes NMState Operator": "Kubernetes NMState Operator",
"KV data transfer rate": "KV data transfer rate",
"Label selectors let you select Nodes based on the value of one or more labels.": "Label selectors let you select Nodes based on the value of one or more labels.",
Expand Down Expand Up @@ -880,6 +882,7 @@
"Reset": "Reset",
"Resource": "Resource",
"Resource already selected": "Resource already selected",
"Resource management": "Resource management",
"Resource name": "Resource name",
"Resources": "Resources",
"Resources are being removed, please wait.": "Resources are being removed, please wait.",
Expand Down
6 changes: 3 additions & 3 deletions src/utils/components/NodeSelectorModal/NodeSelectorModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from 'react';
import React, { FC, useMemo } from 'react';
import produce from 'immer';

import { NodeModel } from '@kubevirt-ui/kubevirt-api/console';
Expand Down Expand Up @@ -29,7 +29,7 @@ type NodeSelectorModalProps = {
vmi?: V1VirtualMachineInstance;
};

const NodeSelectorModal: React.FC<NodeSelectorModalProps> = ({
const NodeSelectorModal: FC<NodeSelectorModalProps> = ({
isOpen,
nodes,
nodesLoaded,
Expand All @@ -50,7 +50,7 @@ const NodeSelectorModal: React.FC<NodeSelectorModalProps> = ({

const onSelectorLabelAdd = () => onLabelAdd({ id: null, key: '', value: '' });

const updatedVirtualMachine = React.useMemo(() => {
const updatedVirtualMachine = useMemo(() => {
const updatedVM = produce<V1VirtualMachine>(vm, (vmDraft: V1VirtualMachine) => {
ensurePath(vmDraft, ['spec.template.template.spec.nodeSelector']);
if (!vmDraft.spec.template.spec.nodeSelector) {
Expand Down
1 change: 1 addition & 0 deletions src/utils/hooks/useHyperConvergeConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { K8sResourceCommon, useK8sWatchResource } from '@openshift-console/dynam

export type HyperConverged = K8sResourceCommon & {
spec: {
configuration?: { ksmConfiguration: { nodeLabelSelector?: Record<string, never> } };
evictionStrategy?: string;
liveMigrationConfig: V1MigrationConfiguration;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import EnableLoadBalancerSection from './components/EnableLoadBalancerSection/En
import EnablePreviewFeaturesSection from './components/EnablePreviewFeaturesSection/EnablePreviewFeaturesSection';
import GeneralInformation from './components/GeneralInformation/GeneralInformation';
import LiveMigrationSection from './components/LiveMigrationSection/LiveMigrationSection';
import ResourceManagementSection from './components/ResourceManagementSection/ResourceManagementSection';
import TemplatesProjectSection from './components/TemplatesProjectSection/TemplatesProjectSection';

const ClusterTab: FC = () => {
Expand All @@ -22,6 +23,8 @@ const ClusterTab: FC = () => {
<EnableLoadBalancerSection />
<Divider className="section-divider" />
<TemplatesProjectSection />
<Divider className="section-divider" />
<ResourceManagementSection />
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React, { FC } from 'react';

import { useKubevirtTranslation } from '@kubevirt-utils/hooks/useKubevirtTranslation';

import ExpandSection from '../../../ExpandSection/ExpandSection';

import KernelSamepageMerging from './components/KernelSamepageMerging/KernelSamepageMerging';

const ResourceManagementSection: FC = () => {
const { t } = useKubevirtTranslation();

return (
<ExpandSection toggleText={t('Resource management')}>
<KernelSamepageMerging />
</ExpandSection>
);
};

export default ResourceManagementSection;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.KernelSamepageMerging {
&__HelpTextIcon {
.pf-c-popover__content {
width: 465px;
}
}

&__Alert {
margin-top: var(--pf-global--spacer--md);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import React, { FC, useState } from 'react';

import HyperConvergedModel from '@kubevirt-ui/kubevirt-api/console/models/HyperConvergedModel';
import HelpTextIcon from '@kubevirt-utils/components/HelpTextIcon/HelpTextIcon';
import useHyperConvergeConfiguration, {
HyperConverged,
} from '@kubevirt-utils/hooks/useHyperConvergeConfiguration';
import { useKubevirtTranslation } from '@kubevirt-utils/hooks/useKubevirtTranslation';
import { isEmpty } from '@kubevirt-utils/utils/utils';
import { k8sPatch } from '@openshift-console/dynamic-plugin-sdk';
import {
Alert,
AlertVariant,
PopoverPosition,
Split,
SplitItem,
Switch,
} from '@patternfly/react-core';

import './KernelSamepageMerging.scss';

const KernelSamepageMerging: FC = () => {
const { t } = useKubevirtTranslation();
const [hyperConverge, hyperLoaded, hyperLoadingError] = useHyperConvergeConfiguration();
const ksmConfiguration = hyperConverge?.spec?.configuration?.ksmConfiguration;
const [isEnabled, setIsEnabled] = useState(
!!(ksmConfiguration && isEmpty(ksmConfiguration?.nodeLabelSelector)), // Empty nodeLabelSelector will enable KSM on every node.
);
const [error, setError] = useState(null);

const onKSMchange = (value: boolean) => {
k8sPatch<HyperConverged>({
data: [
{
op: 'replace',
path: `/spec/configuration/ksmConfiguration/nodeLabelSelector`,
value: value ? {} : null,
},
],
model: HyperConvergedModel,
resource: hyperConverge,
})
.then(() => setIsEnabled(value))
.catch((err) => setError(err.message));
};

return (
<>
<Split>
<SplitItem isFilled>
{t('Kernel Samepage Merging (KSM)')}{' '}
<HelpTextIcon
bodyContent={t(
'KSM is a memory-saving deduplication feature designed to fit more VirtualMachines into physical memory by sharing the data common between them. It is specifically effective for similar VirtualMachines. KSM should only be used with trusted workloads. Turning this feature on enables it for all nodes in the cluster.',
)}
className="KernelSamepageMerging__HelpTextIcon"
helpIconClassName="KernelSamepageMerging__HelpIcon"
position={PopoverPosition.bottom}
/>
</SplitItem>
{hyperLoaded && (
<SplitItem>
<Switch id="kernel-samepage-merging" isChecked={isEnabled} onChange={onKSMchange} />
</SplitItem>
)}
</Split>
{(error || hyperLoadingError) && (
<Alert
className="KernelSamepageMerging__Alert"
isInline
title={t('An error occurred')}
variant={AlertVariant.danger}
>
{error || hyperLoadingError}
</Alert>
)}
</>
);
};

export default KernelSamepageMerging;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { FC } from 'react';
import { TemplateSchedulingGridProps } from 'src/views/templates/details/tabs/scheduling/components/TemplateSchedulingLeftGrid';
import { getNodeSelector } from 'src/views/templates/utils/selectors';

Expand All @@ -7,6 +7,7 @@ import { useKubevirtTranslation } from '@kubevirt-utils/hooks/useKubevirtTransla
import { isEmpty } from '@kubevirt-utils/utils/utils';
import {
Button,
ButtonVariant,
DescriptionListDescription,
DescriptionListGroup,
DescriptionListTerm,
Expand All @@ -17,7 +18,7 @@ import { PencilAltIcon } from '@patternfly/react-icons';

import NodeSelectorModal from './NodeSelectorModal';

const NodeSelector: React.FC<TemplateSchedulingGridProps> = ({ editable, onSubmit, template }) => {
const NodeSelector: FC<TemplateSchedulingGridProps> = ({ editable, onSubmit, template }) => {
const { t } = useKubevirtTranslation();
const { createModal } = useModal();
const nodeSelector = getNodeSelector(template);
Expand Down Expand Up @@ -51,7 +52,7 @@ const NodeSelector: React.FC<TemplateSchedulingGridProps> = ({ editable, onSubmi
isInline
onClick={onEditClick}
type="button"
variant="link"
variant={ButtonVariant.link}
>
{nodeSelectorLabels}
<PencilAltIcon className="co-icon-space-l pf-c-button-icon--plain" />
Expand Down

0 comments on commit ea52dde

Please sign in to comment.