Skip to content

Commit 865ed89

Browse files
committed
chore: updates from PR comments
1 parent 791a33a commit 865ed89

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

agent/src/util/config_action.rs

+14-9
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,7 @@ async fn handle_config(
154154
}
155155
// If a config is updated, delete all associated instances and device plugins and then recreate them to reflect updated config
156156
WatchEvent::Modified(config) => {
157-
let do_recreate = should_recreate_config(&config, config_map.clone())
158-
.await
159-
.unwrap();
157+
let do_recreate = should_recreate_config(&config, config_map.clone()).await?;
160158
if !do_recreate {
161159
trace!(
162160
"handle_config - config {:?} has not changed. ignoring config modified event.",
@@ -294,13 +292,20 @@ async fn handle_config_delete(
294292
/// Checks to see if the configuration needs to be recreated.
295293
/// At present, this just checks to see if the `.metadata.generation` has changed.
296294
/// The `.metadata.generation` value is incremented for all changes, except for changes to `.metadata` or `.status`.
297-
async fn should_recreate_config(config: &Configuration, config_map: ConfigMap) -> Result<bool, ()> {
295+
async fn should_recreate_config(
296+
config: &Configuration,
297+
config_map: ConfigMap,
298+
) -> Result<bool, anyhow::Error> {
298299
let name = config.metadata.name.clone().unwrap();
299-
let last_generation = config_map.lock().await.get(&name).unwrap().last_generation;
300-
trace!(
301-
"should_recreate_config - checking if config {} needs to be recreated",
302-
name,
303-
);
300+
let last_generation = config_map
301+
.lock()
302+
.await
303+
.get(&name)
304+
.ok_or(anyhow::anyhow!(
305+
"Configuration {} not found in ConfigMap",
306+
name
307+
))?
308+
.last_generation;
304309

305310
if config.metadata.generation == last_generation {
306311
return Ok(false);

0 commit comments

Comments
 (0)