forked from netobserv/flowlogs-pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
61 lines (55 loc) · 1.56 KB
/
config.go
File metadata and controls
61 lines (55 loc) · 1.56 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
package informers
import (
"github.com/netobserv/flowlogs-pipeline/pkg/api"
"github.com/netobserv/flowlogs-pipeline/pkg/config"
"github.com/netobserv/flowlogs-pipeline/pkg/pipeline/transform/kubernetes/cni"
)
var (
cniPlugins = map[string]cni.Plugin{
api.OVN: &cni.OVNPlugin{},
}
multus = cni.MultusHandler{}
udn = cni.UDNHandler{}
)
type Config struct {
managedCNI []string
secondaryNetworks []api.SecondaryNetwork
hasMultus bool
hasUDN bool
trackedKinds []string
}
func NewConfig(cfg *api.NetworkTransformKubeConfig) Config {
c := Config{
managedCNI: cfg.ManagedCNI,
secondaryNetworks: cfg.SecondaryNetworks,
trackedKinds: cfg.TrackedKinds,
}
if c.managedCNI == nil {
c.managedCNI = []string{api.OVN}
}
c.secondaryNetworks = cfg.SecondaryNetworks
for _, netConfig := range cfg.SecondaryNetworks {
for index := range netConfig.Index {
if multus.Manages(index) {
c.hasMultus = true
}
if udn.Manages(index) {
c.hasUDN = true
}
}
}
return c
}
func (k *Config) BuildSecondaryNetworkKeys(flow config.GenericMap, rule *api.K8sRule) []cni.SecondaryNetKey {
return buildSecondaryNetworkKeys(flow, rule, k.secondaryNetworks, k.hasMultus, k.hasUDN)
}
func buildSecondaryNetworkKeys(flow config.GenericMap, rule *api.K8sRule, secNet []api.SecondaryNetwork, hasMultus, hasUDN bool) []cni.SecondaryNetKey {
var keys []cni.SecondaryNetKey
if hasMultus {
keys = append(keys, multus.BuildKeys(flow, rule, secNet)...)
}
if hasUDN {
keys = append(keys, udn.BuildKeys(flow, rule)...)
}
return keys
}