From 4bd3d9f8af682357db4965b85e2bec7ef2c9ab97 Mon Sep 17 00:00:00 2001 From: Joel Takvorian Date: Fri, 8 Dec 2023 15:24:45 +0100 Subject: [PATCH] NETOBSERV-1430: make operator provide agent IP The agent IP as deteted by the agent itself could potentially differ from the expected machine network IP, e.g. getting " 192.168.12.2" instead of "10.10.10.2". But forcing the IP from the operator by inferring its host node IP, we ensure using the correct one Note that the AGENT_IP env was already implemented on Agent side to override IP detection --- controllers/ebpf/agent_controller.go | 11 +++++++++++ .../flowcollector_controller_certificates_test.go | 9 +++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/controllers/ebpf/agent_controller.go b/controllers/ebpf/agent_controller.go index 563c4dde7..a97c45815 100644 --- a/controllers/ebpf/agent_controller.go +++ b/controllers/ebpf/agent_controller.go @@ -30,6 +30,7 @@ const ( envCacheMaxFlows = "CACHE_MAX_FLOWS" envExcludeInterfaces = "EXCLUDE_INTERFACES" envInterfaces = "INTERFACES" + envAgentIP = "AGENT_IP" envFlowsTargetHost = "FLOWS_TARGET_HOST" envFlowsTargetPort = "FLOWS_TARGET_PORT" envSampling = "SAMPLING" @@ -474,6 +475,16 @@ func (c *AgentController) setEnvConfig(coll *flowslatest.FlowCollector) []corev1 } config = append(config, corev1.EnvVar{Name: envDedupe, Value: dedup}) config = append(config, corev1.EnvVar{Name: envDedupeJustMark, Value: dedupJustMark}) + config = append(config, corev1.EnvVar{ + Name: envAgentIP, + ValueFrom: &corev1.EnvVarSource{ + FieldRef: &corev1.ObjectFieldSelector{ + APIVersion: "v1", + FieldPath: "status.hostIP", + }, + }, + }, + ) return config } diff --git a/controllers/flowcollector_controller_certificates_test.go b/controllers/flowcollector_controller_certificates_test.go index 25f1bd1ee..9b6c29167 100644 --- a/controllers/flowcollector_controller_certificates_test.go +++ b/controllers/flowcollector_controller_certificates_test.go @@ -466,14 +466,11 @@ func flowCollectorCertificatesSpecs() { Context("Cleanup", func() { // Retrieve CR to get its UID flowCR := flowslatest.FlowCollector{} - It("Should get CR", func() { - Eventually(func() error { - return k8sClient.Get(ctx, crKey, &flowCR) - }, timeout, interval).Should(Succeed()) - }) - It("Should delete CR", func() { Eventually(func() error { + if err := k8sClient.Get(ctx, crKey, &flowCR); err != nil { + return err + } return k8sClient.Delete(ctx, &flowCR) }, timeout, interval).Should(Succeed()) })