-
Notifications
You must be signed in to change notification settings - Fork 906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(provider/kubernetes): v2 resize modal #4274
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { copy, equals, IController, module } from 'angular' | ||
import { IModalInstanceService } 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: IModalInstanceService, | ||
private serverGroupWriter: ServerGroupWriter, | ||
private application: Application) { | ||
'ngInject'; | ||
this.taskMonitor = taskMonitorBuilder.buildTaskMonitor({ | ||
title: `Resizing ${this.serverGroup.name}`, | ||
application: application, | ||
modalInstance: $uibModalInstance, | ||
} as any); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh that would explain it - I thought typescript was mishandling the optional properties. |
||
|
||
this.current = this.serverGroup.capacity; | ||
this.command = { | ||
capacity: copy(this.current), | ||
} as IResizeCommand; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can initialize There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
} | ||
|
||
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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nothing is going to go wrong here, since the input type is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah good catch |
||
</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--> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this is everywhere...but can't you put There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure thing - why do you prefer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The hidden button feels a little hacky. Or not. Who knows. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why, but the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh. That's probably why it's being used. Now I know. |
||
<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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seemed OK to add since it's in clouddriver's server group model.