forked from tchen0123/supergiant
/
pods_controller.go
113 lines (108 loc) · 2.47 KB
/
pods_controller.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package ui
import (
"net/http"
"github.com/supergiant/supergiant/pkg/client"
)
func NewPod(sg *client.Client, w http.ResponseWriter, r *http.Request) error {
m := map[string]interface{}{
"kube_name": "",
"kind": "Pod",
"namespace": "default",
"name": "",
"resource": map[string]interface{}{
"metadata": map[string]interface{}{
"labels": map[string]string{},
},
"spec": map[string]interface{}{
"containers": []map[string]interface{}{
{
"name": "jenkins",
"image": "jenkins",
"ports": []map[string]interface{}{
{
"containerPort": 8080,
},
},
},
},
},
},
}
// case "service":
// m = map[string]interface{}{
// "kube_name": "",
// "kind": "Service",
// "namespace": "default",
// "name": "",
// "template": map[string]interface{}{
// "spec": map[string]interface{}{
// "type": "NodePort",
// "selector": map[string]string{},
// "ports": []map[string]interface{}{
// {
// "name": "jenkins",
// "port": 8080,
// },
// },
// },
// },
// }
// default:
// m = map[string]interface{}{
// "kube_name": "",
// "kind": "",
// "namespace": "default",
// "name": "",
// "template": map[string]interface{}{},
// }
// }
return renderTemplate(sg, w, "new", map[string]interface{}{
"title": "Pods",
"formAction": "/ui/pods",
"model": m,
})
}
func ListPods(sg *client.Client, w http.ResponseWriter, r *http.Request) error {
fields := []map[string]interface{}{
{
"title": "Name",
"type": "field_value",
"field": "name",
},
{
"title": "Kube name",
"type": "field_value",
"field": "kube_name",
},
{
"title": "Namespace",
"type": "field_value",
"field": "namespace",
},
}
return renderTemplate(sg, w, "kube_resources", map[string]interface{}{
"title": "Pods",
"uiBasePath": "/ui/pods",
"apiBasePath": "/api/v0/kube_resources?filter.kind=Pod",
"fields": fields,
"showNewLink": true,
"showStatusCol": true,
"actionPaths": map[string]string{
"Edit": "/ui/pods/{{ ID }}/edit",
},
"batchActionPaths": map[string]map[string]string{
"Delete": map[string]string{
"method": "DELETE",
"relativePath": "",
},
"Start": map[string]string{
"method": "POST",
"relativePath": "/start",
},
"Stop": map[string]string{
"method": "POST",
"relativePath": "/stop",
},
},
})
}