Skip to content

Commit

Permalink
[Agent] API Watcher uses the latest config
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanchaoa authored and rvql committed Jul 11, 2023
1 parent 53059cc commit 0b09d16
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 20 deletions.
13 changes: 3 additions & 10 deletions agent/src/config/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1786,6 +1786,9 @@ impl ConfigHandler {
|| old_cfg.kubernetes_api_memory_trim_percent
!= new_cfg.kubernetes_api_memory_trim_percent
|| old_cfg.max_memory != new_cfg.max_memory);
if restart_api_watcher {
api_watcher.stop();
}

info!(
"platform config change from {:#?} to {:#?}",
Expand All @@ -1795,16 +1798,6 @@ impl ConfigHandler {

#[cfg(target_os = "linux")]
if static_config.agent_mode == RunningMode::Managed {
if restart_api_watcher {
api_watcher.stop();
api_watcher.start();
}
if candidate_config.platform.kubernetes_api_enabled {
api_watcher.start();
} else {
api_watcher.stop();
}

fn platform_callback(handler: &ConfigHandler, components: &mut AgentComponents) {
let conf = &handler.candidate_config.platform;

Expand Down
84 changes: 74 additions & 10 deletions agent/src/trident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,16 @@ impl Trident {
match &mut *state_guard {
State::Running => {
state_guard = cond.wait(state_guard).unwrap();
#[cfg(target_os = "linux")]
if config_handler
.candidate_config
.platform
.kubernetes_api_enabled
{
api_watcher.start();
} else {
api_watcher.stop();
}
continue;
}
State::Terminated => {
Expand Down Expand Up @@ -571,6 +581,17 @@ impl Trident {
#[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();
}
}
state_guard = cond.wait(state_guard).unwrap();
continue;
Expand Down Expand Up @@ -611,6 +632,17 @@ impl Trident {
&api_watcher,
);

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

config_handler.load_plugin(
&runtime,
&session,
Expand Down Expand Up @@ -651,15 +683,27 @@ impl Trident {

components.replace(comp);
}
Some(components) => {
if let Components::Agent(components) = components {
let callbacks = config_handler.on_config(
runtime_config,
&exception_handler,
Some(components),
#[cfg(target_os = "linux")]
&api_watcher,
);
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();
Expand All @@ -678,7 +722,27 @@ impl Trident {
listener.on_config_change(&config_handler.candidate_config.dispatcher);
}
}
}
_ => {
config_handler.on_config(
runtime_config,
&exception_handler,
None,
#[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();
}
}
},
}
state_guard = state.lock().unwrap();
}
Expand Down

0 comments on commit 0b09d16

Please sign in to comment.