-
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(core/managed): add Managed Resources section to app config, allo…
…w opting out (#7409)
- Loading branch information
Erik Munson
committed
Sep 18, 2019
1 parent
d0ceddb
commit f8267a4
Showing
10 changed files
with
217 additions
and
0 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
7 changes: 7 additions & 0 deletions
7
app/scripts/modules/core/src/application/config/managedResources/ManagedResourceConfig.less
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,7 @@ | ||
.ManagedResourceConfig .rainbow-icon { | ||
text-shadow: 0px 1px 4px rgba(0, 0, 0, 0.5); | ||
} | ||
|
||
.ManagedResourceConfig .paused-warning { | ||
background-color: var(--color-warning-light); | ||
} |
142 changes: 142 additions & 0 deletions
142
app/scripts/modules/core/src/application/config/managedResources/ManagedResourceConfig.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,142 @@ | ||
import * as React from 'react'; | ||
import { module } from 'angular'; | ||
import { react2angular } from 'react2angular'; | ||
import * as ReactGA from 'react-ga'; | ||
import * as classNames from 'classnames'; | ||
|
||
import { NgReact } from 'core/reactShims'; | ||
import { Application } from 'core/application'; | ||
import { useData } from 'core/presentation'; | ||
import { ValidationMessage } from 'core/validation'; | ||
import { Spinner } from 'core/widgets'; | ||
import { ManagedReader, ManagedWriter } from 'core/managed'; | ||
|
||
import './ManagedResourceConfig.less'; | ||
|
||
const { useState, useEffect } = React; | ||
const { ButtonBusyIndicator } = NgReact; | ||
|
||
export interface IManagedResourceConfigProps { | ||
application: Application; | ||
} | ||
|
||
const logClick = (label: string, application: string) => | ||
ReactGA.event({ | ||
category: 'Managed Resource Config', | ||
action: `${label} clicked`, | ||
label: application, | ||
}); | ||
|
||
const getManagementStatus = (paused: boolean) => { | ||
if (paused) { | ||
return ( | ||
<> | ||
<div className="sp-padding-m sp-margin-m-bottom paused-warning"> | ||
<i className="fa fa-pause sp-margin-xs-right" /> <b>Continuous management of resources is paused.</b> | ||
</div> | ||
<p className="sp-margin-l-bottom"> | ||
Spinnaker is configured to continuously manage some of this application's resources, but management has been | ||
paused. When resumed, Spinnaker will take action to make each resource match its declarative configuration. | ||
</p> | ||
</> | ||
); | ||
} else { | ||
return ( | ||
<> | ||
<p> | ||
<span className="rainbow-icon">🌈</span> <b>Spinnaker is continuously managing some resources.</b> | ||
</p> | ||
<p className="sp-margin-l-bottom"> | ||
If you need to temporarily stop Spinnaker from managing resources — for example, if something is wrong and | ||
manual intervention is required — you can pause management and resume it later. Pausing affects all managed | ||
resources within this application. | ||
</p> | ||
</> | ||
); | ||
} | ||
}; | ||
|
||
const ManagedResourceConfig = ({ application }: IManagedResourceConfigProps) => { | ||
const [pausePending, setPausePending] = useState(false); | ||
const [pauseFailed, setPauseFailed] = useState(false); | ||
const [paused, setPaused] = useState(false); | ||
const { status: vetoStatus, result: vetos, refresh } = useData(() => ManagedReader.getApplicationVetos(), [], []); | ||
|
||
const isRejected = vetos && vetos.includes(application.name); | ||
useEffect(() => { | ||
setPaused(isRejected); | ||
}, [isRejected]); | ||
|
||
const pauseManagement = () => { | ||
setPausePending(true); | ||
setPauseFailed(false); | ||
logClick('Pause Management', application.name); | ||
|
||
ManagedWriter.pauseResourceManagement(application.name) | ||
.then(() => setPaused(true)) | ||
.catch(() => setPauseFailed(true)) | ||
.finally(() => setPausePending(false)); | ||
}; | ||
|
||
const resumeManagement = () => { | ||
setPausePending(true); | ||
setPauseFailed(false); | ||
logClick('Resume Management', application.name); | ||
|
||
ManagedWriter.resumeResourceManagement(application.name) | ||
.then(() => setPaused(false)) | ||
.catch(() => setPauseFailed(true)) | ||
.finally(() => setPausePending(false)); | ||
}; | ||
|
||
if (['NONE', 'PENDING'].includes(vetoStatus)) { | ||
return <Spinner size="medium" />; | ||
} else if (vetoStatus === 'REJECTED') { | ||
return ( | ||
<div className="alert alert-danger"> | ||
Something went wrong.{' '} | ||
<button className="btn btn-link" onClick={refresh}> | ||
Try again | ||
</button> | ||
</div> | ||
); | ||
} | ||
|
||
const iconClass = paused ? 'fa-play' : 'fa-pause'; | ||
|
||
return ( | ||
<div className="ManagedResourceConfig"> | ||
{getManagementStatus(paused)} | ||
<button | ||
className="btn btn-primary" | ||
disabled={pausePending} | ||
onClick={paused ? resumeManagement : pauseManagement} | ||
type="button" | ||
> | ||
{(!pausePending && <i className={classNames('fa sp-margin-xs-right', iconClass)} />) || <ButtonBusyIndicator />}{' '} | ||
{paused ? 'Resume Management' : 'Pause Management'} | ||
</button> | ||
{pauseFailed && ( | ||
<div className="sp-margin-l-top"> | ||
<ValidationMessage type="error" message="Saving failed." /> | ||
</div> | ||
)} | ||
<div className="color-text-caption sp-margin-l-top"> | ||
Not sure what this means?{' '} | ||
<a | ||
target="_blank" | ||
onClick={() => logClick('Documentation', application.name)} | ||
href="https://www.spinnaker.io/reference/managed-delivery" | ||
> | ||
Check out our documentation | ||
</a> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export const MANAGED_RESOURCE_CONFIG = 'spinnaker.core.managedResourceConfig.component'; | ||
module(MANAGED_RESOURCE_CONFIG, []).component( | ||
'managedResourceConfig', | ||
react2angular(ManagedResourceConfig, ['application']), | ||
); |
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
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,23 @@ | ||
import { IPromise } from 'angular'; | ||
|
||
import { API } from 'core/api'; | ||
|
||
export interface IManagedApplicationSummary { | ||
hasManagedResources: boolean; | ||
} | ||
|
||
export class ManagedReader { | ||
public static getApplicationSummary(app: string): IPromise<IManagedApplicationSummary> { | ||
return API.one('managed') | ||
.one('application', app) | ||
.get(); | ||
} | ||
|
||
public static getApplicationVetos(): IPromise<string[]> { | ||
return API.one('managed') | ||
.all('vetos') | ||
.one('ApplicationVeto') | ||
.all('rejections') | ||
.get(); | ||
} | ||
} |
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,21 @@ | ||
import { IPromise } from 'angular'; | ||
|
||
import { API } from 'core/api'; | ||
|
||
export class ManagedWriter { | ||
public static pauseResourceManagement(application: string): IPromise<void> { | ||
return API.one('managed') | ||
.all('vetos') | ||
.one('ApplicationVeto') | ||
.data({ application, optedOut: true }) | ||
.post(); | ||
} | ||
|
||
public static resumeResourceManagement(application: string): IPromise<void> { | ||
return API.one('managed') | ||
.all('vetos') | ||
.one('ApplicationVeto') | ||
.data({ application, optedOut: false }) | ||
.post(); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export * from './ManagedReader'; | ||
export * from './ManagedWriter'; | ||
export * from './ManagedResourceDetailsIndicator'; | ||
export * from './managedResourceDetailsIndicator.component'; |
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