forked from viliproject/vili
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nodes.go
66 lines (56 loc) · 1.35 KB
/
nodes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package api
import (
"fmt"
"net/http"
"net/url"
"github.com/airware/vili/errors"
"github.com/airware/vili/kube"
"github.com/airware/vili/server"
"gopkg.in/labstack/echo.v1"
)
var nodesQueryParams = []string{"labelSelector", "fieldSelector"}
func nodesHandler(c *echo.Context) error {
env := c.Param("env")
query := &url.Values{}
for _, param := range nodesQueryParams {
val := c.Request().URL.Query().Get(param)
if val != "" {
query.Add(param, val)
}
}
resp, err := kube.Nodes.List(env, query)
if err != nil {
return err
}
return c.JSON(http.StatusOK, resp)
}
func nodeHandler(c *echo.Context) error {
env := c.Param("env")
node := c.Param("node")
resp, status, err := kube.Nodes.Get(env, node)
if err != nil {
return err
}
if status != nil {
return c.JSON(http.StatusOK, status)
}
return c.JSON(http.StatusOK, resp)
}
func nodeStateEditHandler(c *echo.Context) error {
env := c.Param("env")
node := c.Param("node")
state := c.Param("state")
var unschedulable bool
if state == "enable" {
unschedulable = false
} else if state == "disable" {
unschedulable = true
} else {
return server.ErrorResponse(c, errors.BadRequestError(fmt.Sprintf("Invalid state for node: %s", state)))
}
resp, err := kube.Nodes.PatchUnschedulable(env, node, unschedulable)
if err != nil {
return err
}
return c.JSON(http.StatusOK, resp)
}