Skip to content

Commit 2df0091

Browse files
committed
feat(mgmt): build internal config if not there
Build an internal config for a GwConfig if it does not have it. This should only happen if we rollback to a blank config. We dpon't build the internal config for a blank config upfront not try to apply it. We only try to apply such a config if the first config to be applied fails, as a means to clean up. This behavior can be trivially changed by not storing a blank config in the config database. Signed-off-by: Fredi Raspall <[email protected]>
1 parent c69288c commit 2df0091

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

mgmt/src/processor/proc.rs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,6 @@ impl ConfigProcessor {
134134
e
135135
}
136136

137-
/// Apply a blank configuration
138-
#[allow(unused)]
139-
async fn apply_blank_config(&mut self) -> ConfigResult {
140-
let mut blank = GwConfig::blank();
141-
let internal = build_internal_config(&blank)?;
142-
blank.set_internal_config(internal);
143-
self.apply(blank).await
144-
}
145-
146137
/// Apply the provided configuration and update the history. On success, store it.
147138
async fn apply(&mut self, mut config: GwConfig) -> ConfigResult {
148139
let result = self.apply_gw_config(&mut config).await;
@@ -155,7 +146,10 @@ impl ConfigProcessor {
155146
result
156147
}
157148

158-
/// Attempt to apply the previously applied config
149+
/// Attempt to apply the previously applied config. If no config was applied, this
150+
/// will apply a blank config as we stored it in the config db.
151+
/// Note: when we apply a "rollback" config, the config history is not updated.
152+
/// TODO: decide if we want the history to include rollbacks.
159153
async fn rollback(&mut self) {
160154
if let Some(mut current) = self.config_db.get_current_config_mut().cloned() {
161155
info!("Rolling back to config with genid {}...", current.genid());
@@ -530,13 +524,12 @@ impl ConfigProcessor {
530524
let natallocatorw = &mut self.proc_params.natallocatorw;
531525
let vpcdtablesw = &mut self.proc_params.vpcdtablesw;
532526

533-
/* make sure we built internal config */
534-
let Some(internal) = &config.internal else {
535-
error!("Config for genid {genid} does not have internal config");
536-
return Err(ConfigError::InternalFailure(
537-
"No internal config was built".to_string(),
538-
));
539-
};
527+
/* build internal config if it hasn't been built */
528+
if config.internal.is_none() {
529+
let internal = build_internal_config(config)?;
530+
config.set_internal_config(internal);
531+
}
532+
let internal = config.internal.as_ref().unwrap_or_else(|| unreachable!());
540533

541534
/* apply device config */
542535
apply_device_config(&config.external.device)?;

0 commit comments

Comments
 (0)