Skip to content

Commit e2e0eb0

Browse files
committed
Add scaling functionality for Machine Deployments
- Introduced ScaleButtons component to handle scaling up and down of machine deployments. - Updated MachineDeploymentsTable to include available replicas and scale buttons. - Implemented scaleHandler to process scaling requests via POST method. - Added error handling for invalid requests in scaleHandler. - Updated server routing to include the new scale endpoint. Signed-off-by: Artiom Diomin <artiom@kubermatic.com>
1 parent c906669 commit e2e0eb0

3 files changed

Lines changed: 323 additions & 85 deletions

File tree

pkg/dashboard/components.templ

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,29 @@ templ NodesTable(nodes []node) {
115115
</div>
116116
}
117117

118+
templ ScaleButtons(md machineDeployment) {
119+
<div class="d-flex align-items-center gap-2">
120+
<form method="POST" action="/scale">
121+
<input type="hidden" name="namespace" value={ md.Namespace }/>
122+
<input type="hidden" name="name" value={ md.Name }/>
123+
<input type="hidden" name="direction" value="down"/>
124+
<button
125+
type="submit"
126+
class="btn btn-outline-secondary btn-sm"
127+
disabled?={ md.Replicas == 0 }
128+
title="Scale down"
129+
>−</button>
130+
</form>
131+
<span class="fw-semibold">{ fmt.Sprintf("%d", md.Replicas) }</span>
132+
<form method="POST" action="/scale">
133+
<input type="hidden" name="namespace" value={ md.Namespace }/>
134+
<input type="hidden" name="name" value={ md.Name }/>
135+
<input type="hidden" name="direction" value="up"/>
136+
<button type="submit" class="btn btn-outline-primary btn-sm" title="Scale up">+</button>
137+
</form>
138+
</div>
139+
}
140+
118141
templ MachineDeploymentsTable(machineDeployments []machineDeployment) {
119142
<div class="mt-2">
120143
<table class="table">
@@ -124,6 +147,8 @@ templ MachineDeploymentsTable(machineDeployments []machineDeployment) {
124147
<th scope="col">Name</th>
125148
<th scope="col">Namespace</th>
126149
<th scope="col">Replicas</th>
150+
<th scope="col">Available</th>
151+
<th scope="col">Scale</th>
127152
<th scope="col">Kubelet</th>
128153
<th scope="col">Age</th>
129154
</tr>
@@ -138,7 +163,9 @@ templ MachineDeploymentsTable(machineDeployments []machineDeployment) {
138163
</td>
139164
<td><strong>{ md.Name }</strong></td>
140165
<td>{ md.Namespace }</td>
141-
<td>{ fmt.Sprintf("%d / %d", md.AvailableReplicas, md.Replicas) }</td>
166+
<td>{ fmt.Sprintf("%d", md.Replicas) }</td>
167+
<td>{ fmt.Sprintf("%d", md.AvailableReplicas) }</td>
168+
<td>@ScaleButtons(md)</td>
142169
<td>{ md.Kubelet }</td>
143170
<td>{ md.Age.String() }</td>
144171
</tr>

0 commit comments

Comments
 (0)