Skip to content

Commit

Permalink
sled-agent: make zone_network_setup_install take Ipv6Addr instead of …
Browse files Browse the repository at this point in the history
…String
  • Loading branch information
jgallagher committed May 28, 2024
1 parent ade1aef commit 312e11d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 33 deletions.
9 changes: 7 additions & 2 deletions sled-agent/src/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,12 @@ impl PropertyGroupBuilder {
}
}

pub fn add_property(mut self, name: &str, ty: &str, value: &str) -> Self {
pub fn add_property<S: Into<String>>(
mut self,
name: &str,
ty: &str,
value: S,
) -> Self {
// The data structures here are oriented around a few goals:
//
// - Properties will be written out in the order that they were added.
Expand All @@ -209,7 +214,7 @@ impl PropertyGroupBuilder {
.property_values
.entry(name.to_string())
.or_insert_with(Vec::new);
values.push(value.to_string());
values.push(value.into());
self
}
}
Expand Down
80 changes: 49 additions & 31 deletions sled-agent/src/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1406,7 +1406,7 @@ impl ServiceManager {
match domain {
Some(d) => {
dns_config_builder =
dns_config_builder.add_property("domain", "astring", &d)
dns_config_builder.add_property("domain", "astring", d)
}
None => (),
}
Expand All @@ -1423,10 +1423,11 @@ impl ServiceManager {
fn zone_network_setup_install(
gw_addr: &Ipv6Addr,
zone: &InstalledZone,
static_addr: &String,
static_addr: &Ipv6Addr,
) -> Result<ServiceBuilder, Error> {
let datalink = zone.get_control_vnic_name();
let gateway = &gw_addr.to_string();
let static_addr = &static_addr.to_string();

let mut config_builder = PropertyGroupBuilder::new("config");
config_builder = config_builder
Expand Down Expand Up @@ -1593,7 +1594,7 @@ impl ServiceManager {
return Err(Error::SledAgentNotReady);
};

let listen_addr = &underlay_address.to_string();
let listen_addr = underlay_address;
let listen_port = &CLICKHOUSE_PORT.to_string();

let nw_setup_service = Self::zone_network_setup_install(
Expand All @@ -1605,7 +1606,11 @@ impl ServiceManager {
let dns_service = Self::dns_install(info, None, &None).await?;

let config = PropertyGroupBuilder::new("config")
.add_property("listen_addr", "astring", listen_addr)
.add_property(
"listen_addr",
"astring",
listen_addr.to_string(),
)
.add_property("listen_port", "astring", listen_port)
.add_property("store", "astring", "/data");
let clickhouse_service =
Expand Down Expand Up @@ -1642,7 +1647,7 @@ impl ServiceManager {
return Err(Error::SledAgentNotReady);
};

let listen_addr = &underlay_address.to_string();
let listen_addr = underlay_address;
let listen_port = &CLICKHOUSE_KEEPER_PORT.to_string();

let nw_setup_service = Self::zone_network_setup_install(
Expand All @@ -1654,7 +1659,11 @@ impl ServiceManager {
let dns_service = Self::dns_install(info, None, &None).await?;

let config = PropertyGroupBuilder::new("config")
.add_property("listen_addr", "astring", listen_addr)
.add_property(
"listen_addr",
"astring",
listen_addr.to_string(),
)
.add_property("listen_port", "astring", listen_port)
.add_property("store", "astring", "/data");
let clickhouse_keeper_service =
Expand Down Expand Up @@ -1694,29 +1703,37 @@ impl ServiceManager {
return Err(Error::SledAgentNotReady);
};

let crdb_listen_addr = *underlay_address;
let crdb_listen_port = COCKROACH_ADMIN_PORT;
let crdb_address = SocketAddr::new(
IpAddr::V6(*underlay_address),
IpAddr::V6(crdb_listen_addr),
COCKROACH_PORT,
);
let admin_address = SocketAddr::new(
IpAddr::V6(*underlay_address),
IpAddr::V6(crdb_listen_addr),
COCKROACH_ADMIN_PORT,
);
let crdb_listen_addr = &crdb_address.ip().to_string();
let crdb_listen_port = &crdb_address.port().to_string();

let nw_setup_service = Self::zone_network_setup_install(
&info.underlay_address,
&installed_zone,
crdb_listen_addr,
&crdb_listen_addr,
)?;

let dns_service = Self::dns_install(info, None, &None).await?;

// Configure the CockroachDB service.
let cockroachdb_config = PropertyGroupBuilder::new("config")
.add_property("listen_addr", "astring", crdb_listen_addr)
.add_property("listen_port", "astring", crdb_listen_port)
.add_property(
"listen_addr",
"astring",
crdb_listen_addr.to_string(),
)
.add_property(
"listen_port",
"astring",
crdb_listen_port.to_string(),
)
.add_property("store", "astring", "/data");
let cockroachdb_service =
ServiceBuilder::new("oxide/cockroachdb").add_instance(
Expand Down Expand Up @@ -1771,7 +1788,7 @@ impl ServiceManager {
let Some(info) = self.inner.sled_info.get() else {
return Err(Error::SledAgentNotReady);
};
let listen_addr = &underlay_address.to_string();
let listen_addr = &underlay_address;
let listen_port = &CRUCIBLE_PORT.to_string();

let nw_setup_service = Self::zone_network_setup_install(
Expand All @@ -1788,7 +1805,11 @@ impl ServiceManager {
let uuid = &Uuid::new_v4().to_string();
let config = PropertyGroupBuilder::new("config")
.add_property("dataset", "astring", &dataset_name)
.add_property("listen_addr", "astring", listen_addr)
.add_property(
"listen_addr",
"astring",
listen_addr.to_string(),
)
.add_property("listen_port", "astring", listen_port)
.add_property("uuid", "astring", uuid)
.add_property("store", "astring", "/data");
Expand Down Expand Up @@ -1826,7 +1847,7 @@ impl ServiceManager {
return Err(Error::SledAgentNotReady);
};

let listen_addr = &underlay_address.to_string();
let listen_addr = &underlay_address;
let listen_port = &CRUCIBLE_PANTRY_PORT.to_string();

let nw_setup_service = Self::zone_network_setup_install(
Expand All @@ -1836,7 +1857,11 @@ impl ServiceManager {
)?;

let config = PropertyGroupBuilder::new("config")
.add_property("listen_addr", "astring", listen_addr)
.add_property(
"listen_addr",
"astring",
listen_addr.to_string(),
)
.add_property("listen_port", "astring", listen_port);

let profile = ProfileBuilder::new("omicron")
Expand Down Expand Up @@ -1877,12 +1902,10 @@ impl ServiceManager {
OXIMETER_PORT,
);

let listen_addr = &address.ip().to_string();

let nw_setup_service = Self::zone_network_setup_install(
&info.underlay_address,
&installed_zone,
listen_addr,
underlay_address,
)?;

let oximeter_config = PropertyGroupBuilder::new("config")
Expand Down Expand Up @@ -1920,12 +1943,10 @@ impl ServiceManager {
return Err(Error::SledAgentNotReady);
};

let static_addr = underlay_address.to_string();

let nw_setup_service = Self::zone_network_setup_install(
&info.underlay_address,
&installed_zone,
&static_addr.clone(),
underlay_address,
)?;

// Like Nexus, we need to be reachable externally via
Expand All @@ -1949,7 +1970,8 @@ impl ServiceManager {
})?;
let opte_ip = port.ip();

let http_addr = format!("[{}]:{}", static_addr, DNS_HTTP_PORT);
let http_addr =
format!("[{}]:{}", underlay_address, DNS_HTTP_PORT);
let dns_addr = format!("{}:{}", opte_ip, DNS_PORT);

let external_dns_config = PropertyGroupBuilder::new("config")
Expand Down Expand Up @@ -2009,12 +2031,10 @@ impl ServiceManager {
return Err(Error::SledAgentNotReady);
};

let static_addr = underlay_address.to_string();

let nw_setup_service = Self::zone_network_setup_install(
&info.underlay_address,
&installed_zone,
&static_addr.clone(),
underlay_address,
)?;

let is_boundary = matches!(
Expand Down Expand Up @@ -2107,7 +2127,7 @@ impl ServiceManager {
let nw_setup_service = Self::zone_network_setup_install(
gz_address,
&installed_zone,
&underlay_address.to_string(),
underlay_address,
)?;

// Internal DNS zones require a special route through
Expand Down Expand Up @@ -2187,12 +2207,10 @@ impl ServiceManager {
return Err(Error::SledAgentNotReady);
};

let static_addr = underlay_address.to_string();

let nw_setup_service = Self::zone_network_setup_install(
&info.underlay_address,
&installed_zone,
&static_addr.clone(),
underlay_address,
)?;

// While Nexus will be reachable via `external_ip`, it
Expand Down

0 comments on commit 312e11d

Please sign in to comment.