Skip to content

Commit

Permalink
dc_as_zone: add dirty hack for using datacenter as zone
Browse files Browse the repository at this point in the history
  • Loading branch information
lowitea committed Dec 7, 2023
1 parent ef58810 commit 4acebb6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ CMakeFiles
cmake_install.cmake
*.dylib
*.idea
*.vscode
cluster.genin.yml
inventory.yml
__pycache__
*pyc
.cache
Expand Down
2 changes: 1 addition & 1 deletion src/task/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ impl Cluster {
/// - that's it, when there may only be single domain name in instance's `failure_domains`.
pub fn use_failure_domain_as_zone_for_instances(mut self, args: &ArgMatches) -> Self {
if args.get_flag("fd-as-zone") {
self.hosts.use_failure_domain_as_zone();
self.hosts.use_failure_domain_as_zone(None);
}
self
}
Expand Down
2 changes: 1 addition & 1 deletion src/task/cluster/hst/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ fn hosts_use_failure_domain_as_zone() {
assert_eq!(failure_domain_instance_zone(&host, "cache-2-1"), None);
assert_eq!(failure_domain_instance_zone(&host, "cache-2-2"), None);

host.use_failure_domain_as_zone();
host.use_failure_domain_as_zone(None);
assert_eq!(
failure_domain_instance_zone(&host, "cache-2-1"),
Some("dc-2")
Expand Down
17 changes: 14 additions & 3 deletions src/task/cluster/hst/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,14 +774,25 @@ impl HostV2 {
}

/// For every instance that has finalized failure domain, replace its zone with that domain name.
pub fn use_failure_domain_as_zone(&mut self) {
pub fn use_failure_domain_as_zone(&mut self, dc: Option<String>) {
let dc = if dc.is_some() {
dc
} else if self.name == Name::from("cluster") {
None
} else {
Some(self.name.to_string())
};
for instance in self.instances.iter_mut() {
if let FailureDomains::Finished(failure_domain) = &instance.failure_domains {
instance.config.zone = Some(failure_domain.clone());
if let Some(dc) = &dc {
instance.config.zone = Some(dc.clone());
} else {
instance.config.zone = Some(failure_domain.clone());
}
}
}
for sub_host in self.hosts.iter_mut() {
sub_host.use_failure_domain_as_zone()
sub_host.use_failure_domain_as_zone(dc.clone())
}
}

Expand Down

0 comments on commit 4acebb6

Please sign in to comment.