Skip to content

Commit

Permalink
[Agent] optimize match expression
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoziv authored and sharang committed Sep 21, 2023
1 parent 830c696 commit ab62131
Showing 1 changed file with 53 additions and 55 deletions.
108 changes: 53 additions & 55 deletions agent/src/trident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ impl Trident {
}
};

let hostname = match config.override_os_hostname.as_ref() {
let hostname = match &config.override_os_hostname {
Some(name) => name.to_owned(),
None => get_hostname().unwrap_or_default(),
None => get_hostname().unwrap_or("unknown-host".to_owned()),
};

let ntp_diff = Arc::new(AtomicI64::new(0));
Expand Down Expand Up @@ -767,67 +767,65 @@ impl Trident {

components.replace(comp);
}
Some(components) => match components {
Components::Agent(components) => {
let callbacks: Vec<fn(&ConfigHandler, &mut AgentComponents)> =
config_handler.on_config(
runtime_config,
&exception_handler,
Some(components),
#[cfg(target_os = "linux")]
&api_watcher,
);

#[cfg(target_os = "linux")]
if config_handler
.candidate_config
.platform
.kubernetes_api_enabled
{
api_watcher.start();
} else {
api_watcher.stop();
}

components.start();
components.config = config_handler.candidate_config.clone();
dispatcher_listener_callback(
&config_handler.candidate_config.dispatcher,
components,
blacklist,
vm_mac_addrs,
gateway_vmac_addrs,
tap_types,
);
for callback in callbacks {
callback(&config_handler, components);
}

for listener in components.dispatcher_listeners.iter_mut() {
listener.on_config_change(&config_handler.candidate_config.dispatcher);
}
}
_ => {
config_handler.on_config(
Some(Components::Agent(components)) => {
let callbacks: Vec<fn(&ConfigHandler, &mut AgentComponents)> = config_handler
.on_config(
runtime_config,
&exception_handler,
None,
Some(components),
#[cfg(target_os = "linux")]
&api_watcher,
);

#[cfg(target_os = "linux")]
if config_handler
.candidate_config
.platform
.kubernetes_api_enabled
{
api_watcher.start();
} else {
api_watcher.stop();
}

components.start();
components.config = config_handler.candidate_config.clone();
dispatcher_listener_callback(
&config_handler.candidate_config.dispatcher,
components,
blacklist,
vm_mac_addrs,
gateway_vmac_addrs,
tap_types,
);
for callback in callbacks {
callback(&config_handler, components);
}

for listener in components.dispatcher_listeners.iter_mut() {
listener.on_config_change(&config_handler.candidate_config.dispatcher);
}
}
_ => {
config_handler.on_config(
runtime_config,
&exception_handler,
None,
#[cfg(target_os = "linux")]
if config_handler
.candidate_config
.platform
.kubernetes_api_enabled
{
api_watcher.start();
} else {
api_watcher.stop();
}
&api_watcher,
);

#[cfg(target_os = "linux")]
if config_handler
.candidate_config
.platform
.kubernetes_api_enabled
{
api_watcher.start();
} else {
api_watcher.stop();
}
},
}
}
state_guard = state.lock().unwrap();
}
Expand Down

0 comments on commit ab62131

Please sign in to comment.