Add config ability to rollback changes on kube
This commit is contained in:
parent
2b59432414
commit
9695c98e5f
15 changed files with 237 additions and 63 deletions
|
@ -1,5 +1,5 @@
|
|||
import {Component, Inject, OnDestroy } from 'ng-metadata/core';
|
||||
import {AngularPollChannel, PollHandle} from "../../services/services.types";
|
||||
import { Input, Component, Inject, OnDestroy } from 'ng-metadata/core';
|
||||
import { AngularPollChannel, PollHandle } from "../../services/services.types";
|
||||
const templateUrl = require('./kube-deploy-modal.component.html');
|
||||
const styleUrl = require('./kube-deploy-modal.css');
|
||||
|
||||
|
@ -24,22 +24,25 @@ const DEPLOYMENT_POLL_SLEEPTIME = 5000; /* 5 seconds */
|
|||
styleUrls: [ styleUrl ],
|
||||
})
|
||||
export class KubeDeployModalComponent implements OnDestroy {
|
||||
@Input('<') public loadedConfig;
|
||||
private state
|
||||
: 'loadingDeployments'
|
||||
| 'readyToDeploy'
|
||||
| 'deployingConfiguration'
|
||||
| 'cyclingDeployments'
|
||||
| 'deployed'
|
||||
| 'error';
|
||||
| 'error'
|
||||
| 'rolledBackWarning' = 'loadingDeployments';
|
||||
private errorMessage: string;
|
||||
private offerRollback: boolean;
|
||||
private deploymentsStatus: DeploymentStatus[] = [];
|
||||
private deploymentsCycled: number = 0;
|
||||
private onDestroyListeners: Function[] = [];
|
||||
private rollingBackStatus
|
||||
: 'none'
|
||||
| 'offer'
|
||||
| 'rolling' = 'none';
|
||||
|
||||
constructor(@Inject('ApiService') private ApiService, @Inject('AngularPollChannel') private AngularPollChannel: AngularPollChannel) {
|
||||
this.state = 'loadingDeployments';
|
||||
|
||||
ApiService.scGetNumDeployments().then(resp => {
|
||||
this.deploymentsStatus = resp.items.map(dep => ({ name: dep.metadata.name, numPods: dep.spec.replicas }));
|
||||
this.state = 'readyToDeploy';
|
||||
|
@ -80,7 +83,7 @@ export class KubeDeployModalComponent implements OnDestroy {
|
|||
|
||||
watchDeployments(): void {
|
||||
this.deploymentsStatus.forEach(deployment => {
|
||||
const pollChannel = this.AngularPollChannel.create( {
|
||||
const pollChannel = this.AngularPollChannel.create({
|
||||
// Have to mock the scope object for the poll channel since we're calling into angular1 code
|
||||
// We register the onDestroy function to be called later when this object is destroyed
|
||||
'$on': (_, onDestruction) => { this.onDestroyListeners.push(onDestruction) }
|
||||
|
@ -113,14 +116,38 @@ export class KubeDeployModalComponent implements OnDestroy {
|
|||
continue_callback(false);
|
||||
deployment.message = deploymentRollout.message;
|
||||
this.errorMessage = `Could not cycle deployments: ${deploymentRollout.message}`;
|
||||
this.offerRollback = true;
|
||||
|
||||
// Only offer rollback if we loaded/populated a config. (Can't rollback an initial setup)
|
||||
if (this.loadedConfig) {
|
||||
this.rollingBackStatus = 'offer';
|
||||
this.errorMessage = `Could not cycle deployments: ${deploymentRollout.message}`;
|
||||
}
|
||||
}
|
||||
}).catch(err => {
|
||||
continue_callback(false);
|
||||
this.state = 'error';
|
||||
this.errorMessage = `Could not cycle the deployments with the new configuration. Error: ${err.toString()}`;
|
||||
this.offerRollback = true;
|
||||
this.errorMessage = `Could not cycle the deployments with the new configuration. Error: ${err.toString()}\
|
||||
Would you like to rollback the deployment to its previous state?`;
|
||||
// Only offer rollback if we loaded/populated a config. (Can't rollback an initial setup)
|
||||
if (this.loadedConfig) {
|
||||
this.rollingBackStatus = 'offer';
|
||||
this.errorMessage = `Could not get deployment information for: ${deployment}`;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
rollbackDeployments(): void {
|
||||
this.rollingBackStatus = 'rolling';
|
||||
const deploymentNames: string[] = this.deploymentsStatus.map(dep => dep.name);
|
||||
|
||||
this.ApiService.scRollbackDeployments({ deploymentNames }).then(() => {
|
||||
this.state = 'rolledBackWarning';
|
||||
this.rollingBackStatus = 'none';
|
||||
}).catch(err => {
|
||||
this.rollingBackStatus = 'none';
|
||||
this.state = 'error';
|
||||
this.errorMessage = `Could not cycle the deployments back to their previous states. Please contact support: ${err.toString()}`;
|
||||
})
|
||||
}
|
||||
}
|
Reference in a new issue