Skip to content

Commit

Permalink
Merge pull request #1942 from pcbailey/bug-auto-compute-cpu-limits-di…
Browse files Browse the repository at this point in the history
…sable-defunct

CNV-41385: Remove labels when auto-compute CPU limits is disabled
  • Loading branch information
openshift-merge-bot[bot] committed May 14, 2024
2 parents d034d12 + 6054e46 commit 3940540
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC, useState } from 'react';
import React, { FC, useEffect, useState } from 'react';

import ExpandSectionWithSwitch from '@kubevirt-utils/components/ExpandSectionWithSwitch/ExpandSectionWithSwitch';
import { useModal } from '@kubevirt-utils/components/ModalProvider/ModalProvider';
Expand All @@ -13,7 +13,7 @@ import { useKubevirtTranslation } from '@kubevirt-utils/hooks/useKubevirtTransla
import { Alert, AlertVariant, Button, ButtonVariant } from '@patternfly/react-core';
import { PencilAltIcon } from '@patternfly/react-icons';

import { addLabelsToHyperConvergedCR } from './utils/utils';
import { addLabelsToHyperConvergedCR, removeLabelsFromHyperConvergedCR } from './utils/utils';
import ProjectSelectorModal from './ProjectSelectorModal';

import './AutoComputeCPULimits.scss';
Expand All @@ -37,6 +37,14 @@ const AutoComputeCPULimits: FC<AutoComputeCPULimitsProps> = ({
AUTOCOMPUTE_CPU_LIMITS_PREVIEW_ENABLED,
);

useEffect(() => {
if (!hco) return null;

if (!autoComputeCPUEnabled) {
removeLabelsFromHyperConvergedCR(hco).catch((err) => setError(err.message));
}
}, [autoComputeCPUEnabled, hco]);

const handleSubmit = (idLabels: IDLabel[]) => {
addLabelsToHyperConvergedCR(hco, idLabels).catch((err) => setError(err.message));
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,16 @@ export const addLabelsToHyperConvergedCR = (hcoCR: HyperConverged, idLabels: IDL
resource: hcoCR,
});
};

export const removeLabelsFromHyperConvergedCR = (hcoCR: HyperConverged) => {
return k8sPatch<HyperConverged>({
data: [
{
op: 'remove',
path: '/spec/resourceRequirements/autoCPULimitNamespaceLabelSelector',
},
],
model: HyperConvergedModel,
resource: hcoCR,
});
};

0 comments on commit 3940540

Please sign in to comment.