-
Notifications
You must be signed in to change notification settings - Fork 7
/
handler.go
53 lines (49 loc) · 1.33 KB
/
handler.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 cniserver
import (
"encoding/json"
"io"
"net/http"
"github.com/containernetworking/cni/pkg/skel"
)
func (s *server) PodCreated(w http.ResponseWriter, req *http.Request) {
bs, err := io.ReadAll(req.Body)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
_, _ = w.Write([]byte(err.Error()))
}
args := skel.CmdArgs{}
err = json.Unmarshal(bs, &args)
log.Info().Msgf("cni called create with args: %+v", args)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
_, _ = w.Write([]byte(err.Error()))
}
err = s.CmdAdd(&args)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
_, _ = w.Write([]byte(err.Error()))
}
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("ok"))
}
func (s *server) PodDeleted(w http.ResponseWriter, req *http.Request) {
bs, err := io.ReadAll(req.Body)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
_, _ = w.Write([]byte(err.Error()))
}
args := skel.CmdArgs{}
err = json.Unmarshal(bs, &args)
log.Info().Msgf("cni called delete with args: %+v", args)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
_, _ = w.Write([]byte(err.Error()))
}
err = s.CmdDelete(&args)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
_, _ = w.Write([]byte(err.Error()))
}
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("ok"))
}