Skip to content

Commit 6e3fe96

Browse files
authored
[reconfigurator] in blueprint displays, make KvList headings optional (#8096)
I'd like to use `KvListWithHeading` in a place where there isn't a reasonable heading. Rename the struct to `KvList` and make the heading optional.
1 parent aa386c4 commit 6e3fe96

File tree

3 files changed

+42
-40
lines changed

3 files changed

+42
-40
lines changed

nexus/types/src/deployment.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub use zone_type::blueprint_zone_type;
104104

105105
use blueprint_display::{
106106
BpDiffState, BpOmicronZonesTableSchema, BpPhysicalDisksTableSchema,
107-
BpTable, BpTableData, BpTableRow, KvListWithHeading, constants::*,
107+
BpTable, BpTableData, BpTableRow, KvList, constants::*,
108108
};
109109
use id_map::{IdMap, IdMappable};
110110
use serde::de::SeqAccess;
@@ -430,15 +430,15 @@ pub struct BlueprintDisplay<'a> {
430430
}
431431

432432
impl BlueprintDisplay<'_> {
433-
fn make_cockroachdb_table(&self) -> KvListWithHeading {
433+
fn make_cockroachdb_table(&self) -> KvList {
434434
let fingerprint = if self.blueprint.cockroachdb_fingerprint.is_empty() {
435435
NONE_PARENS.to_string()
436436
} else {
437437
self.blueprint.cockroachdb_fingerprint.clone()
438438
};
439439

440-
KvListWithHeading::new_unchanged(
441-
COCKROACHDB_HEADING,
440+
KvList::new_unchanged(
441+
Some(COCKROACHDB_HEADING),
442442
vec![
443443
(COCKROACHDB_FINGERPRINT, fingerprint),
444444
(
@@ -451,9 +451,9 @@ impl BlueprintDisplay<'_> {
451451
)
452452
}
453453

454-
fn make_oximeter_table(&self) -> KvListWithHeading {
455-
KvListWithHeading::new_unchanged(
456-
OXIMETER_HEADING,
454+
fn make_oximeter_table(&self) -> KvList {
455+
KvList::new_unchanged(
456+
Some(OXIMETER_HEADING),
457457
vec![
458458
(GENERATION, self.blueprint.oximeter_read_version.to_string()),
459459
(
@@ -464,15 +464,15 @@ impl BlueprintDisplay<'_> {
464464
)
465465
}
466466

467-
fn make_metadata_table(&self) -> KvListWithHeading {
467+
fn make_metadata_table(&self) -> KvList {
468468
let comment = if self.blueprint.comment.is_empty() {
469469
NONE_PARENS.to_string()
470470
} else {
471471
self.blueprint.comment.clone()
472472
};
473473

474-
KvListWithHeading::new_unchanged(
475-
METADATA_HEADING,
474+
KvList::new_unchanged(
475+
Some(METADATA_HEADING),
476476
vec![
477477
(CREATED_BY, self.blueprint.creator.clone()),
478478
(
@@ -498,7 +498,7 @@ impl BlueprintDisplay<'_> {
498498
// Return tables representing a [`ClickhouseClusterConfig`] in a given blueprint
499499
fn make_clickhouse_cluster_config_tables(
500500
&self,
501-
) -> Option<(KvListWithHeading, BpTable, BpTable)> {
501+
) -> Option<(KvList, BpTable, BpTable)> {
502502
let config = &self.blueprint.clickhouse_cluster_config.as_ref()?;
503503

504504
let diff_table =

nexus/types/src/deployment/blueprint_diff.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use super::blueprint_display::{
88
BpClickhouseServersTableSchema, BpDatasetsTableSchema, BpDiffState,
99
BpGeneration, BpOmicronZonesTableSchema, BpPendingMgsUpdates,
1010
BpPhysicalDisksTableSchema, BpTable, BpTableColumn, BpTableData,
11-
BpTableRow, KvListWithHeading, KvPair, constants::*, linear_table_modified,
11+
BpTableRow, KvList, KvPair, constants::*, linear_table_modified,
1212
linear_table_unchanged,
1313
};
1414
use super::{
@@ -1186,7 +1186,7 @@ impl BpDiffDatasets {
11861186
/// there is only a single known blueprint with no before or after collection or
11871187
/// bluerpint to compare to.
11881188
pub struct ClickhouseClusterConfigDiffTablesForSingleBlueprint {
1189-
pub metadata: KvListWithHeading,
1189+
pub metadata: KvList,
11901190
pub keepers: BpTable,
11911191
pub servers: BpTable,
11921192
}
@@ -1220,7 +1220,7 @@ impl ClickhouseClusterConfigDiffTablesForSingleBlueprint {
12201220
.collect();
12211221

12221222
let metadata =
1223-
KvListWithHeading::new(CLICKHOUSE_CLUSTER_CONFIG_HEADING, rows);
1223+
KvList::new(Some(CLICKHOUSE_CLUSTER_CONFIG_HEADING), rows);
12241224

12251225
let keepers = BpTable::new(
12261226
BpClickhouseKeepersTableSchema {},
@@ -1259,7 +1259,7 @@ impl From<ClickhouseClusterConfigDiffTablesForSingleBlueprint>
12591259
/// `ClickhouseClusterConfig` tables or a `ClickhouseClusterConfig` table and
12601260
/// its inventory representation.
12611261
pub struct ClickhouseClusterConfigDiffTables {
1262-
pub metadata: KvListWithHeading,
1262+
pub metadata: KvList,
12631263
pub keepers: BpTable,
12641264
pub servers: Option<BpTable>,
12651265
}
@@ -1289,8 +1289,8 @@ impl ClickhouseClusterConfigDiffTables {
12891289
),
12901290
)
12911291
};
1292-
let metadata = KvListWithHeading::new(
1293-
CLICKHOUSE_CLUSTER_CONFIG_HEADING,
1292+
let metadata = KvList::new(
1293+
Some(CLICKHOUSE_CLUSTER_CONFIG_HEADING),
12941294
vec![
12951295
KvPair::new(
12961296
BpDiffState::Added,
@@ -1434,8 +1434,8 @@ impl ClickhouseClusterConfigDiffTables {
14341434
};
14351435
}
14361436

1437-
let metadata = KvListWithHeading::new(
1438-
CLICKHOUSE_CLUSTER_CONFIG_HEADING,
1437+
let metadata = KvList::new(
1438+
Some(CLICKHOUSE_CLUSTER_CONFIG_HEADING),
14391439
vec![
14401440
diff_row!(generation, GENERATION),
14411441
diff_row!(max_used_server_id, CLICKHOUSE_MAX_USED_SERVER_ID),
@@ -1523,8 +1523,8 @@ impl ClickhouseClusterConfigDiffTables {
15231523
before: &clickhouse_admin_types::ClickhouseKeeperClusterMembership,
15241524
) -> Self {
15251525
// There's only so much information in a collection. Show what we can.
1526-
let metadata = KvListWithHeading::new(
1527-
CLICKHOUSE_CLUSTER_CONFIG_HEADING,
1526+
let metadata = KvList::new(
1527+
Some(CLICKHOUSE_CLUSTER_CONFIG_HEADING),
15281528
vec![KvPair::new(
15291529
BpDiffState::Removed,
15301530
CLICKHOUSE_HIGHEST_SEEN_KEEPER_LEADER_COMMITTED_LOG_INDEX,
@@ -1713,7 +1713,7 @@ impl<'diff> BlueprintDiffDisplay<'diff> {
17131713

17141714
pub fn make_metadata_diff_tables(
17151715
&self,
1716-
) -> impl IntoIterator<Item = KvListWithHeading> {
1716+
) -> impl IntoIterator<Item = KvList> {
17171717
macro_rules! diff_row {
17181718
($member:ident, $label:expr) => {
17191719
diff_row!($member, $label, std::convert::identity)
@@ -1742,8 +1742,8 @@ impl<'diff> BlueprintDiffDisplay<'diff> {
17421742
}
17431743

17441744
[
1745-
KvListWithHeading::new(
1746-
COCKROACHDB_HEADING,
1745+
KvList::new(
1746+
Some(COCKROACHDB_HEADING),
17471747
vec![
17481748
diff_row!(
17491749
cockroachdb_fingerprint,
@@ -1757,8 +1757,8 @@ impl<'diff> BlueprintDiffDisplay<'diff> {
17571757
),
17581758
],
17591759
),
1760-
KvListWithHeading::new(
1761-
METADATA_HEADING,
1760+
KvList::new(
1761+
Some(METADATA_HEADING),
17621762
vec![
17631763
diff_row!(internal_dns_version, INTERNAL_DNS_VERSION),
17641764
diff_row!(external_dns_version, EXTERNAL_DNS_VERSION),
@@ -1769,7 +1769,7 @@ impl<'diff> BlueprintDiffDisplay<'diff> {
17691769

17701770
pub fn make_oximeter_read_diff_tables(
17711771
&self,
1772-
) -> impl IntoIterator<Item = KvListWithHeading> {
1772+
) -> impl IntoIterator<Item = KvList> {
17731773
macro_rules! diff_row {
17741774
($member:ident, $label:expr) => {
17751775
diff_row!($member, $label, std::convert::identity)
@@ -1799,8 +1799,8 @@ impl<'diff> BlueprintDiffDisplay<'diff> {
17991799
};
18001800
}
18011801

1802-
[KvListWithHeading::new(
1803-
OXIMETER_HEADING,
1802+
[KvList::new(
1803+
Some(OXIMETER_HEADING),
18041804
vec![
18051805
diff_row!(oximeter_read_version, GENERATION),
18061806
diff_row!(oximeter_read_mode, OXIMETER_READ_FROM),

nexus/types/src/deployment/blueprint_display.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -455,25 +455,25 @@ impl KvPair {
455455
}
456456
}
457457

458-
// A top-to-bottom list of KV pairs with a heading
458+
// A top-to-bottom list of KV pairs, with or without a heading
459459
#[derive(Debug)]
460-
pub struct KvListWithHeading {
461-
heading: &'static str,
460+
pub struct KvList {
461+
heading: Option<&'static str>,
462462
kv: Vec<KvPair>,
463463
}
464464

465-
impl KvListWithHeading {
465+
impl KvList {
466466
pub fn new_unchanged<S1: Into<String>, S2: Into<String>>(
467-
heading: &'static str,
467+
heading: Option<&'static str>,
468468
kv: Vec<(S1, S2)>,
469-
) -> KvListWithHeading {
469+
) -> KvList {
470470
let kv =
471471
kv.into_iter().map(|(k, v)| KvPair::new_unchanged(k, v)).collect();
472-
KvListWithHeading { heading, kv }
472+
KvList { heading, kv }
473473
}
474474

475-
pub fn new(heading: &'static str, kv: Vec<KvPair>) -> KvListWithHeading {
476-
KvListWithHeading { heading, kv }
475+
pub fn new(heading: Option<&'static str>, kv: Vec<KvPair>) -> KvList {
476+
KvList { heading, kv }
477477
}
478478

479479
/// Compute the max width of the keys for alignment purposes
@@ -482,10 +482,12 @@ impl KvListWithHeading {
482482
}
483483
}
484484

485-
impl fmt::Display for KvListWithHeading {
485+
impl fmt::Display for KvList {
486486
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
487487
// Write the heading
488-
writeln!(f, " {}:", self.heading)?;
488+
if let Some(heading) = self.heading {
489+
writeln!(f, " {}:", heading)?;
490+
}
489491

490492
// Write the rows
491493
let key_width = self.max_key_width() + 1;

0 commit comments

Comments
 (0)