/
types.go
73 lines (60 loc) · 2.12 KB
/
types.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
package cni
import (
"net/http"
"github.com/containernetworking/cni/pkg/types"
)
// serverRunDir is the default directory for CNIServer runtime files
const serverRunDir string = "/var/run/ovn-kubernetes/cni/"
const serverSocketName string = "ovn-cni-server.sock"
const serverSocketPath string = serverRunDir + "/" + serverSocketName
const serverTCPAddress string = "127.0.0.1:3996"
// Explicit type for CNI commands the server handles
type command string
// CNIAdd is the command representing add operation for a new pod
const CNIAdd command = "ADD"
// CNIUpdate is the command representing update operation for an existing pod
const CNIUpdate command = "UPDATE"
// CNIDel is the command representing delete operation on a pod that is to be torn down
const CNIDel command = "DEL"
// Request sent to the Server by the OVN CNI plugin
type Request struct {
// CNI environment variables, like CNI_COMMAND and CNI_NETNS
Env map[string]string `json:"env,omitempty"`
// CNI configuration passed via stdin to the CNI plugin
Config []byte `json:"config,omitempty"`
}
// PodRequest structure built from Request which is passed to the
// handler function given to the Server at creation time
type PodRequest struct {
// The CNI command of the operation
Command command
// kubernetes namespace name
PodNamespace string
// kubernetes pod name
PodName string
// kubernetes container ID
SandboxID string
// kernel network namespace path
Netns string
// Interface name to be configured
IfName string
// CNI conf obtained from stdin conf
CNIConf *types.NetConf
// Channel for returning the operation result to the Server
Result chan *PodResult
}
// PodResult of a PodRequest sent through the PodRequest's Result channel.
type PodResult struct {
// Response to be returned to the OVN CNI plugin on success
Response []byte
// Error to be returned to the OVN CNI plugin on failure
Err error
}
type cniRequestFunc func(request *PodRequest) ([]byte, error)
// Server object that listens for JSON-marshaled Request objects
// on a private root-only Unix domain socket.
type Server struct {
http.Server
requestFunc cniRequestFunc
rundir string
}