Skip to content

Commit

Permalink
Add network flows export support to OpenShift
Browse files Browse the repository at this point in the history
  • Loading branch information
rcarrillocruz committed Mar 5, 2021
1 parent 1ac7415 commit d2c0846
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
11 changes: 11 additions & 0 deletions bindata/network/ovn-kubernetes/006-ovs-node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ spec:
trap quit SIGTERM
# Don't need to worry about restoring flows; this can only change if we've rebooted
tail --pid=$BASHPID -F /host/var/log/openvswitch/ovs-vswitchd.log /host/var/log/openvswitch/ovsdb-server.log &
{{ if .EnableExportNetworkFlows }}
{{ if .EnableNetFlow }}
ovs-vsctl -- --id=@netflow create netflow targets={{ .NetFlowCollectors }} -- set bridge br-int netflow=@netflow
{{ end }}
{{ if .EnableSFlow }}
ovs-vsctl -- --id=@sflow create sflow agent=ovn-k8s-mp0 targets={{ .SFlowCollectors }} header=128 sampling=64 polling=10 -- set bridge br-int sflow=@sflow
{{ end }}
{{ if .EnableIPFIX }}
ovs-vsctl -- --id=@ipfix create ipfix targets={{ .IPFIXCollectors }} obs_domain_id=123 obs_point=456 sampling=1 -- set bridge br-int ipfix=@ipfix
{{ end }}
{{ end }}
wait
env:
- name: OVS_LOG_LEVEL
Expand Down
39 changes: 39 additions & 0 deletions pkg/network/ovn_kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,45 @@ func renderOVNKubernetes(conf *operv1.NetworkSpec, bootstrapResult *bootstrap.Bo
data.Data["EnableIPsec"] = false
}

if conf.ExportNetworkFlows != nil {
data.Data["EnableExportNetworkFlows"] = true
if conf.ExportNetworkFlows.NetFlow != nil {
data.Data["EnableNetFlow"] = true
collectors := "\\["
for _, v := range conf.ExportNetworkFlows.NetFlow {
collectors += "\\\"" + v + "\\\"" + ","
}
collectors = strings.TrimSuffix(collectors, ",") + "\\]"
data.Data["NetFlowCollectors"] = collectors
} else {
data.Data["EnableNetFlow"] = false
}
if conf.ExportNetworkFlows.SFlow != nil {
data.Data["EnableSFlow"] = true
collectors := "\\["
for _, v := range conf.ExportNetworkFlows.SFlow {
collectors += "\\\"" + v + "\\\"" + ","
}
collectors = strings.TrimSuffix(collectors, ",") + "\\]"
data.Data["SFlowCollectors"] = collectors
} else {
data.Data["EnableSFlow"] = false
}
if conf.ExportNetworkFlows.IPFIX != nil {
data.Data["EnableIPFIX"] = true
collectors := "\\["
for _, v := range conf.ExportNetworkFlows.IPFIX {
collectors += "\\\"" + v + "\\\"" + ","
}
collectors = strings.TrimSuffix(collectors, ",") + "\\]"
data.Data["IPFIXCollectors"] = collectors
} else {
data.Data["EnableIPFIX"] = false
}
} else {
data.Data["EnableExportNetworkFlows"] = false
}

manifests, err := render.RenderDir(filepath.Join(manifestDir, "network/ovn-kubernetes"), &data)
if err != nil {
return nil, errors.Wrap(err, "failed to render manifests")
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions vendor/github.com/openshift/api/operator/v1/types_network.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d2c0846

Please sign in to comment.