-
Notifications
You must be signed in to change notification settings - Fork 32
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 #1073 from upalatucci/ssh-select-load-balancer
[release-4.12] Bug 2172832: CNV-23494 Ssh select load balancer
- Loading branch information
Showing
7 changed files
with
186 additions
and
127 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 was deleted.
Oops, something went wrong.
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
74 changes: 74 additions & 0 deletions
74
src/utils/components/SSHAccess/components/SSHServiceSelect.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,74 @@ | ||
import React, { FC, useMemo } from 'react'; | ||
|
||
import { IoK8sApiCoreV1Service } from '@kubevirt-ui/kubevirt-api/kubernetes'; | ||
import { useKubevirtTranslation } from '@kubevirt-utils/hooks/useKubevirtTranslation'; | ||
import { useK8sModels } from '@openshift-console/dynamic-plugin-sdk'; | ||
import { Select, SelectOption, SelectVariant } from '@patternfly/react-core'; | ||
|
||
import { METALLB_GROUP, SERVICE_TYPES } from '../constants'; | ||
|
||
type SSHServiceSelectProps = { | ||
sshService: IoK8sApiCoreV1Service; | ||
sshServiceLoaded: boolean; | ||
onSSHChange: (serviceType: SERVICE_TYPES) => void; | ||
}; | ||
|
||
const SSHServiceSelect: FC<SSHServiceSelectProps> = ({ | ||
sshService, | ||
sshServiceLoaded, | ||
onSSHChange, | ||
}) => { | ||
const { t } = useKubevirtTranslation(); | ||
const [isOpen, setIsOpen] = React.useState(false); | ||
const [models] = useK8sModels(); | ||
|
||
const sshServiceType = sshService?.spec?.type ?? SERVICE_TYPES.NONE; | ||
|
||
const hasSomeMetalCrd = useMemo( | ||
() => | ||
Object.keys(models).some((modelGroupVersionKind) => | ||
modelGroupVersionKind.startsWith(METALLB_GROUP), | ||
), | ||
[models], | ||
); | ||
|
||
const handleChange = (event: React.ChangeEvent<Element>, newValue: string | undefined) => { | ||
setIsOpen(false); | ||
|
||
if (newValue === sshServiceType) return; | ||
onSSHChange(newValue as SERVICE_TYPES); | ||
}; | ||
|
||
return ( | ||
<Select | ||
menuAppendTo="parent" | ||
isOpen={isOpen} | ||
onToggle={setIsOpen} | ||
onSelect={handleChange} | ||
variant={SelectVariant.single} | ||
selections={sshServiceType} | ||
isDisabled={!sshServiceLoaded} | ||
> | ||
<SelectOption value={SERVICE_TYPES.NONE}>{t('None')}</SelectOption> | ||
<SelectOption | ||
value={SERVICE_TYPES.NODE_PORT} | ||
description={t( | ||
'Opens a specific port on all Nodes in the cluster. If the Node is publicly accessible, any traffic that is sent to this port is forwarded to the Service', | ||
)} | ||
> | ||
{t('SSH over NodePort')} | ||
</SelectOption> | ||
<SelectOption | ||
isDisabled={!hasSomeMetalCrd} | ||
value={SERVICE_TYPES.LOAD_BALANCER} | ||
description={t( | ||
'Assigns an external IP address to the VirtualMachine. This option requires a LoadBalancer Service backend', | ||
)} | ||
> | ||
{t('SSH over LoadBalancer')} | ||
</SelectOption> | ||
</Select> | ||
); | ||
}; | ||
|
||
export default SSHServiceSelect; |
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
Oops, something went wrong.