Skip to content

Commit

Permalink
Fixed PVC creation and GCP issues
Browse files Browse the repository at this point in the history
  • Loading branch information
bipuladh committed Dec 8, 2019
1 parent 1288239 commit 7ce1e97
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const CreateBackingStoreFormPage: React.FC<CreateBackingStoreFormPageProps> = ({
isPage
namespace={ns}
className="nb-bs-page-form__short"
csv={clusterServiceVersion}
/>
</div>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { history } from '@console/internal/components/utils/router';
import { StorageClassDropdown } from '@console/internal/components/utils/storage-class-dropdown';
import { NooBaaBackingStoreModel } from '../../models';
import './create-bs.scss';
import { BC_PROVIDERS } from '../../constants';

const providers = {
'AWS S3': 'AWS S3',
Expand All @@ -58,12 +59,14 @@ const bucketNoobaaMap = {
'AWS S3': 'targetBucket',
'S3 Compatible': 'targetBucket',
'Azure Blob': 'targetBlobContainer',
'Google cloud storage': 'targetBucket',
};

const typeNoobaaMap = {
'AWS S3': 'aws-s3',
'S3 Compatible': 's3-compatible',
'Azure Blob': 'azure-blob',
'Google cloud storage': 'google-cloud-storage',
PVC: 'pv-pool',
};

Expand All @@ -90,17 +93,22 @@ const awsRegions = [
];

const awsRegionItems = _.zipObject(awsRegions, awsRegions);

const externalProviders = [
BC_PROVIDERS.AWS,
BC_PROVIDERS.AZURE,
BC_PROVIDERS.S3,
BC_PROVIDERS.GOOG,
];
/**
* aws-s3, s3 compatible share the same form
*/
const S3EndPointType: React.FC<S3EndpointTypeProps> = (props) => {
const [showSecret, setShowSecret] = React.useState(true);
const { provider, namespace, state, dispatch } = props;

const targetLabel = provider === 'Azure Blob' ? 'Target Blob Container' : 'Target Bucket';
const credentialField1Label = provider === 'Azure Blob' ? 'Account Name' : 'Access Key';
const credentialField2Label = provider === 'Azure Blob' ? 'Account Key' : 'Secret Key';
const targetLabel = provider === BC_PROVIDERS.AZURE ? 'Target Blob Container' : 'Target Bucket';
const credentialField1Label = provider === BC_PROVIDERS.AZURE ? 'Account Name' : 'Access Key';
const credentialField2Label = provider === BC_PROVIDERS.AZURE ? 'Account Key' : 'Secret Key';
const resources = [
{
isList: true,
Expand Down Expand Up @@ -173,7 +181,7 @@ const S3EndPointType: React.FC<S3EndpointTypeProps> = (props) => {
</FormGroup>
) : (
<>
<FormGroup label={credentialField1Label} fieldId="acess-key" isRequired>
<FormGroup label={credentialField1Label} fieldId="acess-key">
<InputGroup>
<TextInput
value={state.accessKey}
Expand All @@ -191,7 +199,6 @@ const S3EndPointType: React.FC<S3EndpointTypeProps> = (props) => {
className="nb-bs-form-entry"
label={credentialField2Label}
fieldId="secret-key"
isRequired
>
<TextInput
value={state.secretKey}
Expand Down Expand Up @@ -294,7 +301,7 @@ const PVCType: React.FC<PVCTypeProps> = ({ state, dispatch }) => {
);
};

const gcpHelpText = () => (
const gcpHelpText = (
<DashboardCardPopupLink
linkTitle={
<>
Expand All @@ -317,7 +324,7 @@ const gcpHelpText = () => (
const GCPEndpointType: React.FC<GCPEndPointTypeProps> = (props) => {
const [fileData, setFileData] = React.useState('');
const [inputData, setInputData] = React.useState('');
const { dispatch } = props;
const { state, dispatch } = props;

const onUpload = (event) => {
event.preventDefault();
Expand Down Expand Up @@ -374,6 +381,20 @@ const GCPEndpointType: React.FC<GCPEndPointTypeProps> = (props) => {
value={fileData}
/>
</FormGroup>
<FormGroup
className="nb-bs-form-entry"
label="Target Bucket"
fieldId="target-bucket"
isRequired
>
<TextInput
value={state.target}
onChange={(e) => {
dispatch({ type: 'setTarget', value: e });
}}
aria-label="Target Bucket"
/>
</FormGroup>
</>
);
};
Expand Down Expand Up @@ -421,7 +442,7 @@ const initialState: ProviderDataState = {
secretName: '',
secretKey: '',
accessKey: '',
region: '',
region: awsRegions[0],
gcpJSON: '',
target: '',
endpoint: '',
Expand Down Expand Up @@ -477,13 +498,13 @@ const secretPayloadCreator = (
};

switch (provider) {
case 'Azure Blob':
case BC_PROVIDERS.AZURE:
payload.stringData = {
AccountName: field1,
AccountKey: field2,
};
break;
case 'Google cloud storage':
case BC_PROVIDERS.GOOG:
payload.stringData = {
GoogleServiceAccountPrivateKeyJson: field1,
};
Expand All @@ -503,7 +524,7 @@ const CreateBackingStoreForm: React.FC<CreateBackingStoreFormProps> = withHandle
>((props) => {
const [namespace, setNamespace] = React.useState(props.namespace);
const [bsName, setBsName] = React.useState('');
const [provider, setProvider] = React.useState(providers['AWS S3']);
const [provider, setProvider] = React.useState(BC_PROVIDERS.AWS);
const [providerDataState, providerDataDispatch] = React.useReducer(
providerDataReducer,
initialState,
Expand All @@ -516,7 +537,7 @@ const CreateBackingStoreForm: React.FC<CreateBackingStoreFormProps> = withHandle
/** Create a secret if secret ==='' */
let { secretName } = providerDataState;
const promises = [];
if (!secretName) {
if (!secretName && provider !== BC_PROVIDERS.PVC) {
secretName = bsName.concat('-secret');
const { secretKey, accessKey, gcpJSON } = providerDataState;
const secretPayload = secretPayloadCreator(
Expand All @@ -526,6 +547,7 @@ const CreateBackingStoreForm: React.FC<CreateBackingStoreFormProps> = withHandle
accessKey || gcpJSON,
secretKey,
);
providerDataDispatch({ type: 'setSecretName', value: secretName });
promises.push(k8sCreate(SecretModel, secretPayload));
}
/** Payload for bs */
Expand All @@ -538,20 +560,40 @@ const CreateBackingStoreForm: React.FC<CreateBackingStoreFormProps> = withHandle
},
spec: {
type: typeNoobaaMap[provider],
ssl: false,
},
};
if (provider === BC_PROVIDERS.PVC) {
// eslint-disable-next-line
bsPayload.spec['pvPool'] = {
numVolumes: providerDataState.numVolumes,
storageClass: providerDataState.storageClass,
};
} else if (externalProviders.includes(provider)) {
bsPayload.spec = {
...bsPayload.spec,
[providerNoobaaMap[provider]]: {
[bucketNoobaaMap[provider]]: providerDataState.target,
secret: {
name: secretName,
name: providerDataState.secretName,
namespace,
},
},
ssl: false,
},
};

if (provider === 'AWS S3') {
};
}
if (provider === BC_PROVIDERS.S3) {
// eslint-disable-next-line
bsPayload.spec['s3Compatible'] = {
// eslint-disable-next-line
...bsPayload.spec['s3Compatible'],
endpoint: providerDataState.endpoint,
};
}
// Add region in the end
if (provider === BC_PROVIDERS.AWS) {
bsPayload.spec.awsS3 = { ...bsPayload.spec.awsS3, region: providerDataState.region };
}

promises.push(k8sCreate(NooBaaBackingStoreModel, bsPayload));
return handlePromise(Promise.all(promises)).then((resource) => {
const lastIndex = resource.length - 1;
Expand Down Expand Up @@ -599,16 +641,22 @@ const CreateBackingStoreForm: React.FC<CreateBackingStoreFormProps> = withHandle
selectedKey={provider}
/>
</FormGroup>
{provider === 'Google cloud storage' && <GCPEndpointType dispatch={providerDataDispatch} />}
{(provider === 'AWS S3' || provider === 'S3 Compatible' || provider === 'Azure Blob') && (
{provider === BC_PROVIDERS.GOOG && (
<GCPEndpointType state={providerDataState} dispatch={providerDataDispatch} />
)}
{(provider === BC_PROVIDERS.AWS ||
provider === BC_PROVIDERS.S3 ||
provider === BC_PROVIDERS.AZURE) && (
<S3EndPointType
provider={provider}
namespace="openshift-storage"
state={providerDataState}
dispatch={providerDataDispatch}
/>
)}
{provider === 'PVC' && <PVCType state={providerDataState} dispatch={providerDataDispatch} />}
{provider === BC_PROVIDERS.PVC && (
<PVCType state={providerDataState} dispatch={providerDataDispatch} />
)}
<ButtonBar errorMessage={errorMessage} inProgress={inProgress}>
<ActionGroup>
<Button type="submit" variant="primary">
Expand Down Expand Up @@ -645,5 +693,6 @@ type PVCTypeProps = {
};

type GCPEndPointTypeProps = {
state: ProviderDataState;
dispatch: React.Dispatch<Action>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,11 @@ export const CHART_LABELS = {
[BY_EGRESS]: 'Egress Per Provider',
[BY_IOPS]: 'I/O Operations count',
};

export enum BC_PROVIDERS {
AWS = 'AWS S3',
S3 = 'S3 Compatible',
PVC = 'PVC',
GOOG = 'Google cloud storage',
AZURE = 'Azure Blob',
}

0 comments on commit 7ce1e97

Please sign in to comment.