import React, { useEffect, useState } from 'react'; import type { IAccount, IStageConfigProps } from '@spinnaker/core'; import { AccountRegionClusterSelector, AccountService, PlatformHealthOverride, Registry, StageConfigField, } from '@spinnaker/core'; function pluralize(str: string, val: number): string { return val === 1 ? str : `${str}s`; } export function AwsShrinkClusterStageConfig(props: IStageConfigProps) { const { application, pipeline, stage, stageFieldUpdated, updateStageField } = props; const [accounts, setAccounts] = useState([]); useEffect(() => { const changes: Record = {}; if (stage.cloudProvider !== 'aws') { changes.cloudProvider = 'aws'; } if (!stage.credentials && application.defaultCredentials?.aws) { changes.credentials = application.defaultCredentials.aws; } if (stage.shrinkToSize === undefined) { changes.shrinkToSize = 1; } if (stage.allowDeleteActive === undefined) { changes.allowDeleteActive = false; } if (stage.retainLargerOverNewer === undefined) { changes.retainLargerOverNewer = 'false'; } if ( stage.isNew && application.attributes.platformHealthOnlyShowOverride && application.attributes.platformHealthOnly && stage.interestingHealthProviderNames === undefined ) { changes.interestingHealthProviderNames = ['Amazon']; } if (Object.keys(changes).length) { updateStageField(changes); } }, []); useEffect(() => { let active = true; AccountService.listAccounts('aws').then((loadedAccounts) => active && setAccounts(loadedAccounts)); return () => { active = false; }; }, []); return (
{!pipeline.strategy && ( )}
Shrink to{' '} updateStageField({ shrinkToSize: Number(event.target.value) })} required style={{ width: 50 }} type="number" value={stage.shrinkToSize ?? ''} />{' '} {pluralize('server group', stage.shrinkToSize)}, keeping the{' '}
{application.attributes.platformHealthOnlyShowOverride && ( updateStageField({ interestingHealthProviderNames })} platformHealthType="Amazon" /> )}
); } export const awsShrinkClusterStage = { key: 'shrinkCluster', provides: 'shrinkCluster', cloudProvider: 'aws', component: AwsShrinkClusterStageConfig, accountExtractor: (stage: any) => [stage.context.credentials], configAccountExtractor: (stage: any) => [stage.credentials], validators: [ { type: 'requiredField', fieldName: 'cluster' }, { type: 'requiredField', fieldName: 'shrinkToSize', fieldLabel: 'shrink to [X] Server Groups' }, { type: 'requiredField', fieldName: 'regions' }, { type: 'requiredField', fieldName: 'credentials', fieldLabel: 'account' }, ], }; export function registerAwsShrinkClusterStage() { Registry.pipeline.registerStage(awsShrinkClusterStage); } registerAwsShrinkClusterStage();