Skip to content

Commit 413b39a

Browse files
authored
feat: Node cordon button in the UI (#573)
* feat: ui node cordon button * improve visuals
1 parent c3a8491 commit 413b39a

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

web/api/webrpc/cluster.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,3 +393,19 @@ func (a *WebRPC) ClusterNodeInfo(ctx context.Context, id int64) (*MachineInfo, e
393393

394394
return &summaries[0], nil
395395
}
396+
397+
func (a *WebRPC) Cordon(ctx context.Context, id int64) error {
398+
_, err := a.deps.DB.Exec(ctx, `UPDATE harmony_machines SET unschedulable = $1 WHERE id = $2`, true, id)
399+
if err != nil {
400+
return xerrors.Errorf("cordon failed: %w", err)
401+
}
402+
return nil
403+
}
404+
405+
func (a *WebRPC) Uncordon(ctx context.Context, id int64) error {
406+
_, err := a.deps.DB.Exec(ctx, `UPDATE harmony_machines SET unschedulable = $1 WHERE id = $2`, false, id)
407+
if err != nil {
408+
return xerrors.Errorf("uncordon failed: %w", err)
409+
}
410+
return nil
411+
}

web/static/cluster-machines.mjs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ customElements.define('cluster-machines', class ClusterMachines extends LitEleme
2424
this.detailed = e.target.checked;
2525
}
2626

27+
async _cordon(id) {
28+
await RPCCall('Cordon', [id]);
29+
this.loadData();
30+
}
31+
32+
async _uncordon(id) {
33+
await RPCCall('Uncordon', [id]);
34+
this.loadData();
35+
}
36+
2737
render() {
2838
return html`
2939
<link
@@ -65,7 +75,7 @@ customElements.define('cluster-machines', class ClusterMachines extends LitEleme
6575
}
6676
<th>Last Contact</th>
6777
<th>Uptime</th>
68-
<th>Schedulable</th>
78+
<th>Scheduling</th>
6979
${
7080
this.detailed
7181
? html`<th>Tasks Supported</th>
@@ -99,11 +109,22 @@ customElements.define('cluster-machines', class ClusterMachines extends LitEleme
99109
}
100110
<td>${item.SinceContact}</td>
101111
<td>${item.Uptime}</td>
112+
102113
<td>
114+
<a href="javascript:void(0)" @click=${() => this._cordon(item.ID)} style="${item.Unschedulable ? 'opacity: 0.3; pointer-events: none;' : ''}" >
115+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-pause" viewBox="0 0 16 16">
116+
<path d="M6 3.5a.5.5 0 0 1 .5.5v8a.5.5 0 0 1-1 0V4a.5.5 0 0 1 .5-.5m4 0a.5.5 0 0 1 .5.5v8a.5.5 0 0 1-1 0V4a.5.5 0 0 1 .5-.5"/>
117+
</svg>
118+
</a>
119+
<a href="javascript:void(0)" @click=${() => this._uncordon(item.ID)} style="${!item.Unschedulable ? 'opacity: 0.3; pointer-events: none;' : ''}">
120+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-play" viewBox="0 0 16 16">
121+
<path d="M10.804 8 5 4.633v6.734zm.792-.696a.802.802 0 0 1 0 1.392l-6.363 3.692C4.713 12.69 4 12.345 4 11.692V4.308c0-.653.713-.998 1.233-.696z"/>
122+
</svg>
123+
</a>
103124
${!item.Unschedulable
104-
? html`<span class="success">ok</span>`
125+
? html`<span class="success" style="white-space: nowrap;">enabled</span>`
105126
: html`
106-
<span class="warning">
127+
<span class="warning" style="white-space: nowrap;">
107128
${
108129
item.RunningTasks > 0
109130
? html`cordoned (${item.RunningTasks} tasks still running)`

0 commit comments

Comments
 (0)