-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2084 from metalice/CNV-37371-add-change-bootable-…
…volume-namespace CNV-37371: New setting for change bootable volumes default ns
- Loading branch information
Showing
12 changed files
with
295 additions
and
108 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
45 changes: 45 additions & 0 deletions
45
.../components/GeneralSettings/BootableVolumeProjectSection/BootableVolumeProjectSection.tsx
This file contains 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,45 @@ | ||
import React, { FC } from 'react'; | ||
|
||
import { OPENSHIFT_OS_IMAGES_NS } from '@kubevirt-utils/constants/constants'; | ||
import { HyperConverged } from '@kubevirt-utils/hooks/useHyperConvergeConfiguration'; | ||
import { useKubevirtTranslation } from '@kubevirt-utils/hooks/useKubevirtTranslation'; | ||
import { K8sResourceCommon } from '@openshift-console/dynamic-plugin-sdk'; | ||
|
||
import GeneralSettingsProject from '../shared/GeneralSettingsProject'; | ||
|
||
import { | ||
getCurrentBootableVolumesNamespaceFromHCO, | ||
updateHCOBootableVolumesNamespace, | ||
} from './utils/utils'; | ||
|
||
import '../shared/general-settings.scss'; | ||
|
||
type BootableVolumeProjectSectionProps = { | ||
hyperConvergeConfiguration: [hyperConvergeConfig: HyperConverged, loaded: boolean, error: any]; | ||
projectsData: [projects: K8sResourceCommon[], loaded: boolean, error: any]; | ||
}; | ||
|
||
const BootableVolumeProjectSection: FC<BootableVolumeProjectSectionProps> = ({ | ||
hyperConvergeConfiguration, | ||
projectsData, | ||
}) => { | ||
const { t } = useKubevirtTranslation(); | ||
|
||
return ( | ||
<GeneralSettingsProject | ||
description={t( | ||
"Select a project for Red Hat bootable volumes. The default project is 'openshift-virtualization-os-images'", | ||
)} | ||
hcoResourceNamespace={getCurrentBootableVolumesNamespaceFromHCO( | ||
hyperConvergeConfiguration?.[0], | ||
)} | ||
hyperConvergeConfiguration={hyperConvergeConfiguration} | ||
namespace={OPENSHIFT_OS_IMAGES_NS} | ||
onChange={updateHCOBootableVolumesNamespace} | ||
projectsData={projectsData} | ||
toggleText={t('Bootable volumes project')} | ||
/> | ||
); | ||
}; | ||
|
||
export default BootableVolumeProjectSection; |
36 changes: 36 additions & 0 deletions
36
...ingsTab/ClusterTab/components/GeneralSettings/BootableVolumeProjectSection/utils/utils.ts
This file contains 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,36 @@ | ||
import HyperConvergedModel from '@kubevirt-ui/kubevirt-api/console/models/HyperConvergedModel'; | ||
import { OPENSHIFT_OS_IMAGES_NS } from '@kubevirt-utils/constants/constants'; | ||
import { HyperConverged } from '@kubevirt-utils/hooks/useHyperConvergeConfiguration'; | ||
import { k8sPatch } from '@openshift-console/dynamic-plugin-sdk'; | ||
|
||
export const getCurrentBootableVolumesNamespaceFromHCO = (hyperConverged: HyperConverged): string => | ||
hyperConverged?.spec?.commonBootImageNamespace || OPENSHIFT_OS_IMAGES_NS; | ||
|
||
export const updateHCOBootableVolumesNamespace = async ( | ||
hyperConverged: HyperConverged, | ||
newNamespace: null | number | string, | ||
handelError: (value: string) => void, | ||
handleLoading: (value: boolean) => void, | ||
) => { | ||
const currentTemplatesNamespace = getCurrentBootableVolumesNamespaceFromHCO(hyperConverged); | ||
if (newNamespace !== currentTemplatesNamespace) { | ||
handleLoading(true); | ||
try { | ||
await k8sPatch<HyperConverged>({ | ||
data: [ | ||
{ | ||
op: 'replace', | ||
path: `/spec/commonBootImageNamespace`, | ||
value: newNamespace === OPENSHIFT_OS_IMAGES_NS ? null : newNamespace, | ||
}, | ||
], | ||
model: HyperConvergedModel, | ||
resource: hyperConverged, | ||
}); | ||
} catch (error) { | ||
handelError(error?.message || error); | ||
} finally { | ||
handleLoading(false); | ||
} | ||
} | ||
}; |
This file contains 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
120 changes: 16 additions & 104 deletions
120
...ClusterTab/components/GeneralSettings/TemplatesProjectSection/TemplatesProjectSection.tsx
This file contains 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
28 changes: 28 additions & 0 deletions
28
...verview/SettingsTab/ClusterTab/components/GeneralSettings/shared/GeneralSettingsError.tsx
This file contains 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,28 @@ | ||
import React, { FC } from 'react'; | ||
|
||
import { useKubevirtTranslation } from '@kubevirt-utils/hooks/useKubevirtTranslation'; | ||
import { Alert, AlertVariant } from '@patternfly/react-core'; | ||
|
||
type GeneralSettingsErrorProps = { | ||
error: string; | ||
loading: string; | ||
}; | ||
|
||
const GeneralSettingsError: FC<GeneralSettingsErrorProps> = ({ error, loading }) => { | ||
const { t } = useKubevirtTranslation(); | ||
|
||
return ( | ||
(error || loading) && ( | ||
<Alert | ||
className="project-tab__main--error" | ||
isInline | ||
title={t('Error')} | ||
variant={AlertVariant.danger} | ||
> | ||
{error || loading} | ||
</Alert> | ||
) | ||
); | ||
}; | ||
|
||
export default GeneralSettingsError; |
Oops, something went wrong.