forked from Qihoo360/wayne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
60 lines (52 loc) · 1.71 KB
/
log.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
package log
import (
"k8s.io/api/core/v1"
"github.com/Qihoo360/wayne/src/backend/controllers/base"
"github.com/Qihoo360/wayne/src/backend/models"
"github.com/Qihoo360/wayne/src/backend/resources/log"
"github.com/Qihoo360/wayne/src/backend/util/hack"
"github.com/Qihoo360/wayne/src/backend/util/logs"
)
type KubeLogController struct {
base.APIController
}
func (c *KubeLogController) URLMapping() {
c.Mapping("List", c.List)
}
func (c *KubeLogController) Prepare() {
// Check administration
c.APIController.Prepare()
methodActionMap := map[string]string{
"List": models.PermissionRead,
}
_, method := c.GetControllerAndAction()
c.PreparePermission(methodActionMap, method, models.PermissionTypeKubePod)
}
// @Title log
// @Description pod logs
// @Param tailLines query int true "log tail lines."
// @Param cluster path string true "cluster name."
// @Param namespace path string true "namespace name."
// @Param pod path string true "pod name."
// @Param container path string true "container name."
// @Success 200 {object} "log text" success
// @router /:pod/containers/:container/namespaces/:namespace/clusters/:cluster [get]
func (c *KubeLogController) List() {
tailLines := c.GetIntParamFromQuery("tailLines")
cluster := c.Ctx.Input.Param(":cluster")
namespace := c.Ctx.Input.Param(":namespace")
pod := c.Ctx.Input.Param(":pod")
container := c.Ctx.Input.Param(":container")
opt := &v1.PodLogOptions{
Container: container,
TailLines: &tailLines,
}
cli := c.Client(cluster)
result, err := log.GetLogsByPod(cli, namespace, pod, opt)
if err != nil {
logs.Info("get kubernetes log by pod error.", cluster, namespace, pod, err)
c.HandleError(err)
return
}
c.Success(hack.String(result))
}