Skip to content

Commit c860954

Browse files
rvqlsharang
authored andcommitted
[AGENT] Create sidecar poller before agent component start
1 parent e1619be commit c860954

File tree

2 files changed

+34
-25
lines changed

2 files changed

+34
-25
lines changed

agent/src/platform/kubernetes/mod.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
use std::{fs, net::IpAddr, os::unix::io::AsRawFd};
17+
use std::{fs, os::unix::io::AsRawFd};
1818

1919
use arc_swap::access::Access;
2020
use enum_dispatch::enum_dispatch;
@@ -67,15 +67,7 @@ pub fn check_read_link_ns() -> bool {
6767
}
6868

6969
impl GenericPoller {
70-
pub fn new(
71-
dest: IpAddr,
72-
config: PlatformAccess,
73-
extra_netns_regex: String,
74-
sidecar_mode: bool,
75-
) -> Self {
76-
if sidecar_mode {
77-
return SidecarPoller::new(dest).into();
78-
}
70+
pub fn new(config: PlatformAccess, extra_netns_regex: String) -> Self {
7971
let (can_set_ns, can_read_link_ns) = (check_set_ns(), check_read_link_ns());
8072

8173
if !can_set_ns || !can_read_link_ns {

agent/src/trident.rs

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ use crate::{
100100
use crate::{
101101
ebpf_dispatcher::EbpfCollector,
102102
platform::{
103-
kubernetes::{GenericPoller, Poller},
103+
kubernetes::{GenericPoller, Poller, SidecarPoller},
104104
ApiWatcher, LibvirtXmlExtractor, SocketSynchronizer,
105105
},
106106
utils::{
@@ -530,7 +530,7 @@ impl Trident {
530530
monitor.start();
531531

532532
#[cfg(target_os = "linux")]
533-
let (libvirt_xml_extractor, platform_synchronizer) = {
533+
let (libvirt_xml_extractor, platform_synchronizer, sidecar_poller) = {
534534
let ext = Arc::new(LibvirtXmlExtractor::new());
535535
let syn = Arc::new(PlatformSynchronizer::new(
536536
runtime.clone(),
@@ -548,7 +548,17 @@ impl Trident {
548548
HashMap::new(),
549549
));
550550
ext.start();
551-
(ext, syn)
551+
let poller = if sidecar_mode {
552+
let p: Arc<GenericPoller> = Arc::new(
553+
SidecarPoller::new(config_handler.static_config.controller_ips[0].parse()?)
554+
.into(),
555+
);
556+
syn.set_kubernetes_poller(p.clone());
557+
Some(p)
558+
} else {
559+
None
560+
};
561+
(ext, syn, poller)
552562
};
553563
#[cfg(target_os = "windows")]
554564
let platform_synchronizer = Arc::new(PlatformSynchronizer::new(
@@ -708,6 +718,8 @@ impl Trident {
708718
libvirt_xml_extractor.clone(),
709719
platform_synchronizer.clone(),
710720
#[cfg(target_os = "linux")]
721+
sidecar_poller.clone(),
722+
#[cfg(target_os = "linux")]
711723
api_watcher.clone(),
712724
vm_mac_addrs,
713725
config_handler.static_config.agent_mode,
@@ -1375,6 +1387,7 @@ impl AgentComponents {
13751387
remote_log_config: RemoteLogConfig,
13761388
#[cfg(target_os = "linux")] libvirt_xml_extractor: Arc<LibvirtXmlExtractor>,
13771389
platform_synchronizer: Arc<PlatformSynchronizer>,
1390+
#[cfg(target_os = "linux")] sidecar_poller: Option<Arc<GenericPoller>>,
13781391
#[cfg(target_os = "linux")] api_watcher: Arc<ApiWatcher>,
13791392
vm_mac_addrs: Vec<MacAddr>,
13801393
agent_mode: RunningMode,
@@ -1469,18 +1482,19 @@ impl AgentComponents {
14691482
// TODO: packet handler builders
14701483

14711484
#[cfg(target_os = "linux")]
1472-
let kubernetes_poller = Arc::new(GenericPoller::new(
1473-
config_handler.static_config.controller_ips[0].parse()?,
1474-
config_handler.platform(),
1475-
config_handler
1476-
.candidate_config
1477-
.dispatcher
1478-
.extra_netns_regex
1479-
.clone(),
1480-
sidecar_mode,
1481-
));
1482-
#[cfg(target_os = "linux")]
1483-
platform_synchronizer.set_kubernetes_poller(kubernetes_poller.clone());
1485+
// sidecar poller is created before agent start to provide pod interface info for server
1486+
let kubernetes_poller = sidecar_poller.unwrap_or_else(|| {
1487+
let poller = Arc::new(GenericPoller::new(
1488+
config_handler.platform(),
1489+
config_handler
1490+
.candidate_config
1491+
.dispatcher
1492+
.extra_netns_regex
1493+
.clone(),
1494+
));
1495+
platform_synchronizer.set_kubernetes_poller(poller.clone());
1496+
poller
1497+
});
14841498

14851499
#[cfg(target_os = "linux")]
14861500
let prometheus_targets_watcher = Arc::new(TargetsWatcher::new(
@@ -2563,6 +2577,7 @@ impl Components {
25632577
remote_log_config: RemoteLogConfig,
25642578
#[cfg(target_os = "linux")] libvirt_xml_extractor: Arc<LibvirtXmlExtractor>,
25652579
platform_synchronizer: Arc<PlatformSynchronizer>,
2580+
#[cfg(target_os = "linux")] sidecar_poller: Option<Arc<GenericPoller>>,
25662581
#[cfg(target_os = "linux")] api_watcher: Arc<ApiWatcher>,
25672582
vm_mac_addrs: Vec<MacAddr>,
25682583
agent_mode: RunningMode,
@@ -2597,6 +2612,8 @@ impl Components {
25972612
libvirt_xml_extractor,
25982613
platform_synchronizer,
25992614
#[cfg(target_os = "linux")]
2615+
sidecar_poller,
2616+
#[cfg(target_os = "linux")]
26002617
api_watcher,
26012618
vm_mac_addrs,
26022619
agent_mode,

0 commit comments

Comments
 (0)