Skip to content

Commit 5403281

Browse files
authored
Merge pull request #25 from persys-dev/codex/add-node-drain,-taint,-and-management-commands
Add node management APIs: drain/undrain, taint/untaint, labels and automatic workload relocation
2 parents 1460d27 + 279d3ac commit 5403281

14 files changed

Lines changed: 4165 additions & 379 deletions

File tree

persys-gateway/controllers/scheduler.controller.go

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,112 @@ func (c *ProwController) GetNodeHandler() gin.HandlerFunc {
185185
}
186186
}
187187

188+
type nodeReasonPayload struct {
189+
Reason string `json:"reason"`
190+
}
191+
192+
type nodeTaintPayload struct {
193+
Key string `json:"key" binding:"required"`
194+
Value string `json:"value"`
195+
Effect string `json:"effect"`
196+
}
197+
198+
type nodeLabelPayload struct {
199+
Key string `json:"key" binding:"required"`
200+
Value string `json:"value"`
201+
}
202+
203+
func (c *ProwController) DrainNodeHandler() gin.HandlerFunc {
204+
return func(ctx *gin.Context) {
205+
var body nodeReasonPayload
206+
_ = ctx.ShouldBindJSON(&body)
207+
resp, err := c.prowService.DrainNode(ctx.Request.Context(), c.resolveClusterID(ctx), c.resolveSessionKey(ctx), c.resolveWorkloadKey(ctx), &controlv1.DrainNodeRequest{NodeId: ctx.Param("id"), Reason: body.Reason})
208+
if err != nil {
209+
c.writeProxyError(ctx, err)
210+
return
211+
}
212+
writeProtoJSON(ctx, http.StatusOK, resp)
213+
}
214+
}
215+
216+
func (c *ProwController) UndrainNodeHandler() gin.HandlerFunc {
217+
return func(ctx *gin.Context) {
218+
var body nodeReasonPayload
219+
_ = ctx.ShouldBindJSON(&body)
220+
resp, err := c.prowService.UndrainNode(ctx.Request.Context(), c.resolveClusterID(ctx), c.resolveSessionKey(ctx), c.resolveWorkloadKey(ctx), &controlv1.UndrainNodeRequest{NodeId: ctx.Param("id"), Reason: body.Reason})
221+
if err != nil {
222+
c.writeProxyError(ctx, err)
223+
return
224+
}
225+
writeProtoJSON(ctx, http.StatusOK, resp)
226+
}
227+
}
228+
229+
func (c *ProwController) TaintNodeHandler() gin.HandlerFunc {
230+
return func(ctx *gin.Context) {
231+
var body nodeTaintPayload
232+
if err := ctx.ShouldBindJSON(&body); err != nil {
233+
ctx.JSON(http.StatusBadRequest, gin.H{"error": "invalid taint payload"})
234+
return
235+
}
236+
req := &controlv1.TaintNodeRequest{NodeId: ctx.Param("id"), Taint: &controlv1.NodeTaint{Key: body.Key, Value: body.Value, Effect: body.Effect}}
237+
resp, err := c.prowService.TaintNode(ctx.Request.Context(), c.resolveClusterID(ctx), c.resolveSessionKey(ctx), c.resolveWorkloadKey(ctx), req)
238+
if err != nil {
239+
c.writeProxyError(ctx, err)
240+
return
241+
}
242+
writeProtoJSON(ctx, http.StatusOK, resp)
243+
}
244+
}
245+
246+
func (c *ProwController) UntaintNodeHandler() gin.HandlerFunc {
247+
return func(ctx *gin.Context) {
248+
var body nodeTaintPayload
249+
if err := ctx.ShouldBindJSON(&body); err != nil {
250+
ctx.JSON(http.StatusBadRequest, gin.H{"error": "invalid taint payload"})
251+
return
252+
}
253+
resp, err := c.prowService.UntaintNode(ctx.Request.Context(), c.resolveClusterID(ctx), c.resolveSessionKey(ctx), c.resolveWorkloadKey(ctx), &controlv1.UntaintNodeRequest{NodeId: ctx.Param("id"), Key: body.Key, Effect: body.Effect})
254+
if err != nil {
255+
c.writeProxyError(ctx, err)
256+
return
257+
}
258+
writeProtoJSON(ctx, http.StatusOK, resp)
259+
}
260+
}
261+
262+
func (c *ProwController) SetNodeLabelHandler() gin.HandlerFunc {
263+
return func(ctx *gin.Context) {
264+
var body nodeLabelPayload
265+
if err := ctx.ShouldBindJSON(&body); err != nil {
266+
ctx.JSON(http.StatusBadRequest, gin.H{"error": "invalid label payload"})
267+
return
268+
}
269+
resp, err := c.prowService.SetNodeLabel(ctx.Request.Context(), c.resolveClusterID(ctx), c.resolveSessionKey(ctx), c.resolveWorkloadKey(ctx), &controlv1.SetNodeLabelRequest{NodeId: ctx.Param("id"), Key: body.Key, Value: body.Value})
270+
if err != nil {
271+
c.writeProxyError(ctx, err)
272+
return
273+
}
274+
writeProtoJSON(ctx, http.StatusOK, resp)
275+
}
276+
}
277+
278+
func (c *ProwController) DeleteNodeLabelHandler() gin.HandlerFunc {
279+
return func(ctx *gin.Context) {
280+
var body nodeLabelPayload
281+
if err := ctx.ShouldBindJSON(&body); err != nil {
282+
ctx.JSON(http.StatusBadRequest, gin.H{"error": "invalid label payload"})
283+
return
284+
}
285+
resp, err := c.prowService.DeleteNodeLabel(ctx.Request.Context(), c.resolveClusterID(ctx), c.resolveSessionKey(ctx), c.resolveWorkloadKey(ctx), &controlv1.DeleteNodeLabelRequest{NodeId: ctx.Param("id"), Key: body.Key})
286+
if err != nil {
287+
c.writeProxyError(ctx, err)
288+
return
289+
}
290+
writeProtoJSON(ctx, http.StatusOK, resp)
291+
}
292+
}
293+
188294
func (c *ProwController) ClusterMetricsHandler() gin.HandlerFunc {
189295
return func(ctx *gin.Context) {
190296
clusterID := c.resolveClusterID(ctx)

0 commit comments

Comments
 (0)