-
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.
feat(google): support stateful MIG operations (#7196)
* feat(google): add gce stateful mig feature flag * feat(google): instance template disk UI adjustments * feat(google): support stateful disk operations * fix(google): couple of misc. fixes to stateful MIG UI
- Loading branch information
1 parent
d51b0d4
commit f340b02
Showing
12 changed files
with
291 additions
and
77 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
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,10 @@ | ||
export interface IGceDisk { | ||
boot: boolean; | ||
deviceName: string; | ||
index: number; | ||
initializeParams: { | ||
diskSizeGb: number; | ||
diskType: string; | ||
sourceImage: string; | ||
}; | ||
} |
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
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
93 changes: 93 additions & 0 deletions
93
app/scripts/modules/google/src/serverGroup/details/ServerGroupDiskDescriptions.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,93 @@ | ||
import { module } from 'angular'; | ||
|
||
import { get, last } from 'lodash'; | ||
import * as React from 'react'; | ||
import { react2angular } from 'react2angular'; | ||
|
||
import { Application } from '@spinnaker/core'; | ||
|
||
import { IGceDisk, IGceServerGroup } from '../../domain'; | ||
import { StatefulMIGService } from './stateful/StatefulMIGService'; | ||
import { MarkDiskStatefulButton } from './stateful/MarkDiskStatefulButton'; | ||
import { UpdateBootImageButton } from './stateful/UpdateBootImageButton'; | ||
|
||
interface IServerGroupDiskDescriptionProps { | ||
application: Application; | ||
serverGroup: IGceServerGroup; | ||
} | ||
|
||
class ServerGroupDiskDescriptions extends React.Component<IServerGroupDiskDescriptionProps> { | ||
public render() { | ||
const { application, serverGroup } = this.props; | ||
const disks: IGceDisk[] = get(serverGroup, 'launchConfig.instanceTemplate.properties.disks', []); | ||
const statefulOperationsEnabled: boolean = StatefulMIGService.statefulMigsEnabled(); | ||
const canUpdateBootImage = | ||
statefulOperationsEnabled && disks.some(disk => StatefulMIGService.isDiskStateful(disk.deviceName, serverGroup)); | ||
|
||
return disks.map(disk => { | ||
if (disk.boot) { | ||
return ( | ||
<React.Fragment key={disk.deviceName}> | ||
<dt> | ||
Boot Disk | ||
{canUpdateBootImage && ( | ||
<UpdateBootImageButton | ||
application={application} | ||
bootImage={ServerGroupDiskDescriptions.getDiskImageName(disk)} | ||
serverGroup={serverGroup} | ||
/> | ||
)} | ||
</dt> | ||
<dd>{ServerGroupDiskDescriptions.getDiskTypeLabel(disk)}</dd> | ||
<dd>{ServerGroupDiskDescriptions.getDiskImageLabel(disk)}</dd> | ||
</React.Fragment> | ||
); | ||
} | ||
return ( | ||
<React.Fragment key={disk.deviceName}> | ||
<dt> | ||
Disk | ||
{statefulOperationsEnabled && ( | ||
<MarkDiskStatefulButton | ||
application={application} | ||
deviceName={disk.deviceName} | ||
serverGroup={serverGroup} | ||
/> | ||
)} | ||
</dt> | ||
<dd>{ServerGroupDiskDescriptions.getDiskTypeLabel(disk)}</dd> | ||
<dd>{ServerGroupDiskDescriptions.getDiskImageLabel(disk)}</dd> | ||
</React.Fragment> | ||
); | ||
}); | ||
} | ||
|
||
private static translateDiskType = (disk: IGceDisk): string => { | ||
const diskType = disk.initializeParams.diskType; | ||
if (diskType === 'pd-ssd') { | ||
return 'Persistent SSD'; | ||
} else if (diskType === 'local-ssd') { | ||
return 'Local SSD'; | ||
} else { | ||
return 'Persistent Std'; | ||
} | ||
}; | ||
|
||
private static getDiskTypeLabel = (disk: IGceDisk): string => { | ||
return `${ServerGroupDiskDescriptions.translateDiskType(disk)}: ${disk.initializeParams.diskSizeGb}GB`; | ||
}; | ||
|
||
private static getDiskImageLabel = (disk: IGceDisk): string => { | ||
return `Image: ${ServerGroupDiskDescriptions.getDiskImageName(disk)}`; | ||
}; | ||
|
||
private static getDiskImageName = (disk: IGceDisk): string => { | ||
return last(get(disk, 'initializeParams.sourceImage', '').split('/')); | ||
}; | ||
} | ||
|
||
export const GCE_SERVER_GROUP_DISK_DESCRIPTIONS = 'spinnaker.gce.serverGroupDiskDescriptions'; | ||
module(GCE_SERVER_GROUP_DISK_DESCRIPTIONS, []).component( | ||
'gceServerGroupDiskDescriptions', | ||
react2angular(ServerGroupDiskDescriptions, ['application', 'serverGroup']), | ||
); |
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
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
40 changes: 40 additions & 0 deletions
40
app/scripts/modules/google/src/serverGroup/details/stateful/MarkDiskStatefulButton.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,40 @@ | ||
import * as React from 'react'; | ||
|
||
import { Application, ReactInjector } from '@spinnaker/core'; | ||
|
||
import { StatefulMIGService } from 'google/serverGroup/details/stateful/StatefulMIGService'; | ||
import { IGceServerGroup } from 'google/domain'; | ||
|
||
interface IMarkDiskStatefulButtonProps { | ||
application: Application; | ||
deviceName: string; | ||
serverGroup: IGceServerGroup; | ||
} | ||
|
||
export function MarkDiskStatefulButton({ application, deviceName, serverGroup }: IMarkDiskStatefulButtonProps) { | ||
function openConfirmationModal(): void { | ||
ReactInjector.confirmationModalService.confirm({ | ||
account: serverGroup.account, | ||
askForReason: true, | ||
buttonText: 'Mark as stateful', | ||
header: `Really mark disk ${deviceName} as stateful?`, | ||
submitMethod: () => { | ||
return StatefulMIGService.markDiskStateful(application.name, deviceName, serverGroup); | ||
}, | ||
taskMonitorConfig: { | ||
application, | ||
title: 'Marking disk as stateful', | ||
}, | ||
}); | ||
} | ||
|
||
if (StatefulMIGService.isDiskStateful(deviceName, serverGroup)) { | ||
return <span> (Marked as Stateful)</span>; | ||
} | ||
|
||
return ( | ||
<button className="btn-link" onClick={() => openConfirmationModal()}> | ||
Mark as Stateful | ||
</button> | ||
); | ||
} |
49 changes: 49 additions & 0 deletions
49
app/scripts/modules/google/src/serverGroup/details/stateful/StatefulMIGService.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,49 @@ | ||
import { has } from 'lodash'; | ||
|
||
import { SETTINGS, TaskExecutor } from '@spinnaker/core'; | ||
|
||
import { IGceServerGroup } from 'google/domain'; | ||
|
||
export class StatefulMIGService { | ||
public static markDiskStateful(applicationName: string, deviceName: string, serverGroup: IGceServerGroup) { | ||
return TaskExecutor.executeTask({ | ||
application: applicationName, | ||
description: 'Mark disk as stateful', | ||
job: [ | ||
{ | ||
cloudProvider: 'gce', | ||
credentials: serverGroup.account, | ||
deviceName, | ||
region: serverGroup.region, | ||
serverGroupName: serverGroup.name, | ||
type: 'setStatefulDisk', | ||
}, | ||
], | ||
}); | ||
} | ||
|
||
public static statefullyUpdateBootDisk(applicationName: string, bootImage: string, serverGroup: IGceServerGroup) { | ||
return TaskExecutor.executeTask({ | ||
application: applicationName, | ||
description: 'Statefully update boot disk image', | ||
job: [ | ||
{ | ||
bootImage, | ||
cloudProvider: 'gce', | ||
credentials: serverGroup.account, | ||
region: serverGroup.region, | ||
serverGroupName: serverGroup.name, | ||
type: 'statefullyUpdateBootImage', | ||
}, | ||
], | ||
}); | ||
} | ||
|
||
public static isDiskStateful(deviceName: string, serverGroup: IGceServerGroup): boolean { | ||
return has(serverGroup, ['statefulPolicy', 'preservedState', 'disks', deviceName]); | ||
} | ||
|
||
public static statefulMigsEnabled(): boolean { | ||
return SETTINGS.feature.gceStatefulMigsEnabled; | ||
} | ||
} |
Oops, something went wrong.