Skip to content

Commit

Permalink
Adds support for Noobaa external postgres
Browse files Browse the repository at this point in the history
Signed-off-by: vbadrina <[email protected]>
  • Loading branch information
vbnrh committed Nov 28, 2023
1 parent 5646fc8 commit 81a7598
Show file tree
Hide file tree
Showing 12 changed files with 757 additions and 33 deletions.
15 changes: 14 additions & 1 deletion locales/en/plugin__odf-console.json
Original file line number Diff line number Diff line change
Expand Up @@ -628,10 +628,24 @@
"Data Foundation will use a StorageClass provided by the Local Storage Operator (LSO) on top of your attached drives. This option is available on any platform with devices attached to nodes.": "Data Foundation will use a StorageClass provided by the Local Storage Operator (LSO) on top of your attached drives. This option is available on any platform with devices attached to nodes.",
"Connect an external storage platform": "Connect an external storage platform",
"Data Foundation will create a dedicated StorageClass.": "Data Foundation will create a dedicated StorageClass.",
"Use external PostgreSQL": "Use external PostgreSQL",
"Allow Noobaa to connect to an external postgres server": "Allow Noobaa to connect to an external postgres server",
"NFS is currently not supported for external storage type. To proceed with an external storage type, disable this option.": "NFS is currently not supported for external storage type. To proceed with an external storage type, disable this option.",
"NFS is currently not supported for external storage type.": "NFS is currently not supported for external storage type.",
"Enable network file system (NFS)": "Enable network file system (NFS)",
"Allow NFS to use low resources by default.": "Allow NFS to use low resources by default.",
"Show password": "Show password",
"Server": "Server",
"Port": "Port",
"Database name": "Database name",
"Enable TLS/SSL": "Enable TLS/SSL",
"Enable this for encrytion on flight with the Postgres server": "Enable this for encrytion on flight with the Postgres server",
"Allow self-signed certificates": "Allow self-signed certificates",
"Adding this option will allow the postgres server to use a self-signed certificates.": "Adding this option will allow the postgres server to use a self-signed certificates.",
"Enable client-side certificates": "Enable client-side certificates",
"Select this option to upload and use your client side certificates": "Select this option to upload and use your client side certificates",
"Accepted file types: .pem, .crt, .key": "Accepted file types: .pem, .crt, .key",
"Files should be named private and public followed by compatible extensions": "Files should be named private and public followed by compatible extensions",
"Deploys MultiCloud Object Gateway without block and file services.": "Deploys MultiCloud Object Gateway without block and file services.",
"Deploys Data Foundation with block, shared fileSystem and object services.": "Deploys Data Foundation with block, shared fileSystem and object services.",
"Deployment type": "Deployment type",
Expand Down Expand Up @@ -795,7 +809,6 @@
"Please enter a URL": "Please enter a URL",
"Please enter a valid port": "Please enter a valid port",
"Address": "Address",
"Port": "Port",
"Client certificate": "Client certificate",
"CA certificate": "CA certificate",
"Client private key": "Client private key",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@
.odf-backing-store__dropdown--margin-top {
margin-top: var(--pf-global--spacer--sm);
}

