From 894641fc6abe4dfb5095c21f3b33c9dca4e83a1a Mon Sep 17 00:00:00 2001 From: Chet Nichols III Date: Mon, 22 Jun 2026 00:27:58 -0700 Subject: [PATCH] refactor(dns): remove the unused instance-DNS view and its SQL hostname function `nico_inet_to_dns_hostname` and the `dns_records_instance` view derived forward A/AAAA names directly from instance IP addresses (`10.1.2.3` -> `10-1-2-3`). That view was dropped from the served `dns_records` view back in early 2025 and has not been served since; today the only thing that touched either object was a unit test. IP-derived hostnames are produced by the host-naming strategy -- the Rust `address_to_hostname` helper -- and stored in `machine_interfaces.hostname`, which the shortname/adm views serve, so the SQL function was a stale duplicate of that logic. This drops the view and the function -- verified to have no remaining dependents: nothing in the codebase queries them, there are no external grants, and a RESTRICT drop of both succeeds -- and removes the two tests that exercised them. IP-derived DNS is unchanged; it flows through the naming strategy and the stored hostname, not this view. This supports https://github.com/NVIDIA/infra-controller/issues/2709. Signed-off-by: Chet Nichols III --- ...072105_remove_unused_instance_dns_view.sql | 11 ++ crates/api-db/src/dns/mod.rs | 160 ------------------ 2 files changed, 11 insertions(+), 160 deletions(-) create mode 100644 crates/api-db/migrations/20260622072105_remove_unused_instance_dns_view.sql diff --git a/crates/api-db/migrations/20260622072105_remove_unused_instance_dns_view.sql b/crates/api-db/migrations/20260622072105_remove_unused_instance_dns_view.sql new file mode 100644 index 0000000000..8fb56fcd2d --- /dev/null +++ b/crates/api-db/migrations/20260622072105_remove_unused_instance_dns_view.sql @@ -0,0 +1,11 @@ +-- Remove the unused instance-DNS view and its hostname-derivation function. +-- +-- `dns_records_instance` derived forward A/AAAA names directly from instance IP +-- addresses via nico_inet_to_dns_hostname(). It was dropped from the served +-- `dns_records` view in 20250113220120 and has not been served since. IP-derived +-- hostnames are produced by the host-naming strategy (the Rust +-- `address_to_hostname` helper) and stored in machine_interfaces.hostname, which +-- the shortname/adm views serve -- so this view and function are a stale SQL +-- duplicate of that logic, with no remaining consumers. +DROP VIEW IF EXISTS dns_records_instance; +DROP FUNCTION IF EXISTS nico_inet_to_dns_hostname(inet); diff --git a/crates/api-db/src/dns/mod.rs b/crates/api-db/src/dns/mod.rs index bca2fb0edf..64ad186b3c 100644 --- a/crates/api-db/src/dns/mod.rs +++ b/crates/api-db/src/dns/mod.rs @@ -71,9 +71,6 @@ pub fn arpa_qname_to_ip(qname: &str) -> Option { #[cfg(test)] mod tests { - use carbide_test_support::Outcome::*; - use carbide_test_support::{Case, check_cases_async}; - use sqlx::Row; #[test] fn test_normalize_domain_name() { @@ -115,163 +112,6 @@ mod tests { ); } - #[crate::sqlx_test] - async fn test_dns_hostname_from_ipv6_expands_to_rust_format(pool: sqlx::PgPool) { - check_cases_async( - [ - Case { - scenario: "ipv4 dotted-quad becomes dashed octets", - input: "192.168.1.2", - expect: Yields("192-168-1-2".to_string()), - }, - Case { - scenario: "unspecified address expands every hextet", - input: "::", - expect: Yields("0000-0000-0000-0000-0000-0000-0000-0000".to_string()), - }, - Case { - scenario: "loopback keeps the low hextet", - input: "::1", - expect: Yields("0000-0000-0000-0000-0000-0000-0000-0001".to_string()), - }, - Case { - scenario: "documentation prefix expands in full", - input: "2001:db8::2", - expect: Yields("2001-0db8-0000-0000-0000-0000-0000-0002".to_string()), - }, - Case { - scenario: "ipv4-mapped folds into the trailing hextets", - input: "::ffff:192.0.2.128", - expect: Yields("0000-0000-0000-0000-0000-ffff-c000-0280".to_string()), - }, - ], - |address| { - // Clone the (Arc-backed) pool per case so the future owns it and - // the closure stays `Fn` — see check_cases_async's signature. - let pool = pool.clone(); - async move { - sqlx::query_scalar::<_, String>("SELECT nico_inet_to_dns_hostname($1::inet)") - .bind(address) - .fetch_one(&pool) - .await - .map_err(drop) - } - }, - ) - .await; - } - - #[crate::sqlx_test] - async fn test_dns_records_instance_ipv6_qname_expands_hostname(pool: sqlx::PgPool) { - sqlx::query( - "INSERT INTO domains (id, name) - VALUES ('10000000-0000-0000-0000-000000000001', 'dwrt1.com')", - ) - .execute(&pool) - .await - .unwrap(); - - sqlx::query( - "INSERT INTO network_segments (id, name, version) - VALUES ('20000000-0000-0000-0000-000000000001', 'tenant-segment', 'test')", - ) - .execute(&pool) - .await - .unwrap(); - - sqlx::query( - "INSERT INTO machines (id, dpf) - VALUES ('host-1', '{\"enabled\": true, \"used_for_ingestion\": false}'::jsonb)", - ) - .execute(&pool) - .await - .unwrap(); - - sqlx::query( - "INSERT INTO machine_interfaces ( - id, - machine_id, - segment_id, - mac_address, - domain_id, - primary_interface, - hostname, - association_type - ) - VALUES ( - '30000000-0000-0000-0000-000000000001', - 'host-1', - '20000000-0000-0000-0000-000000000001', - '02:00:00:00:00:01', - '10000000-0000-0000-0000-000000000001', - true, - 'host-1', - 'Machine' - )", - ) - .execute(&pool) - .await - .unwrap(); - - let network_config = serde_json::json!({ - "interfaces": [ - { - "function_id": { "type": "physical" }, - "ip_addrs": { - "unspecified": "::", - "loopback": "::1", - "tenant": "2001:db8::2" - } - } - ] - }); - - sqlx::query("INSERT INTO instances (machine_id, network_config) VALUES ($1, $2::jsonb)") - .bind("host-1") - .bind(network_config) - .execute(&pool) - .await - .unwrap(); - - let rows = sqlx::query( - "SELECT DISTINCT q_name, host(resource_record) AS resource_record - FROM dns_records_instance", - ) - .fetch_all(&pool) - .await - .unwrap(); - - let records = rows - .iter() - .map(|row| { - ( - row.try_get::("resource_record").unwrap(), - row.try_get::("q_name").unwrap(), - ) - }) - .collect::>(); - - let expected_records = vec![ - ( - "::".to_string(), - "0000-0000-0000-0000-0000-0000-0000-0000.dwrt1.com.".to_string(), - ), - ( - "::1".to_string(), - "0000-0000-0000-0000-0000-0000-0000-0001.dwrt1.com.".to_string(), - ), - ( - "2001:db8::2".to_string(), - "2001-0db8-0000-0000-0000-0000-0000-0002.dwrt1.com.".to_string(), - ), - ]; - - assert_eq!(records.len(), expected_records.len()); - for expected_record in expected_records { - assert!(records.contains(&expected_record)); - } - } - #[crate::sqlx_test] async fn find_ptr_record_resolves_address_to_hostname(pool: sqlx::PgPool) { sqlx::query(