diff --git a/app/scripts/modules/core/src/domain/IServerGroup.ts b/app/scripts/modules/core/src/domain/IServerGroup.ts index d3e2ca3922b..31d4e6a5712 100644 --- a/app/scripts/modules/core/src/domain/IServerGroup.ts +++ b/app/scripts/modules/core/src/domain/IServerGroup.ts @@ -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 { @@ -18,6 +19,7 @@ export interface IServerGroup { asg?: IAsg; buildInfo?: any; category?: string; + capacity?: ICapacity; cloudProvider: string; cluster: string; clusterEntityTags?: IEntityTags[]; diff --git a/app/scripts/modules/kubernetes/v2/kubernetes.v2.module.ts b/app/scripts/modules/kubernetes/v2/kubernetes.v2.module.ts index da39192bce1..016521a96fa 100644 --- a/app/scripts/modules/kubernetes/v2/kubernetes.v2.module.ts +++ b/app/scripts/modules/kubernetes/v2/kubernetes.v2.module.ts @@ -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$/); @@ -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, @@ -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', } }); diff --git a/app/scripts/modules/kubernetes/v2/serverGroup/IKubernetesServerGroup.ts b/app/scripts/modules/kubernetes/v2/serverGroup/details/IKubernetesServerGroup.ts similarity index 92% rename from app/scripts/modules/kubernetes/v2/serverGroup/IKubernetesServerGroup.ts rename to app/scripts/modules/kubernetes/v2/serverGroup/details/IKubernetesServerGroup.ts index 19949f7fa23..0e9c29caf7e 100644 --- a/app/scripts/modules/kubernetes/v2/serverGroup/IKubernetesServerGroup.ts +++ b/app/scripts/modules/kubernetes/v2/serverGroup/details/IKubernetesServerGroup.ts @@ -5,4 +5,5 @@ export interface IKubernetesServerGroup extends IServerGroup { displayName: string; apiVersion: string; disabled: boolean; + manifest: any; } diff --git a/app/scripts/modules/kubernetes/v2/serverGroup/details.controller.ts b/app/scripts/modules/kubernetes/v2/serverGroup/details/details.controller.ts similarity index 80% rename from app/scripts/modules/kubernetes/v2/serverGroup/details.controller.ts rename to app/scripts/modules/kubernetes/v2/serverGroup/details/details.controller.ts index 71de28c67ac..01d08ce07a4 100644 --- a/app/scripts/modules/kubernetes/v2/serverGroup/details.controller.ts +++ b/app/scripts/modules/kubernetes/v2/serverGroup/details/details.controller.ts @@ -1,4 +1,5 @@ import { IController, module } from 'angular'; +import { IModalService } from 'angular-ui-bootstrap'; import { Application, @@ -24,6 +25,7 @@ class KubernetesServerGroupDetailsController implements IController { constructor(serverGroup: IServerGroupFromStateParams, public app: Application, + private $uibModal: IModalService, private serverGroupReader: ServerGroupReader) { 'ngInject'; @@ -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 { @@ -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; }); } diff --git a/app/scripts/modules/kubernetes/v2/serverGroup/details.html b/app/scripts/modules/kubernetes/v2/serverGroup/details/details.html similarity index 100% rename from app/scripts/modules/kubernetes/v2/serverGroup/details.html rename to app/scripts/modules/kubernetes/v2/serverGroup/details/details.html diff --git a/app/scripts/modules/kubernetes/v2/serverGroup/details/resize/resize.controller.ts b/app/scripts/modules/kubernetes/v2/serverGroup/details/resize/resize.controller.ts new file mode 100644 index 00000000000..62ee4a44b51 --- /dev/null +++ b/app/scripts/modules/kubernetes/v2/serverGroup/details/resize/resize.controller.ts @@ -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); diff --git a/app/scripts/modules/kubernetes/v2/serverGroup/details/resize/resize.html b/app/scripts/modules/kubernetes/v2/serverGroup/details/resize/resize.html new file mode 100644 index 00000000000..bcb990a5c02 --- /dev/null +++ b/app/scripts/modules/kubernetes/v2/serverGroup/details/resize/resize.html @@ -0,0 +1,54 @@ +