-
Notifications
You must be signed in to change notification settings - Fork 51
/
extractor.go
52 lines (40 loc) · 1.42 KB
/
extractor.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
package cnimonitor
import (
"errors"
"fmt"
"strings"
"go.aporeto.io/trireme-lib/common"
"go.aporeto.io/trireme-lib/policy"
)
// KubernetesMetadataExtractor is a systemd based metadata extractor
func KubernetesMetadataExtractor(event *common.EventInfo) (*policy.PURuntime, error) {
if event.NS == "" {
return nil, errors.New("namespace path is required when using cni")
}
runtimeTags := policy.NewTagStore()
for _, tag := range event.Tags {
parts := strings.Split(tag, "=")
if len(parts) != 2 {
return nil, fmt.Errorf("invalid tag: %s", tag)
}
runtimeTags.AppendKeyValue("@usr:"+parts[0], parts[1])
}
runtimeIps := policy.ExtendedMap{"bridge": "0.0.0.0/0"}
return policy.NewPURuntime(event.Name, 1, "", runtimeTags, runtimeIps, common.LinuxProcessPU, nil), nil
}
// DockerMetadataExtractor is a systemd based metadata extractor
func DockerMetadataExtractor(event *common.EventInfo) (*policy.PURuntime, error) {
if event.NS == "" {
return nil, errors.New("namespace path is required when using cni")
}
runtimeTags := policy.NewTagStore()
for _, tag := range event.Tags {
parts := strings.Split(tag, "=")
if len(parts) != 2 {
return nil, fmt.Errorf("invalid tag: %s", tag)
}
runtimeTags.AppendKeyValue("@usr:"+parts[0], parts[1])
}
runtimeIps := policy.ExtendedMap{"bridge": "0.0.0.0/0"}
return policy.NewPURuntime(event.Name, 0, event.NS, runtimeTags, runtimeIps, common.ContainerPU, nil), nil
}