.odf-backing-store__ssl {
padding-left: var(--pf-global--spacer--xl);
padding-bottom: var(--pf-global--spacer--xl); ;
}


Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ import {
Radio,
Alert,
AlertVariant,
Checkbox,
} from '@patternfly/react-core';
import { ErrorHandler } from '../../error-handler';
import { WizardState, WizardDispatch } from '../../reducer';
import { EnableNFS } from './enable-nfs';
import { PostgresConnectionDetails } from './noobaa-external-postgres/postgres-connection-details';
import { SelectDeployment } from './select-deployment';
import { SetCephRBDStorageClassDefault } from './set-rbd-sc-default';
import './backing-storage-step.scss';
Expand Down Expand Up @@ -189,6 +191,8 @@ export const BackingStorage: React.FC<BackingStorageProps> = ({
isRBDStorageClassDefault,
externalStorage,
deployment,
externalPostgres,
useExternalPostgres,
} = state;

const { t } = useCustomTranslation();
Expand Down Expand Up @@ -364,6 +368,34 @@ export const BackingStorage: React.FC<BackingStorageProps> = ({
/>
</>
)}
<Checkbox
id="use-external-postgress"
label={t('Use external PostgreSQL')}
description={t(
'Allow Noobaa to connect to an external postgres server'
)}
isChecked={useExternalPostgres}
onChange={() =>
dispatch({
type: 'backingStorage/useExternalPostgres',
payload: !useExternalPostgres,
})
}
className="odf-backing-store__radio--margin-bottom"
/>
{useExternalPostgres && (
<PostgresConnectionDetails
dispatch={dispatch}
tlsEnabled={externalPostgres.tls.enabled}
allowSelfSignedCerts={externalPostgres.tls.allowSelfSignedCerts}
username={externalPostgres.username}
password={externalPostgres.password}
serverName={externalPostgres.serverName}
databaseName={externalPostgres.databaseName}
port={externalPostgres.port}
enableClientSideCerts={externalPostgres.tls.enableClientSideCerts}
/>
)}
</Form>
</ErrorHandler>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
import * as React from 'react';
import { UploadFile } from '@odf/shared/file-handling';
import { useCustomTranslation } from '@odf/shared/useCustomTranslationHook';
import {
FormGroup,
Checkbox,
TextInput,
Form,
GridItem,
Grid,
Text,
TextVariants,
Stack,
Tooltip,
Button,
InputGroup,
} from '@patternfly/react-core';
import { EyeIcon, EyeSlashIcon } from '@patternfly/react-icons';
import { WizardDispatch, WizardState } from '../../../reducer';
import '../backing-storage-step.scss';

export const PostgresConnectionDetails: React.FC<PostgresConnectionDetails> = ({
dispatch,
username,
password,
serverName,
port,
databaseName,
tlsEnabled,
allowSelfSignedCerts,
enableClientSideCerts,
}) => {
const { t } = useCustomTranslation();
const [showPassword, setShowPassword] = React.useState(false);
const processKeys = React.useCallback(
() => (keyFiles: File[]) => {
if (keyFiles.some((file) => file.name.startsWith('private'))) {
dispatch({
type: 'backingStorage/externalPostgres/tls/keys/setPrivateKey',
payload: keyFiles.find((file) => file.name.startsWith('private')),
});
} else {
dispatch({
type: 'backingStorage/externalPostgres/tls/keys/setPrivateKey',
payload: null,
});
}

if (keyFiles.some((file) => file.name.startsWith('public'))) {
dispatch({
type: 'backingStorage/externalPostgres/tls/keys/setPublicKey',
payload: keyFiles.find((file) => file.name.startsWith('public')),
});
} else {
dispatch({
type: 'backingStorage/externalPostgres/tls/keys/setPublicKey',
payload: null,
});
}
},
[dispatch]
);

return (
<Form>
<Text component={TextVariants.h4}>Connection details</Text>
<Grid hasGutter md={12}>
<GridItem md={8} span={2}>
<FormGroup label={t('Username')} fieldId="username-tls" isRequired>
<TextInput
id="username-input"
type="text"
value={username}
onChange={(newUsername: string) => {
dispatch({
type: 'backingStorage/externalPostgres/setUsername',
payload: newUsername,
});
}}
isRequired
/>
</FormGroup>
</GridItem>
<GridItem md={8} span={2}>
<FormGroup label={t('Password')} fieldId="password-tls" isRequired>
<InputGroup>
<TextInput
id="password-input"
type={showPassword ? 'text' : 'password'}
value={password}
onChange={(newPassword: string) => {
dispatch({
type: 'backingStorage/externalPostgres/setPassword',
payload: newPassword,
});
}}
isRequired
/>
<Tooltip
content={
showPassword
? t('plugin__odf-console~Hide password')
: t('plugin__odf-console~Show password')
}
>
<Button
variant="control"
onClick={() => setShowPassword(!showPassword)}
>
{showPassword ? <EyeSlashIcon /> : <EyeIcon />}
</Button>
</Tooltip>
</InputGroup>
</FormGroup>
</GridItem>
<GridItem md={6} span={10}>
<FormGroup label={t('Server')} fieldId="server-tls" isRequired>
<TextInput
id="server-input"
type="text"
value={serverName}
onChange={(newServer: string) => {
dispatch({
type: 'backingStorage/externalPostgres/setServerName',
payload: newServer,
});
}}
isRequired
/>
</FormGroup>
</GridItem>
<GridItem md={6} span={2}>
<FormGroup label={t('Port')} fieldId="port-tls" isRequired>
<TextInput
id="port-input"
type="number"
value={port}
onChange={(newPort: string) => {
dispatch({
type: 'backingStorage/externalPostgres/setPort',
payload: newPort,
});
}}
isRequired
/>
</FormGroup>
</GridItem>
<GridItem md={8} span={2}>
<FormGroup
label={t('Database name')}
fieldId="database-tls"
isRequired
>
<TextInput
id="database-input"
type="text"
value={databaseName}
onChange={(newDatabase: string) => {
dispatch({
type: 'backingStorage/externalPostgres/setDatabaseName',
payload: newDatabase,
});
}}
isRequired
/>
</FormGroup>
</GridItem>
</Grid>
<FormGroup fieldId="enable-tls">
<Checkbox
id="enable-tls"
label={t('Enable TLS/SSL')}
description={t(
'Enable this for encrytion on flight with the Postgres server'
)}
isChecked={tlsEnabled}
onChange={() => {
const isTLSEnabled = !tlsEnabled;
dispatch({
type: 'backingStorage/externalPostgres/tls/enableTLS',
payload: !tlsEnabled,
});

dispatch({
type: 'backingStorage/externalPostgres/tls/allowSelfSignedCerts',
payload:
!isTLSEnabled && allowSelfSignedCerts
? false
: allowSelfSignedCerts,
});

dispatch({
type: 'backingStorage/externalPostgres/tls/enableClientSideCerts',
payload:
!isTLSEnabled && enableClientSideCerts
? false
: enableClientSideCerts,
});
}}
className="odf-backing-store__radio--margin-bottom"
/>
{tlsEnabled && (
<Stack className="odf-backing-store__ssl" hasGutter>
<Checkbox
id="allow-self-signed-certs"
label={t('Allow self-signed certificates')}
description={t(
'Adding this option will allow the postgres server to use a self-signed certificates.'
)}
isChecked={allowSelfSignedCerts}
onChange={() =>
dispatch({
type: 'backingStorage/externalPostgres/tls/allowSelfSignedCerts',
payload: !allowSelfSignedCerts,
})
}
/>
<Checkbox
id="enable-client-side-certs"
label={t('Enable client-side certificates')}
description={t(
'Select this option to upload and use your client side certificates'
)}
isChecked={enableClientSideCerts}
onChange={() => {
dispatch({
type: 'backingStorage/externalPostgres/tls/enableClientSideCerts',
payload: !enableClientSideCerts,
});

dispatch({
type: 'backingStorage/externalPostgres/tls/keys/setPrivateKey',
payload: null,
});

dispatch({
type: 'backingStorage/externalPostgres/tls/keys/setPublicKey',
payload: null,
});
}}
/>
</Stack>
)}
{enableClientSideCerts && (
<UploadFile
acceptedFiles=".pem, .key, .crt"
infoText={t('Accepted file types: .pem, .crt, .key')}
titleText={t(
'Files should be named private and public followed by compatible extensions'
)}
onFileUpload={processKeys}
uploadLimit={2}
compatibleFileFilter={(file) =>
file.name.startsWith('private') || file.name.startsWith('public')
}
/>
)}
</FormGroup>
</Form>
);
};

type PostgresConnectionDetails = {
dispatch: WizardDispatch;
username: WizardState['backingStorage']['externalPostgres']['username'];
password: WizardState['backingStorage']['externalPostgres']['password'];
serverName: WizardState['backingStorage']['externalPostgres']['serverName'];
port: WizardState['backingStorage']['externalPostgres']['port'];
databaseName: WizardState['backingStorage']['externalPostgres']['databaseName'];
tlsEnabled: WizardState['backingStorage']['externalPostgres']['tls']['enabled'];
allowSelfSignedCerts: WizardState['backingStorage']['externalPostgres']['tls']['allowSelfSignedCerts'];
enableClientSideCerts: WizardState['backingStorage']['externalPostgres']['tls']['enableClientSideCerts'];
};
Loading

0 comments on commit 81a7598

Please sign in to comment.