From 312e11d49fadcc4e226988823aeee15fef50b4c4 Mon Sep 17 00:00:00 2001 From: John Gallagher Date: Tue, 28 May 2024 11:31:36 -0400 Subject: [PATCH] sled-agent: make zone_network_setup_install take Ipv6Addr instead of String --- sled-agent/src/profile.rs | 9 ++++- sled-agent/src/services.rs | 80 +++++++++++++++++++++++--------------- 2 files changed, 56 insertions(+), 33 deletions(-) diff --git a/sled-agent/src/profile.rs b/sled-agent/src/profile.rs index 1addbca4c9..33e30d1d7b 100644 --- a/sled-agent/src/profile.rs +++ b/sled-agent/src/profile.rs @@ -183,7 +183,12 @@ impl PropertyGroupBuilder { } } - pub fn add_property(mut self, name: &str, ty: &str, value: &str) -> Self { + pub fn add_property>( + 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. @@ -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 } } diff --git a/sled-agent/src/services.rs b/sled-agent/src/services.rs index a70a46cffa..11152bfe81 100644 --- a/sled-agent/src/services.rs +++ b/sled-agent/src/services.rs @@ -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 => (), } @@ -1423,10 +1423,11 @@ impl ServiceManager { fn zone_network_setup_install( gw_addr: &Ipv6Addr, zone: &InstalledZone, - static_addr: &String, + static_addr: &Ipv6Addr, ) -> Result { 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 @@ -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( @@ -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 = @@ -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( @@ -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 = @@ -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( @@ -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( @@ -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"); @@ -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( @@ -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") @@ -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") @@ -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 @@ -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") @@ -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!( @@ -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 @@ -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