forked from viliproject/vili
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pods.go
53 lines (44 loc) · 993 Bytes
/
pods.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
package api
import (
"net/http"
"net/url"
"github.com/airware/vili/kube"
"gopkg.in/labstack/echo.v1"
)
var podsQueryParams = []string{"labelSelector", "fieldSelector"}
func podsHandler(c *echo.Context) error {
env := c.Param("env")
query := &url.Values{}
for _, param := range podsQueryParams {
val := c.Request().URL.Query().Get(param)
if val != "" {
query.Add(param, val)
}
}
resp, _, err := kube.Pods.List(env, query)
if err != nil {
return err
}
return c.JSON(http.StatusOK, resp)
}
func podHandler(c *echo.Context) error {
env := c.Param("env")
pod := c.Param("pod")
resp, status, err := kube.Pods.Get(env, pod)
if err != nil {
return err
}
if status != nil {
return c.JSON(http.StatusOK, status)
}
return c.JSON(http.StatusOK, resp)
}
func podDeleteHandler(c *echo.Context) error {
env := c.Param("env")
pod := c.Param("pod")
resp, _, err := kube.Pods.Delete(env, pod)
if err != nil {
return err
}
return c.JSON(http.StatusOK, resp)
}