Skip to content

Commit

Permalink
fix: prevent useless changes
Browse files Browse the repository at this point in the history
Do not alter the order of the DNS options

Signed-off-by: Flavio Castelli <[email protected]>
  • Loading branch information
flavio committed Oct 1, 2024
1 parent 1cda0d8 commit e870075
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,35 @@ fn validate(payload: &[u8]) -> CallResult {
}

fn enforce_ndots(settings: &Settings, podspec: &apicore::PodSpec) -> PodSpec {
// preserve the order of the options to prevent needless updates
let mut dns_options: Vec<apicore::PodDNSConfigOption> = podspec
.dns_config
.as_ref()
.and_then(|dns_config| dns_config.options.clone())
.unwrap_or_default()
.iter()
.filter(|option| option.name != Some("ndots".to_string()))
.cloned()
.map(|option| {
if option.name == Some("ndots".to_string()) {
apicore::PodDNSConfigOption {
name: Some("ndots".to_string()),
value: Some(settings.ndots.to_string()),
}
} else {
option.clone()
}
})
.collect();
dns_options.push(apicore::PodDNSConfigOption {
name: Some("ndots".to_string()),
value: Some(settings.ndots.to_string()),
});

// ensure the option is added if it's not present
if dns_options
.iter()
.all(|option| option.name != Some("ndots".to_string()))
{
dns_options.push(apicore::PodDNSConfigOption {
name: Some("ndots".to_string()),
value: Some(settings.ndots.to_string()),
});
}

PodSpec {
dns_config: Some(apicore::PodDNSConfig {
Expand Down

0 comments on commit e870075

Please sign in to comment.