Skip to content

Commit

Permalink
feat(provider/kubernetes): v2 resize modal (#4279)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwander authored Oct 17, 2017
1 parent aed2797 commit f2bb3f8
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/scripts/modules/core/src/domain/IServerGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IInstance } from './IInstance';
import { IInstanceCounts } from './IInstanceCounts';
import { ITask } from './ITask';
import { IMoniker } from 'core/naming/IMoniker';
import { ICapacity } from 'core/serverGroup';

// remnant from legacy code
export interface IAsg {
Expand All @@ -18,6 +19,7 @@ export interface IServerGroup {
asg?: IAsg;
buildInfo?: any;
category?: string;
capacity?: ICapacity;
cloudProvider: string;
cluster: string;
clusterEntityTags?: IEntityTags[];
Expand Down
6 changes: 4 additions & 2 deletions app/scripts/modules/kubernetes/v2/kubernetes.v2.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { KUBERNETES_V2_SERVER_GROUP_COMMAND_BUILDER } from './serverGroup/server
import { KUBERNETES_MANIFEST_CTRL } from './manifest/wizard/manifestWizard.controller';
import { KUBERNETES_MANIFEST_ENTRY } from './manifest/wizard/manifestEntry.component';
import { KUBERNETES_V2_SERVER_GROUP_TRANSFORMER } from './serverGroup/serverGroupTransformer.service';
import { KUBERNETES_V2_SERVER_GROUP_DETAILS_CTRL } from './serverGroup/details.controller';
import { KUBERNETES_V2_SERVER_GROUP_DETAILS_CTRL } from './serverGroup/details/details.controller';
import { KUBERNETES_V2_SERVER_GROUP_RESIZE_CTRL } from './serverGroup/details/resize/resize.controller';

// load all templates into the $templateCache
const templates = require.context('kubernetes', true, /\.html$/);
Expand All @@ -24,6 +25,7 @@ module(KUBERNETES_V2_MODULE, [
KUBERNETES_V2_SERVER_GROUP_COMMAND_BUILDER,
KUBERNETES_V2_SERVER_GROUP_TRANSFORMER,
KUBERNETES_V2_SERVER_GROUP_DETAILS_CTRL,
KUBERNETES_V2_SERVER_GROUP_RESIZE_CTRL,
KUBERNETES_MANIFEST_BASIC_SETTINGS,
KUBERNETES_MANIFEST_COMMAND_BUILDER,
KUBERNETES_MANIFEST_CTRL,
Expand All @@ -40,7 +42,7 @@ module(KUBERNETES_V2_MODULE, [
cloneServerGroupController: 'kubernetesManifestWizardCtrl',
cloneServerGroupTemplateUrl: require('./manifest/wizard/manifestWizard.html'),
transformer: 'kubernetesV2ServerGroupTransformer',
detailsTemplateUrl: require('./serverGroup/details.html'),
detailsTemplateUrl: require('./serverGroup/details/details.html'),
detailsController: 'kubernetesV2ServerGroupDetailsCtrl',
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export interface IKubernetesServerGroup extends IServerGroup {
displayName: string;
apiVersion: string;
disabled: boolean;
manifest: any;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IController, module } from 'angular';
import { IModalService } from 'angular-ui-bootstrap';

import {
Application,
Expand All @@ -24,6 +25,7 @@ class KubernetesServerGroupDetailsController implements IController {

constructor(serverGroup: IServerGroupFromStateParams,
public app: Application,
private $uibModal: IModalService,
private serverGroupReader: ServerGroupReader) {
'ngInject';

Expand All @@ -34,7 +36,19 @@ class KubernetesServerGroupDetailsController implements IController {
}

public canResizeServerGroup(): boolean {
return false; // will change with daemon set
return this.serverGroup.kind !== 'DaemonSet';
}

public resizeServerGroup(): void {
this.$uibModal.open({
templateUrl: require('./resize/resize.html'),
controller: 'kubernetesV2ServerGroupResizeCtrl',
controllerAs: 'ctrl',
resolve: {
serverGroup: this.serverGroup,
application: this.app
}
});
}

private autoClose(): void {
Expand All @@ -55,6 +69,7 @@ class KubernetesServerGroupDetailsController implements IController {
.getServerGroup(this.app.name, fromParams.accountId, fromParams.region, fromParams.name)
.then((serverGroupDetails: IServerGroup) => {
this.serverGroup = this.transformServerGroup(serverGroupDetails);
this.serverGroup.account = fromParams.accountId;
this.state.loading = false;
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { copy, equals, IController, module } from 'angular'
import { IModalServiceInstance } from 'angular-ui-bootstrap';

import {
Application,
ICapacity,
SERVER_GROUP_WRITER,
ServerGroupWriter,
TASK_MONITOR_BUILDER,
TaskMonitor,
TaskMonitorBuilder
} from '@spinnaker/core';
import { IKubernetesServerGroup } from '../IKubernetesServerGroup';

interface IResizeCommand {
capacity: ICapacity;
reason: string;
}

class KubernetesServerGroupResizeController implements IController {
public taskMonitor: TaskMonitor;
public command: IResizeCommand;
public current: ICapacity;
public verification = {
verified: false
};

constructor(public serverGroup: IKubernetesServerGroup,
taskMonitorBuilder: TaskMonitorBuilder,
private $uibModalInstance: IModalServiceInstance,
private serverGroupWriter: ServerGroupWriter,
private application: Application) {
'ngInject';
this.taskMonitor = taskMonitorBuilder.buildTaskMonitor({
title: `Resizing ${this.serverGroup.name}`,
application: application,
modalInstance: $uibModalInstance,
});

this.current = this.serverGroup.capacity;
this.command = {
capacity: copy(this.current),
reason: null,
};
}

public isValid(): boolean {
return this.verification.verified && this.command.capacity.desired >= 0 && !equals(this.command.capacity, this.current);
}

public cancel(): void {
this.$uibModalInstance.dismiss();
};

public resize(): void {
this.taskMonitor.submit(() => {
const payload = {
capacity: this.command.capacity,
serverGroupName: this.serverGroup.name,
account: this.serverGroup.account,
region: this.serverGroup.region,
interestingHealthProviderNames: ['KubernetesPod'],
reason: this.command.reason,
};

return this.serverGroupWriter.resizeServerGroup(this.serverGroup, this.application, payload);
});
}
}

export const KUBERNETES_V2_SERVER_GROUP_RESIZE_CTRL = 'spinnaker.kubernetes.v2.serverGroup.details.resize.controller';

module(KUBERNETES_V2_SERVER_GROUP_RESIZE_CTRL, [
SERVER_GROUP_WRITER,
TASK_MONITOR_BUILDER,
])
.controller('kubernetesV2ServerGroupResizeCtrl', KubernetesServerGroupResizeController);
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<div modal-page class="confirmation-modal">
<task-monitor monitor="ctrl.taskMonitor"></task-monitor>
<form role="form" name="resizeForm">
<modal-close dismiss="$dismiss()"></modal-close>
<div class="modal-header">
<h3>Resize {{ctrl.serverGroup.kind}} {{ctrl.serverGroup.displayName}}</h3>
</div>
<div class="modal-body confirmation-modal">
<div class="form-horizontal">
<div class="form-group form-inline">
<div class="col-md-3 sm-label-right">
Current
</div>
<div class="col-md-3">
<div class="input-group">
<input type="number"
class="form-control input-sm highlight-pristine"
ng-model="ctrl.current.desired"
readonly/>
<span class="input-group-addon">pod<span ng-if="ctrl.current.desired !== 1">s</span></span>
</div>
</div>
</div>
<div class="form-group form-inline">
<div class="col-md-3 sm-label-right">
Desired
</div>
<div class="col-md-3">
<div class="input-group">
<input type="number"
class="form-control input-sm highlight-pristine"
ng-model="ctrl.command.capacity.desired"
min="0"
required/>
<span class="input-group-addon">pod<span ng-if="ctrl.command.capacity.desired !== 1">s</span></span>
</div>
</div>
</div>
</div>
<task-reason command="ctrl.command"></task-reason>
</div>
<div class="modal-footer">
<user-verification account="ctrl.serverGroup.account" verification="ctrl.verification"></user-verification>
<button type="submit" ng-click="ctrl.resize()" style="display:none"></button> <!-- Allows form submission via enter keypress-->
<button class="btn btn-default" ng-click="ctrl.cancel()">Cancel</button>
<button type="submit"
class="btn btn-primary"
ng-click="ctrl.resize()"
ng-disabled="!ctrl.isValid() || !resizeForm.$valid">
Submit
</button>
</div>
</form>
</div>

0 comments on commit f2bb3f8

Please sign in to comment.