Skip to content

Commit

Permalink
refactor(core/deployment): Update redblack fields without force updat…
Browse files Browse the repository at this point in the history
…ing (spinnaker#8840)

* refactor(core/deployment): Update redblack fields without force updating

* refactor(cloudfoundry): Remove duplicate redblack additional fields component
  • Loading branch information
caseyhebebrand committed Jan 12, 2021
1 parent ad7608d commit 95eacfb
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Select, { Option } from 'react-select';
import { defaultsDeep, unset } from 'lodash';

import {
CoreRedBlackAdditionalFields,
HelpField,
IDeploymentStrategy,
IDeploymentStrategyAdditionalFieldsProps,
Expand All @@ -11,7 +12,6 @@ import {
} from '@spinnaker/core';

import { IRedBlackCommand } from './strategies/redblack/redblack.strategy';
import { AdditionalFields as AdditionalRedBlackFields } from './strategies/redblack/AdditionalFields';
import {
AdditionalFields as AdditionalRollingRedBlackFields,
IRollingRedBlackCommand,
Expand Down Expand Up @@ -52,7 +52,7 @@ export class CloudFoundryDeploymentStrategySelector extends React.Component<
'Disables <i>all</i> previous server groups in the cluster as soon as new server group passes health checks',
key: 'redblack',
additionalFields: ['maxRemainingAsgs'],
AdditionalFieldsComponent: AdditionalRedBlackFields,
AdditionalFieldsComponent: CoreRedBlackAdditionalFields,
initializationMethod: (command: IRedBlackCommand) => {
defaultsDeep(command, {
rollback: {
Expand Down

This file was deleted.

1 change: 1 addition & 0 deletions app/scripts/modules/core/src/deploymentStrategy/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './DeploymentStrategySelector';
export * from './deploymentStrategy.registry';
export { AdditionalFields as CoreRedBlackAdditionalFields } from './strategies/redblack/AdditionalFields';
Original file line number Diff line number Diff line change
@@ -1,95 +1,79 @@
import React from 'react';
import { set } from 'lodash';

import { IDeploymentStrategyAdditionalFieldsProps } from '../../deploymentStrategy.registry';
import { HelpField } from 'core/help/HelpField';

import { IRedBlackCommand } from './redblack.strategy';

export interface IRedBlackStrategyAdditionalFieldsProps extends IDeploymentStrategyAdditionalFieldsProps {
command: IRedBlackCommand;
}

export class AdditionalFields extends React.Component<IRedBlackStrategyAdditionalFieldsProps> {
private handleChange = (key: string, value: any) => {
set(this.props.command, key, value);
this.forceUpdate();
};

public render() {
const { command } = this.props;
return (
<div className="form-group">
<div className="col-md-12 checkbox">
<label>
<input
type="checkbox"
checked={command.rollback?.onFailure ?? false}
onChange={(e) => this.handleChange('rollback.onFailure', e.target.checked)}
/>
Rollback to previous server group if deployment fails <HelpField id="strategy.redblack.rollback" />
</label>
</div>
<div className="col-md-12 checkbox">
<label>
<input
type="checkbox"
checked={command.scaleDown}
onChange={(e) => this.handleChange('scaleDown', e.target.checked)}
/>
Scale down replaced server groups to zero instances
<HelpField id="strategy.redblack.scaleDown" />
</label>
</div>
<div className="col-md-12 form-inline">
<label>
Maximum number of server groups to leave
<HelpField id="strategy.redblack.maxRemainingAsgs" />
</label>
<input
className="form-control input-sm"
style={{ width: '50px' }}
type="number"
value={command.maxRemainingAsgs}
onChange={(e) => this.handleChange('maxRemainingAsgs', e.target.value)}
min="2"
/>
</div>
<div className="col-md-12 form-inline">
<label>
Wait Before Disable
<HelpField content="Time to wait before disabling all old server groups in this cluster" />
</label>
<input
className="form-control input-sm"
style={{ width: '60px' }}
min="0"
type="number"
value={command.delayBeforeDisableSec}
onChange={(e) => this.handleChange('delayBeforeDisableSec', e.target.value)}
placeholder="0"
/>
seconds
</div>
{command.scaleDown && (
<div className="col-md-12 form-inline" style={{ marginTop: '5px' }}>
<label>
Wait Before Scale Down
<HelpField content="Time to wait before scaling down all old server groups in this cluster" />
</label>
<input
className="form-control input-sm"
style={{ width: '60px' }}
min="0"
type="number"
value={command.delayBeforeScaleDownSec}
onChange={(e) => this.handleChange('delayBeforeScaleDownSec', e.target.value)}
placeholder="0"
/>
seconds
</div>
)}
export const AdditionalFields = ({ command, onChange }: IRedBlackStrategyAdditionalFieldsProps) => (
<div className="form-group">
<div className="col-md-12 checkbox">
<label>
<input
type="checkbox"
checked={command.rollback?.onFailure ?? false}
onChange={(e) => onChange('rollback.onFailure', e.target.checked)}
/>
Rollback to previous server group if deployment fails <HelpField id="strategy.redblack.rollback" />
</label>
</div>
<div className="col-md-12 checkbox">
<label>
<input type="checkbox" checked={command.scaleDown} onChange={(e) => onChange('scaleDown', e.target.checked)} />
Scale down replaced server groups to zero instances
<HelpField id="strategy.redblack.scaleDown" />
</label>
</div>
<div className="col-md-12 form-inline">
<label>
Maximum number of server groups to leave
<HelpField id="strategy.redblack.maxRemainingAsgs" />
</label>
<input
className="form-control input-sm"
style={{ width: '50px' }}
type="number"
value={command.maxRemainingAsgs}
onChange={(e) => onChange('maxRemainingAsgs', e.target.value)}
min="2"
/>
</div>
<div className="col-md-12 form-inline">
<label>
Wait Before Disable
<HelpField content="Time to wait before disabling all old server groups in this cluster" />
</label>
<input
className="form-control input-sm"
style={{ width: '60px' }}
min="0"
type="number"
value={command.delayBeforeDisableSec}
onChange={(e) => onChange('delayBeforeDisableSec', e.target.value)}
placeholder="0"
/>
seconds
</div>
{command.scaleDown && (
<div className="col-md-12 form-inline" style={{ marginTop: '5px' }}>
<label>
Wait Before Scale Down
<HelpField content="Time to wait before scaling down all old server groups in this cluster" />
</label>
<input
className="form-control input-sm"
style={{ width: '60px' }}
min="0"
type="number"
value={command.delayBeforeScaleDownSec}
onChange={(e) => onChange('delayBeforeScaleDownSec', e.target.value)}
placeholder="0"
/>
seconds
</div>
);
}
}
)}
</div>
);

0 comments on commit 95eacfb

Please sign in to comment.