Skip to content

Commit 483f0c4

Browse files
authored
Fix NetworkEvents with upstream ovnk (#2461)
* Fix NetworkEvents with upstream ovnk * add test
1 parent 1b6fbe5 commit 483f0c4

File tree

2 files changed

+74
-22
lines changed

2 files changed

+74
-22
lines changed

internal/controller/ebpf/agent_controller.go

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -74,27 +74,27 @@ const (
7474
envDNSTrackingPort = "DNS_TRACKING_PORT"
7575
envPreferredInterface = "PREFERRED_INTERFACE_FOR_MAC_PREFIX"
7676
envAttachMode = "TC_ATTACH_MODE"
77+
envOVNObservHostMountPath = "OVN_OBSERV_HOST_MOUNT_PATH"
7778
envListSeparator = ","
7879
)
7980

8081
const (
81-
exportKafka = "kafka"
82-
exportGRPC = "grpc"
83-
kafkaCerts = "kafka-certs"
84-
averageMessageSize = 100
85-
bpfTraceMountName = "bpf-kernel-debug"
86-
bpfTraceMountPath = "/sys/kernel/debug"
87-
bpfNetNSMountName = "var-run-netns"
88-
bpfNetNSMountPath = "/var/run/netns"
89-
droppedFlowsAlertThreshold = 100
90-
ovnObservMountName = "var-run-ovn"
91-
ovnObservMountPath = "/var/run/ovn"
92-
ovnObservHostMountPath = "/var/run/ovn-ic"
93-
ovsMountPath = "/var/run/openvswitch"
94-
ovsHostMountPath = "/var/run/openvswitch"
95-
ovsMountName = "var-run-ovs"
96-
defaultNetworkEventsGroupID = "10"
97-
defaultPreferredInterface = "0a:58=eth0" // Hard-coded default config to deal with OVN-generated MACs
82+
exportKafka = "kafka"
83+
exportGRPC = "grpc"
84+
averageMessageSize = 100
85+
bpfTraceMountName = "bpf-kernel-debug"
86+
bpfTraceMountPath = "/sys/kernel/debug"
87+
bpfNetNSMountName = "var-run-netns"
88+
bpfNetNSMountPath = "/var/run/netns"
89+
droppedFlowsAlertThreshold = 100
90+
ovnObservMountName = "var-run-ovn"
91+
ovnObservMountPath = "/var/run/ovn"
92+
ovnObservHostMountPathOpenShift = "/var/run/ovn-ic"
93+
ovsMountPath = "/var/run/openvswitch"
94+
ovsHostMountPath = "/var/run/openvswitch"
95+
ovsMountName = "var-run-ovs"
96+
defaultNetworkEventsGroupID = "10"
97+
defaultPreferredInterface = "0a:58=eth0" // Hard-coded default config to deal with OVN-generated MACs
9898
)
9999

100100
const (
@@ -221,6 +221,7 @@ func (c *AgentController) desired(ctx context.Context, coll *flowslatest.FlowCol
221221
if err != nil {
222222
return nil, err
223223
}
224+
advancedConfig := helper.GetAdvancedAgentConfig(coll.Spec.Agent.EBPF.Advanced)
224225

225226
if coll.Spec.Agent.EBPF.Metrics.Server.TLS.Type != flowslatest.ServerTLSDisabled {
226227
var promTLS *flowslatest.CertificateReference
@@ -300,15 +301,22 @@ func (c *AgentController) desired(ctx context.Context, coll *flowslatest.FlowCol
300301
if coll.Spec.Agent.EBPF.IsAgentFeatureEnabled(flowslatest.NetworkEvents) ||
301302
coll.Spec.Agent.EBPF.IsAgentFeatureEnabled(flowslatest.UDNMapping) {
302303
if !coll.Spec.Agent.EBPF.Privileged {
303-
rlog.Error(fmt.Errorf("invalid configuration"), "To use Network Events Monitor"+
304-
"features privileged mode needs to be enabled")
304+
rlog.Error(fmt.Errorf("invalid configuration"), "To use NetworkEvents or UDNMapping features, privileged mode needs to be enabled")
305305
} else {
306+
hostPath := advancedConfig.Env[envOVNObservHostMountPath]
307+
if hostPath == "" {
308+
if c.ClusterInfo.IsOpenShift() {
309+
hostPath = ovnObservHostMountPathOpenShift
310+
} else {
311+
hostPath = ovsHostMountPath
312+
}
313+
}
306314
volume := corev1.Volume{
307315
Name: ovnObservMountName,
308316
VolumeSource: corev1.VolumeSource{
309317
HostPath: &corev1.HostPathVolumeSource{
310318
Type: newHostPathType(corev1.HostPathDirectory),
311-
Path: ovnObservHostMountPath,
319+
Path: hostPath,
312320
},
313321
},
314322
}
@@ -361,8 +369,6 @@ func (c *AgentController) desired(ctx context.Context, coll *flowslatest.FlowCol
361369
volumeMounts = append(volumeMounts, volumeMount)
362370
}
363371

364-
advancedConfig := helper.GetAdvancedAgentConfig(coll.Spec.Agent.EBPF.Advanced)
365-
366372
return &v1.DaemonSet{
367373
ObjectMeta: metav1.ObjectMeta{
368374
Name: constants.EBPFAgentName,

internal/controller/ebpf/agent_controller_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,49 @@ func TestBpfmanConfig(t *testing.T) {
222222
"csi.bpfman.io/program": "netobserv",
223223
}, ds.Spec.Template.Spec.Volumes[1].CSI.VolumeAttributes)
224224
}
225+
226+
func TestNetworkEventsOVNMount(t *testing.T) {
227+
fc := flowslatest.FlowCollector{
228+
Spec: flowslatest.FlowCollectorSpec{
229+
Agent: flowslatest.FlowCollectorAgent{
230+
EBPF: flowslatest.FlowCollectorEBPF{
231+
Privileged: true,
232+
Features: []flowslatest.AgentFeature{flowslatest.NetworkEvents},
233+
},
234+
},
235+
},
236+
}
237+
238+
// Upstream OVN
239+
info := reconcilers.Common{Namespace: "netobserv", ClusterInfo: &cluster.Info{}}
240+
inst := info.NewInstance(map[reconcilers.ImageRef]string{reconcilers.MainImage: "ebpf-agent"}, status.Instance{})
241+
agent := NewAgentController(inst)
242+
ds, err := agent.desired(context.Background(), &fc)
243+
assert.NoError(t, err)
244+
assert.NotNil(t, ds)
245+
246+
assert.Equal(t, "var-run-ovn", ds.Spec.Template.Spec.Volumes[2].Name)
247+
assert.Equal(t, "/var/run/openvswitch", ds.Spec.Template.Spec.Volumes[2].HostPath.Path)
248+
249+
// OpenShift OVN
250+
info.ClusterInfo.Mock("4.20.0", cluster.OVNKubernetes)
251+
ds, err = agent.desired(context.Background(), &fc)
252+
assert.NoError(t, err)
253+
assert.NotNil(t, ds)
254+
255+
assert.Equal(t, "var-run-ovn", ds.Spec.Template.Spec.Volumes[2].Name)
256+
assert.Equal(t, "/var/run/ovn-ic", ds.Spec.Template.Spec.Volumes[2].HostPath.Path)
257+
258+
// Custom
259+
fc.Spec.Agent.EBPF.Advanced = &flowslatest.AdvancedAgentConfig{
260+
Env: map[string]string{
261+
envOVNObservHostMountPath: "/foo/bar",
262+
},
263+
}
264+
ds, err = agent.desired(context.Background(), &fc)
265+
assert.NoError(t, err)
266+
assert.NotNil(t, ds)
267+
268+
assert.Equal(t, "var-run-ovn", ds.Spec.Template.Spec.Volumes[2].Name)
269+
assert.Equal(t, "/foo/bar", ds.Spec.Template.Spec.Volumes[2].HostPath.Path)
270+
}

0 commit comments

Comments
 (0)