-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhttpserver.go
More file actions
324 lines (302 loc) · 12.9 KB
/
httpserver.go
File metadata and controls
324 lines (302 loc) · 12.9 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
package apiserver
import (
"github.com/gin-gonic/gin"
"minik8s/pkg/api"
"minik8s/pkg/apiserver/handlers"
)
type HttpServer interface {
Run(addr string) (err error)
BindHandlers()
}
func NewHttpServer() HttpServer {
return &httpServer{
router: gin.Default(),
}
}
type httpServer struct {
router *gin.Engine
}
func (h httpServer) Run(addr string) (err error) {
return h.router.Run(addr)
}
func (h httpServer) BindHandlers() {
// Clear all
h.router.GET(api.ClearAllURL, handlers.HandleClearAll)
/*--------------------- Pod ---------------------*/
// Create a Pod
// POST /api/pods/
h.router.POST(api.PodsURL, handlers.HandlePostPod)
// Update/Replace the specified Pod
// PUT /api/pods/{name}
h.router.PUT(api.PodURL, handlers.HandlePutPod)
// Delete a Pod
// DELETE /api/pods/{name}
h.router.DELETE(api.PodURL, handlers.HandleDeletePod)
// Read the specified Pod
// GET /api/pods/{name}
h.router.GET(api.PodURL, handlers.HandleGetPod)
// List or watch objects of kind Pod
// GET /api/pods
h.router.GET(api.PodsURL, handlers.HandleGetPods)
// Watch changes to an object of kind Pod
// GET /api/watch/pods/{name}
h.router.GET(api.WatchPodURL, handlers.HandleWatchPod)
// Watch individual changes to a list of Pod
// GET /api/watch/pods
h.router.GET(api.WatchPodsURL, handlers.HandleWatchPods)
/*--------------------- Pod Status ---------------------*/
// Read status of the specified Pod
// GET /api/pods/{name}/status
h.router.GET(api.PodStatusURL, handlers.HandleGetPodStatus)
// Replace status of the specified Pod
// PUT /api/pods/{name}/status
h.router.PUT(api.PodStatusURL, handlers.HandlePutPodStatus)
/*--------------------- Node ---------------------*/
// Create a Node
// POST /api/nodes
h.router.POST(api.NodesURL, handlers.HandlePostNode)
// Update/Replace the specified Node
// PUT /api/nodes/{name}
h.router.PUT(api.NodeURL, handlers.HandlePutNode)
// Delete a Node
// DELETE /api/nodes/{name}
h.router.DELETE(api.NodeURL, handlers.HandleDeleteNode)
// Delete all Nodes
// DELETE /api/nodes
h.router.DELETE(api.NodesURL, handlers.HandleDeleteNodes)
// Read the specified Node
// GET /api/nodes/{name}
h.router.GET(api.NodeURL, handlers.HandleGetNode)
// List or watch objects of kind Node
// GET /api/nodes
h.router.GET(api.NodesURL, handlers.HandleGetNodes)
// Watch changes to an object of kind Node
// GET /api/watch/nodes/{name}
h.router.GET(api.WatchNodeURL, handlers.HandleWatchNode)
// Watch individual changes to a list of Node
// GET /api/watch/nodes
h.router.GET(api.WatchNodesURL, handlers.HandleWatchNodes)
/*--------------------- Node Status ---------------------*/
// Read status of the specified Node
// GET /api/nodes/{name}/status
h.router.GET(api.NodeStatusURL, handlers.HandleGetNodeStatus)
// Update/Replace status of the specified Node
// PUT /api/nodes/{name}/status
h.router.PUT(api.NodeStatusURL, handlers.HandlePutNodeStatus)
/*--------------------- Service ---------------------*/
// Create a Service
// POST /api/services
h.router.POST(api.ServicesURL, handlers.HandlePostService)
// Update/Replace the specified Service
// PUT /api/services/{name}
h.router.PUT(api.ServiceURL, handlers.HandlePutService)
// Delete a Service
// DELETE /api/services/{name}
h.router.DELETE(api.ServiceURL, handlers.HandleDeleteService)
// Read the specified Service
// GET /api/services/{name}
h.router.GET(api.ServiceURL, handlers.HandleGetService)
// List or watch objects of kind Service
// GET /api/services
h.router.GET(api.ServicesURL, handlers.HandleGetServices)
// Watch changes to an object of kind Service
// GET /api/watch/services/{name}
h.router.GET(api.WatchServiceURL, handlers.HandleWatchService)
// Watch individual changes to a list of Service
// GET /api/watch/services
h.router.GET(api.WatchServicesURL, handlers.HandleWatchServices)
/*--------------------- Service Status ---------------------*/
// Read status of the specified Service
// GET /api/services/{name}/status
h.router.GET(api.ServiceStatusURL, handlers.HandleGetServiceStatus)
// Replace status of the specified Service
// PUT /api/services/{name}/status
h.router.PUT(api.ServiceStatusURL, handlers.HandlePutServiceStatus)
/*--------------------- ReplicaSet ---------------------*/
// Create a ReplicaSet
// POST /api/replicasets
h.router.POST(api.ReplicaSetsURL, handlers.HandlePostReplicaSet)
// Update/Replace the specified ReplicaSet
// PUT /api/replicasets/{name}
h.router.PUT(api.ReplicaSetURL, handlers.HandlePutReplicaSet)
// Delete a ReplicaSet
// DELETE /api/replicasets/{name}
h.router.DELETE(api.ReplicaSetURL, handlers.HandleDeleteReplicaSet)
// Read the specified ReplicaSet
// GET /api/replicasets/{name}
h.router.GET(api.ReplicaSetURL, handlers.HandleGetReplicaSet)
// List or watch objects of kind ReplicaSet
// GET /api/replicasets
h.router.GET(api.ReplicaSetsURL, handlers.HandleGetReplicaSets)
// Watch changes to an object of kind ReplicaSet
// GET /api/watch/replicasets/{name}
h.router.GET(api.WatchReplicaSetURL, handlers.HandleWatchReplicaSet)
// Watch individual changes to a list of ReplicaSet
// GET /api/watch/replicasets
h.router.GET(api.WatchReplicaSetsURL, handlers.HandleWatchReplicaSets)
/*--------------------- ReplicaSet Status ---------------------*/
// Read status of the specified ReplicaSet
// GET /api/replicasets/{name}/status
h.router.GET(api.ReplicaSetStatusURL, handlers.HandleGetReplicaSetStatus)
// Replace status of the specified ReplicaSet
// PUT /api/replicasets/{name}/status
h.router.PUT(api.ReplicaSetStatusURL, handlers.HandlePutReplicaSetStatus)
/*--------------------- HorizontalPodAutoscaler ---------------------*/
// Create a HorizontalPodAutoscaler
// POST /api/hpa
h.router.POST(api.HorizontalPodAutoscalersURL, handlers.HandlePostHorizontalPodAutoscaler)
// Update/Replace the specified HorizontalPodAutoscaler
// PUT /api/hpa/{name}
h.router.PUT(api.HorizontalPodAutoscalerURL, handlers.HandlePutHorizontalPodAutoscaler)
// Delete a HorizontalPodAutoscaler
// DELETE /api/hpa/{name}
h.router.DELETE(api.HorizontalPodAutoscalerURL, handlers.HandleDeleteHorizontalPodAutoscaler)
// Read the specified HorizontalPodAutoscaler
// GET /api/hpa/{name}
h.router.GET(api.HorizontalPodAutoscalerURL, handlers.HandleGetHorizontalPodAutoscaler)
// List or watch objects of kind HorizontalPodAutoscaler
// GET /api/hpa
h.router.GET(api.HorizontalPodAutoscalersURL, handlers.HandleGetHorizontalPodAutoscalers)
// Watch changes to an object of kind HorizontalPodAutoscaler
// GET /api/watch/hpa/{name}
h.router.GET(api.WatchHorizontalPodAutoscalerURL, handlers.HandleWatchHorizontalPodAutoscaler)
// Watch individual changes to a list of HorizontalPodAutoscaler
// GET /api/watch/hpa
h.router.GET(api.WatchHorizontalPodAutoscalersURL, handlers.HandleWatchHorizontalPodAutoscalers)
/*--------------------- HorizontalPodAutoscaler Status ---------------------*/
// Read status of the specified HorizontalPodAutoscaler
// GET /api/hpa/{name}/status
h.router.GET(api.HorizontalPodAutoscalerStatusURL, handlers.HandleGetHorizontalPodAutoscalerStatus)
// Replace status of the specified HorizontalPodAutoscaler
// PUT /api/hpa/{name}/status
h.router.PUT(api.HorizontalPodAutoscalerStatusURL, handlers.HandlePutHorizontalPodAutoscalerStatus)
/*--------------------- Job ---------------------*/
// Create a Job
// POST /api/jobs
h.router.POST(api.JobsURL, handlers.HandlePostJob)
// Update/Replace the specified Job
// PUT /api/jobs/{name}
h.router.PUT(api.JobURL, handlers.HandlePutJob)
// Delete a Job
// DELETE /api/jobs/{name}
h.router.DELETE(api.JobURL, handlers.HandleDeleteJob)
// Read the specified Job
// GET /api/jobs/{name}
h.router.GET(api.JobURL, handlers.HandleGetJob)
// List or watch objects of kind Job
// GET /api/jobs
h.router.GET(api.JobsURL, handlers.HandleGetJobs)
// Watch changes to an object of kind Job
// GET /api/watch/jobs/{name}
h.router.GET(api.WatchJobURL, handlers.HandleWatchJob)
// Watch individual changes to a list of Job
// GET /api/watch/jobs
h.router.GET(api.WatchJobsURL, handlers.HandleWatchJobs)
/*--------------------- Job Status ---------------------*/
// Read status of the specified Job
// GET /api/jobs/{name}/status
h.router.GET(api.JobStatusURL, handlers.HandleGetJobStatus)
// Replace status of the specified Job
// PUT /api/jobs/{name}/status
h.router.PUT(api.JobStatusURL, handlers.HandlePutJobStatus)
/*--------------------- Heartbeat ---------------------*/
// Create a Heartbeat
// POST /api/heartbeats
h.router.POST(api.HeartbeatsURL, handlers.HandlePostHeartbeat)
// Update/Replace the specified Heartbeat
// PUT /api/heartbeats/{name}
h.router.PUT(api.HeartbeatURL, handlers.HandlePutHeartbeat)
// Delete a Heartbeat
// DELETE /api/heartbeats/{name}
h.router.DELETE(api.HeartbeatURL, handlers.HandleDeleteHeartbeat)
// Read the specified Heartbeat
// GET /api/heartbeats/{name}
h.router.GET(api.HeartbeatURL, handlers.HandleGetHeartbeat)
// List or watch objects of kind Heartbeat
// GET /api/heartbeats
h.router.GET(api.HeartbeatsURL, handlers.HandleGetHeartbeats)
// Watch changes to an object of kind Heartbeat
// GET /api/watch/heartbeats/{name}
h.router.GET(api.WatchHeartbeatURL, handlers.HandleWatchHeartbeat)
// Watch individual changes to a list of Heartbeat
// GET /api/watch/heartbeats
h.router.GET(api.WatchHeartbeatsURL, handlers.HandleWatchHeartbeats)
/*--------------------- Heartbeat Status ---------------------*/
// Read status of the specified Heartbeat
// GET /api/heartbeats/{name}/status
h.router.GET(api.HeartbeatStatusURL, handlers.HandleGetHeartbeatStatus)
// Replace status of the specified Heartbeat
// PUT /api/heartbeats/{name}/status
h.router.PUT(api.HeartbeatStatusURL, handlers.HandlePutHeartbeatStatus)
/*--------------------- DNS ---------------------*/
// Create a DNS
// POST /api/dns
h.router.POST(api.DNSsURL, handlers.HandlePostDNS)
// Update/Replace the specified DNS
// PUT /api/dns/{name}
h.router.PUT(api.DNSURL, handlers.HandlePutDNS)
// Delete a DNS
// DELETE /api/dns/{name}
h.router.DELETE(api.DNSURL, handlers.HandleDeleteDNS)
// Read the specified DNS
// GET /api/dns/{name}
h.router.GET(api.DNSURL, handlers.HandleGetDNS)
// List or watch objects of kind DNS
// GET /api/dns
h.router.GET(api.DNSsURL, handlers.HandleGetDNSs)
// Watch changes to an object of kind DNS
// GET /api/watch/dns/{name}
h.router.GET(api.WatchDNSURL, handlers.HandleWatchDNS)
// Watch individual changes to a list of DNS
// GET /api/watch/dns
h.router.GET(api.WatchDNSsURL, handlers.HandleWatchDNSs)
/*--------------------- DNS Status ---------------------*/
// Read status of the specified DNS
// GET /api/dns/{name}/status
h.router.GET(api.DNSStatusURL, handlers.HandleGetDNSStatus)
// Replace status of the specified DNS
// PUT /api/dns/{name}/status
h.router.PUT(api.DNSStatusURL, handlers.HandlePutDNSStatus)
/*--------------------- Serverless ---------------------*/
/*--------------------- Function Template ---------------------*/
// Create a Function Template
// POST /api/funcs/template
h.router.POST(api.FuncTemplatesURL, handlers.HandlePostFuncTemplate)
// Update/Replace the specified Function Template
// PUT /api/funcs/template/{name}
h.router.PUT(api.FuncTemplateURL, handlers.HandlePutFuncTemplate)
// Delete a Function Template
// DELETE /api/funcs/template/{name}
h.router.DELETE(api.FuncTemplateURL, handlers.HandleDeleteFuncTemplate)
// Read the specified Function Template
// GET /api/funcs/template/{name}
h.router.GET(api.FuncTemplateURL, handlers.HandleGetFuncTemplate)
// List or watch objects of kind Function Template
// GET /api/funcs/template
h.router.GET(api.FuncTemplatesURL, handlers.HandleGetFuncTemplates)
// Watch changes to an object of kind FuncTemplate
// GET /api/watch/funcs/template/{name}
h.router.GET(api.WatchFuncTemplateURL, handlers.HandleWatchFuncTemplate)
// Watch individual changes to a list of FuncTemplate
// GET /api/watch/funcs/template
h.router.GET(api.WatchFuncTemplatesURL, handlers.HandleWatchFuncTemplates)
/*--------------------- FuncTemplate Status ---------------------*/
// Read status of the specified FuncTemplate
// GET /api/funcs/template/{name}/status
h.router.GET(api.FuncTemplateStatusURL, handlers.HandleGetFuncTemplateStatus)
// Replace status of the specified FuncTemplate
// PUT /api/funcs/template/{name}/status
h.router.PUT(api.FuncTemplateStatusURL, handlers.HandlePutFuncTemplateStatus)
/*--------------------- Function Instance (For User) ---------------------*/
// Create a Function Instance (run function)
// return id (instance func id)
// POST /api/funcs/{name}
h.router.POST(api.FuncCallURL, handlers.HandleFuncCall)
// Get the function result
// GET /api/funcs/{id}
h.router.GET(api.FuncResultURL, handlers.HandleGetResult)
/*--------------------- Function Instance (For Impl) ---------------------*/
// Create a Function Instance (run function), id is the instance func id called by user
// PUT /api/funcs/{name}/{id}
h.router.PUT(api.FuncInsideCallURL, handlers.HandleInsideFuncCall)
}