-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(provider/cf): use custom implementation of DeploymentStrateg…
…ySelector
- Loading branch information
1 parent
e19c832
commit c8b8456
Showing
5 changed files
with
148 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
app/scripts/modules/cloudfoundry/src/deploymentStrategy/DeploymentStrategySelector.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { DeploymentStrategySelector, IDeploymentStrategySelectorState } from '@spinnaker/core'; | ||
import { IRedBlackCommand } from 'cloudfoundry/deploymentStrategy/strategies/redblack/redblack.strategy'; | ||
import { defaultsDeep, unset } from 'lodash'; | ||
import { AdditionalFields } from './strategies/redblack/AdditionalFields'; | ||
|
||
export class CloudFoundryDeploymentStrategySelector extends DeploymentStrategySelector { | ||
public state: IDeploymentStrategySelectorState = { | ||
strategies: [ | ||
{ | ||
label: 'None', | ||
description: 'Creates the next server group with no impact on existing server groups', | ||
key: '', | ||
}, | ||
{ | ||
label: 'Highlander', | ||
description: | ||
'Destroys <i>all</i> previous server groups in the cluster as soon as new server group passes health checks', | ||
key: 'highlander', | ||
}, | ||
{ | ||
label: 'Red/Black', | ||
description: | ||
'Disables <i>all</i> previous server groups in the cluster as soon as new server group passes health checks', | ||
key: 'redblack', | ||
additionalFields: ['maxRemainingAsgs'], | ||
AdditionalFieldsComponent: AdditionalFields, | ||
initializationMethod: (command: IRedBlackCommand) => { | ||
defaultsDeep(command, { | ||
rollback: { | ||
onFailure: false, | ||
}, | ||
maxRemainingAsgs: 2, | ||
delayBeforeDisableSec: 0, | ||
delayBeforeScaleDownSec: 0, | ||
scaleDown: false, | ||
}); | ||
}, | ||
}, | ||
], | ||
currentStrategy: null, | ||
AdditionalFieldsComponent: undefined, | ||
}; | ||
|
||
public selectStrategy(strategy: string): void { | ||
const { command, onStrategyChange } = this.props; | ||
const oldStrategy = this.state.strategies.find(s => s.key === this.state.currentStrategy); | ||
const newStrategy = this.state.strategies.find(s => s.key === strategy); | ||
|
||
if (oldStrategy && oldStrategy.additionalFields) { | ||
oldStrategy.additionalFields.forEach(field => { | ||
if (!newStrategy || !newStrategy.additionalFields || !newStrategy.additionalFields.includes(field)) { | ||
unset(command, field); | ||
} | ||
}); | ||
} | ||
|
||
let AdditionalFieldsComponent; | ||
if (newStrategy) { | ||
AdditionalFieldsComponent = newStrategy.AdditionalFieldsComponent; | ||
if (newStrategy.initializationMethod) { | ||
newStrategy.initializationMethod(command); | ||
} | ||
} | ||
command.strategy = strategy; | ||
if (onStrategyChange && newStrategy) { | ||
onStrategyChange(command, newStrategy); | ||
} | ||
this.setState({ currentStrategy: strategy, AdditionalFieldsComponent }); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...ipts/modules/cloudfoundry/src/deploymentStrategy/strategies/redblack/AdditionalFields.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import * as React from 'react'; | ||
import { set } from 'lodash'; | ||
|
||
import { HelpField, IDeploymentStrategyAdditionalFieldsProps } from '@spinnaker/core'; | ||
import { IRedBlackCommand } from 'cloudfoundry/deploymentStrategy/strategies/redblack/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} | ||
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 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 old server group" /> | ||
</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> | ||
</div> | ||
); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...ipts/modules/cloudfoundry/src/deploymentStrategy/strategies/redblack/redblack.strategy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { IServerGroupCommand } from '@spinnaker/core'; | ||
|
||
export interface IRedBlackCommand extends IServerGroupCommand { | ||
maxRemainingAsgs: number; | ||
delayBeforeDisableSec: number; | ||
delayBeforeScaleDownSec: number; | ||
rollback: { | ||
onFailure: boolean; | ||
}; | ||
scaleDown: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters