-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathfooter.tsx
More file actions
610 lines (575 loc) · 18.7 KB
/
Copy pathfooter.tsx
File metadata and controls
610 lines (575 loc) · 18.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
import * as React from 'react';
import {
getDeviceSetReplica,
getExternalStorage,
getTotalCpu,
getTotalMemoryInGiB,
getRBDVolumeSnapshotClassName,
} from '@odf/core/components/utils';
import {
ERASURE_CODING_MIN_NODES,
MINIMUM_NODES,
NO_PROVISIONER,
Steps,
StepsName,
} from '@odf/core/constants';
import { useODFNamespaceSelector } from '@odf/core/redux';
import {
labelOCSNamespace,
isResourceProfileAllowed,
getDeviceSetCount,
getNodeArchitectureFromState,
getOsdAmount,
isFlexibleScaling,
isValidCapacityAutoScalingConfig,
} from '@odf/core/utils';
import { StorageClassWizardStepExtensionProps as ExternalStorage } from '@odf/odf-plugin-sdk/extensions';
import { StorageClusterKind } from '@odf/shared';
import {
StorageAutoScalerModel,
StorageClusterModel,
} from '@odf/shared/models';
import { getName, getNamespace } from '@odf/shared/selectors';
import { useCustomTranslation } from '@odf/shared/useCustomTranslationHook';
import { getStorageAutoScalerName, isNotFoundError } from '@odf/shared/utils';
import {
k8sDelete,
K8sResourceCommon,
} from '@openshift-console/dynamic-plugin-sdk';
import { TFunction } from 'react-i18next';
import { useNavigate } from 'react-router-dom-v5-compat';
import { useWizardContext, WizardFooterWrapper } from '@patternfly/react-core';
import { Button, Alert, AlertActionCloseButton } from '@patternfly/react-core';
import {
NetworkType,
BackingStorageType,
DeploymentType,
VolumeTypeValidation,
} from '../../types';
import { createClusterKmsResources } from '../kms-config/utils';
import { isIpInCidr, isValidCIDRFormat, getMonIp } from '../utils/cidr-utils';
import './create-storage-system.scss';
import {
createNoobaaExternalPostgresResources,
createStorageCluster,
labelNodes,
taintNodes,
createOCSNamespace,
createStorageAutoScaler,
} from './payloads';
import { WizardCommonProps, WizardState } from './reducer';
// Not to be exposed to other files to make our code name agnostic
const OCS_INTERNAL_CR_NAME = 'ocs-storagecluster';
const NOOBAA_DB_BACKUP_VOLUMESNAPSHOTCLASS =
getRBDVolumeSnapshotClassName(OCS_INTERNAL_CR_NAME);
const validateBackingStorageStep = (
backingStorage: WizardState['backingStorage'],
sc: WizardState['storageClass']
) => {
const { type, externalStorage, deployment } = backingStorage;
switch (type) {
case BackingStorageType.EXISTING:
return !!sc.name && !!deployment;
case BackingStorageType.EXTERNAL:
return !!externalStorage;
case BackingStorageType.LOCAL_DEVICES:
return !!deployment;
default:
return false;
}
};
const validateOptionalSettingsStep = (
optionalSettings: WizardState['optionalSettings'],
sc: WizardState['storageClass'],
deployment: DeploymentType,
type: BackingStorageType
) => {
const {
enableNFS,
useExternalPostgres,
externalPostgres,
isDbBackup,
dbBackup,
} = optionalSettings;
const {
username,
password,
serverName,
port,
databaseName,
tls: { enableClientSideCerts, keys },
} = externalPostgres;
const isMCG: boolean = deployment === DeploymentType.MCG;
const hasPGEnabledButNoFields =
useExternalPostgres &&
(!username || !password || !serverName || !port || !databaseName);
const hasClientCertsEnabledButNoKeys =
enableClientSideCerts && (!keys.private || !keys.public);
// The Next button is disabled only when no VolumeSnapshotClass is selected for MCG Standalone when automatic backup option enabled.
const hasDbBackupEnabledButNoFields =
isDbBackup && !dbBackup.volumeSnapshot?.volumeSnapshotClass && isMCG;
switch (type) {
case BackingStorageType.EXISTING:
return (
!!sc.name &&
!!deployment &&
!hasPGEnabledButNoFields &&
!hasClientCertsEnabledButNoKeys &&
!hasDbBackupEnabledButNoFields
);
case BackingStorageType.EXTERNAL:
return (
!enableNFS &&
!hasPGEnabledButNoFields &&
!hasClientCertsEnabledButNoKeys &&
!hasDbBackupEnabledButNoFields
);
case BackingStorageType.LOCAL_DEVICES:
return (
!!deployment &&
!hasPGEnabledButNoFields &&
!hasClientCertsEnabledButNoKeys &&
!hasDbBackupEnabledButNoFields
);
default:
return false;
}
};
const validateAdvancedSettingsStep = (
advancedSettings: WizardState['advancedSettings'],
type: BackingStorageType,
nodeCount: number,
flexibleScaling: boolean
) => {
const {
useErasureCoding,
erasureCodingScheme,
enableForcefulDeployment,
forcefulDeploymentConfirmation,
} = advancedSettings;
const erasureCodingStepValid =
!useErasureCoding ||
!flexibleScaling ||
(nodeCount >= ERASURE_CODING_MIN_NODES && !!erasureCodingScheme);
// The Next button is disabled only when no VolumeSnapshotClass is selected for MCG Standalone when automatic backup option enabled.
const hasForcefulDeploymentButNoConfirmation =
type === BackingStorageType.LOCAL_DEVICES &&
enableForcefulDeployment &&
!(forcefulDeploymentConfirmation?.trim() === 'CONFIRM');
return erasureCodingStepValid && !hasForcefulDeploymentButNoConfirmation;
};
const canJumpToNextStep = (
name: string,
state: WizardState,
t: TFunction,
supportedExternalStorage: ExternalStorage[],
isTNFEnabled: boolean
) => {
const {
storageClass,
backingStorage,
createStorageClass,
capacityAndNodes,
createLocalVolumeSet,
securityAndNetwork,
connectionDetails,
nodes,
advancedSettings,
optionalSettings,
} = state;
const { type, externalStorage } = backingStorage;
const isExternal: boolean = type === BackingStorageType.EXTERNAL;
const isRHCS: boolean = externalStorage === StorageClusterModel.kind;
const {
capacity,
enableArbiter,
pvCount,
resourceProfile,
volumeValidationType,
} = capacityAndNodes;
const isNoProvisioner = storageClass.provisioner === NO_PROVISIONER;
const flexibleScaling = isFlexibleScaling(
nodes,
isNoProvisioner,
enableArbiter
);
const { chartNodes, volumeSetName, isValidDiskSize, isValidDeviceType } =
createLocalVolumeSet;
const {
encryption,
kms,
networkType,
publicNetwork,
clusterNetwork,
addressRanges,
usePublicNetwork,
useClusterNetwork,
} = securityAndNetwork;
const { canGoToNextStep } =
getExternalStorage(externalStorage, supportedExternalStorage) || {};
const publicCidr = addressRanges?.public?.[0]?.trim() ?? '';
const clusterCidr = addressRanges?.cluster?.[0]?.trim() ?? '';
const hasValidNICNetwork =
networkType === NetworkType.NIC &&
((usePublicNetwork && isValidCIDRFormat(publicCidr)) ||
(useClusterNetwork && isValidCIDRFormat(clusterCidr)));
const hasConfiguredNetwork =
networkType === NetworkType.MULTUS
? !!(publicNetwork || clusterNetwork)
: networkType === NetworkType.NIC
? hasValidNICNetwork
: true;
const hasDedicatedStorageWithCidr =
networkType === NetworkType.NIC &&
((usePublicNetwork && publicCidr) || (useClusterNetwork && clusterCidr));
/** mon-ip applies to public network (mons); cluster network CIDR does not use mon-ip checks. */
const needsMonIpAnnotation =
networkType === NetworkType.NIC && usePublicNetwork && !!publicCidr;
const allNodesHaveMonIpAnnotation =
!hasDedicatedStorageWithCidr ||
!needsMonIpAnnotation ||
nodes.every((node) => (getMonIp(node)?.length ?? 0) > 0);
const allMonIpsInCidr =
!hasDedicatedStorageWithCidr ||
nodes.every((node) => {
if (!usePublicNetwork || !publicCidr) return true;
const ip = getMonIp(node);
if (!ip) return false;
return isIpInCidr(ip, publicCidr);
});
const deviceSetReplica: number = getDeviceSetReplica(
enableArbiter,
flexibleScaling,
nodes
);
const deviceSetCount = getDeviceSetCount(pvCount, deviceSetReplica);
const osdAmount = getOsdAmount(deviceSetCount, deviceSetReplica);
switch (name) {
case StepsName(t)[Steps.BackingStorage]:
return validateBackingStorageStep(backingStorage, storageClass);
case StepsName(t)[Steps.OptionalSettings]:
return validateOptionalSettingsStep(
optionalSettings,
storageClass,
backingStorage.deployment,
backingStorage.type
);
case StepsName(t)[Steps.AdvancedSettings]:
return validateAdvancedSettingsStep(
advancedSettings,
backingStorage.type,
nodes.length,
flexibleScaling
);
case StepsName(t)[Steps.CreateStorageClass]:
return (
!!storageClass.name &&
canGoToNextStep &&
canGoToNextStep(createStorageClass, storageClass.name)
);
case StepsName(t)[Steps.CreateLocalVolumeSet]:
return (
// "chartNodes.size === 0" signify no SSDs are attached, but no need to add that as it's already covered by "chartNodes.size >= MINIMUM_NODES" condition
chartNodes.size >= MINIMUM_NODES &&
volumeSetName.trim().length &&
isValidDiskSize &&
isValidDeviceType
);
case StepsName(t)[Steps.CapacityAndNodes]: {
const architecture = getNodeArchitectureFromState(nodes);
if (isTNFEnabled) {
return nodes.length === 2;
} else {
return (
nodes.length >= MINIMUM_NODES &&
capacity &&
![VolumeTypeValidation.UNKNOWN, VolumeTypeValidation.ERROR].includes(
volumeValidationType
) &&
isResourceProfileAllowed(
resourceProfile,
getTotalCpu(nodes),
getTotalMemoryInGiB(nodes),
osdAmount,
architecture,
optionalSettings.enableNFS
) &&
isValidCapacityAutoScalingConfig(
capacityAndNodes.capacityAutoScaling.enable,
capacityAndNodes.capacityAutoScaling.capacityLimit
)
);
}
}
case StepsName(t)[Steps.SecurityAndNetwork]:
if (isExternal && isRHCS) {
return canGoToNextStep(connectionDetails, storageClass.name);
}
return (
encryption.hasHandled &&
kms.providerState.hasHandled &&
hasConfiguredNetwork &&
allNodesHaveMonIpAnnotation &&
allMonIpsInCidr
);
case StepsName(t)[Steps.Security]:
return encryption.hasHandled && kms.providerState.hasHandled;
case StepsName(t)[Steps.ReviewAndCreate]:
return true;
default:
return false;
}
};
const handleReviewAndCreateNext = async (
state: WizardState,
handleError: (err: string, showError: boolean) => void,
navigate,
odfNamespace: string,
existingNamespaces: K8sResourceCommon[],
isTNFEnabled: boolean
) => {
const { nodes, capacityAndNodes } = state;
const { systemNamespace, deployment, type } = state.backingStorage;
const { useExternalPostgres, externalPostgres } = state.optionalSettings;
const { encryption, kms } = state.securityAndNetwork;
const isMCG: boolean = deployment === DeploymentType.MCG;
const nsAlreadyExists = !!existingNamespaces.find(
(ns) => getName(ns) === systemNamespace
);
const createNooBaaResources = async () => {
if (useExternalPostgres) {
let keyTexts = { private: '', public: '' };
if (externalPostgres.tls.enableClientSideCerts) {
const keys = externalPostgres.tls.keys;
const privateKey = await keys.private.text();
const publicKey = await keys.public.text();
keyTexts = { private: privateKey, public: publicKey };
}
await Promise.all(
createNoobaaExternalPostgresResources(
systemNamespace,
externalPostgres,
keyTexts
)
);
}
};
const createAdditionalFeatureResources = async () => {
if (capacityAndNodes.enableTaint && !isMCG) await taintNodes(nodes);
/**
* CSI KMS ConfigMap and Secrets always needs to be created in ODF install namespace (that is, where Rook is deployed),
* whereas OCS KMS ConfigMap and Secrets needs to be created in the namespace where Ceph is being deployed (StorageSystem namespace).
* ToDo: External mode do not support KMS and only single Internal mode is allowed, so it should work for now,
* but in future, if need arises, first check whether CSI ConfigMap already exists or not before creating KMS related resources for multiple clusters.
* Also, change name of "ceph-csi-kms-token" token Secret (if need to create multiple in Rook namespace).
*/
if (encryption.advanced)
// as currently only one internal cluster is allowed, "systemNamespace" (where intenal cluster is being created) and "odfNamespace" (where ODF is installed) will be same
await Promise.all(
createClusterKmsResources(
kms.providerState,
systemNamespace,
odfNamespace,
kms.provider,
isMCG
)
);
if (!isTNFEnabled) await createNooBaaResources();
};
try {
systemNamespace === odfNamespace || nsAlreadyExists
? await labelOCSNamespace(systemNamespace)
: await createOCSNamespace(systemNamespace);
let storageCluster: StorageClusterKind;
if (isMCG) {
await createAdditionalFeatureResources();
storageCluster = await createStorageCluster(
state,
systemNamespace,
OCS_INTERNAL_CR_NAME,
isTNFEnabled
);
} else if (
type === BackingStorageType.EXISTING ||
type === BackingStorageType.LOCAL_DEVICES
) {
await labelNodes(nodes, systemNamespace);
await createAdditionalFeatureResources();
storageCluster = await createStorageCluster(
state,
systemNamespace,
OCS_INTERNAL_CR_NAME,
isTNFEnabled
);
}
if (storageCluster) {
try {
// Delete preexisting ui-created autoscaler to avoid a misconfiguration.
await k8sDelete({
model: StorageAutoScalerModel,
resource: {
metadata: {
name: getStorageAutoScalerName(storageCluster),
namespace: getNamespace(storageCluster),
},
},
});
} catch (error) {
// It's OK if it didn't exist.
if (!isNotFoundError(error)) {
// eslint-disable-next-line no-console
console.error(
`Error while deleting preexisting capacity autoscaling: ${error.message}`
);
}
}
if (state.capacityAndNodes.capacityAutoScaling.enable) {
// Don't stop the workflow on autoscaler creation error.
try {
await createStorageAutoScaler(
state.capacityAndNodes.capacityAutoScaling.capacityLimit,
storageCluster
);
} catch (error) {
// TODO: raise a notification once the notification system is implemented.
// eslint-disable-next-line no-console
console.error(
`Error while enabling capacity autoscaling: ${error.message}`
);
}
}
}
navigate('/odf/storage-cluster');
} catch (err) {
handleError(err.message, true);
}
};
export const CreateStorageSystemFooter: React.FC<
CreateStorageSystemFooterProps
> = ({
dispatch,
state,
disableNext,
supportedExternalStorage,
existingNamespaces,
isTNFEnabled,
}) => {
const { t } = useCustomTranslation();
const navigate = useNavigate();
const { activeStep, goToNextStep, goToPrevStep } = useWizardContext();
const { odfNamespace, isNsSafe } = useODFNamespaceSelector();
const [requestInProgress, setRequestInProgress] = React.useState(false);
const [requestError, setRequestError] = React.useState('');
const [showErrorAlert, setShowErrorAlert] = React.useState(false);
const stepName = activeStep.name as string;
const { deployment } = state.backingStorage;
const { isDbBackup } = state.optionalSettings;
const isMCG: boolean = deployment === DeploymentType.MCG;
const jumpToNextStep = canJumpToNextStep(
stepName,
state,
t,
supportedExternalStorage,
isTNFEnabled
);
const moveToNextStep = () => {
goToNextStep();
};
const handleError = (errorMessage: string, showError: boolean) => {
setRequestError(errorMessage);
setShowErrorAlert(showError);
};
const handleNext = async () => {
switch (stepName) {
case StepsName(t)[Steps.CreateLocalVolumeSet]:
dispatch({
type: 'wizard/setCreateLocalVolumeSet',
payload: { field: 'showConfirmModal', value: true },
});
break;
case StepsName(t)[Steps.OptionalSettings]:
// Auto-select the RBD VolumeSnapshotClass for internal mode when automatic backup is enabled.
if (isDbBackup && !isMCG) {
dispatch({
type: 'optionalSettings/dbBackup/volumeSnapshot/volumeSnapshotClass',
payload: NOOBAA_DB_BACKUP_VOLUMESNAPSHOTCLASS,
});
}
moveToNextStep();
break;
case StepsName(t)[Steps.ReviewAndCreate]:
setRequestInProgress(true);
await handleReviewAndCreateNext(
state,
handleError,
navigate,
odfNamespace,
existingNamespaces,
isTNFEnabled
);
setRequestInProgress(false);
break;
default:
moveToNextStep();
}
};
return (
<>
{showErrorAlert && (
<Alert
className="odf-create-storage-system-footer__alert"
variant="danger"
isInline
actionClose={
<AlertActionCloseButton onClose={() => handleError('', false)} />
}
title={t('An error has occurred')}
>
{requestError}
</Alert>
)}
<WizardFooterWrapper>
<Button
isLoading={requestInProgress || null}
isDisabled={
disableNext || requestInProgress || !jumpToNextStep || !isNsSafe
}
variant="primary"
onClick={handleNext}
className="pf-v6-u-mr-sm"
>
{stepName === StepsName(t)[Steps.ReviewAndCreate]
? t('Create storage system')
: t('Next')}
</Button>
{/* Disabling the back button for the first step (Backing storage) in wizard */}
<Button
variant="secondary"
onClick={goToPrevStep}
isDisabled={
stepName === StepsName(t)[Steps.BackingStorage] ||
requestInProgress ||
!isNsSafe
}
className="pf-v6-u-mr-sm"
>
{t('Back')}
</Button>
<Button
variant="secondary"
onClick={() => navigate(-1)}
isDisabled={requestInProgress}
>
{t('Cancel')}
</Button>
</WizardFooterWrapper>
</>
);
};
type CreateStorageSystemFooterProps = WizardCommonProps & {
disableNext: boolean;
hasOCS: boolean;
supportedExternalStorage: ExternalStorage[];
existingNamespaces: K8sResourceCommon[];
isTNFEnabled: boolean;
};