Skip to content

Plan zone updates for target release #8024

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions common/src/api/external/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,10 @@ impl Generation {
);
Generation(next_gen)
}

pub const fn prev(&self) -> Option<Generation> {
if self.0 > 1 { Some(Generation(self.0 - 1)) } else { None }
}
}

impl<'de> Deserialize<'de> for Generation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ INFO sufficient InternalDns zones exist in plan, desired_count: 3, current_count
INFO added zone to sled, sled_id: a88790de-5962-4871-8686-61c1fd5b7094, kind: ExternalDns
INFO sufficient Nexus zones exist in plan, desired_count: 3, current_count: 3
INFO sufficient Oximeter zones exist in plan, desired_count: 0, current_count: 0
INFO all zones up-to-date
INFO will ensure cockroachdb setting, setting: cluster.preserve_downgrade_option, value: DoNotModify
generated blueprint 9c998c1d-1a7b-440a-ae0c-40f781dea6e2 based on parent blueprint 366b0b68-d80e-4bc1-abd3-dc69837847e0

Expand Down
39 changes: 37 additions & 2 deletions nexus-sled-agent-shared/src/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use omicron_common::{
DatasetManagementStatus, DatasetsConfig, DiskManagementStatus,
DiskVariant, OmicronPhysicalDisksConfig,
},
update::ArtifactId,
zpool_name::ZpoolName,
};
use omicron_uuid_kinds::{DatasetUuid, OmicronZoneUuid};
Expand All @@ -26,7 +27,7 @@ use serde::{Deserialize, Serialize};
// depend on sled-hardware-types.
pub use sled_hardware_types::Baseboard;
use strum::EnumIter;
use tufaceous_artifact::ArtifactHash;
use tufaceous_artifact::{ArtifactHash, KnownArtifactKind};

/// Identifies information about disks which may be attached to Sleds.
#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)]
Expand Down Expand Up @@ -492,13 +493,14 @@ impl OmicronZoneType {
///
/// # String representations of this type
///
/// There are no fewer than four string representations for this type, all
/// There are no fewer than five string representations for this type, all
/// slightly different from each other.
///
/// 1. [`Self::zone_prefix`]: Used to construct zone names.
/// 2. [`Self::service_prefix`]: Used to construct SMF service names.
/// 3. [`Self::name_prefix`]: Used to construct `Name` instances.
/// 4. [`Self::report_str`]: Used for reporting and testing.
/// 5. [`Self::artifact_name`]: Used to match TUF artifact names.
///
/// There is no `Display` impl to ensure that users explicitly choose the
/// representation they want. (Please play close attention to this! The
Expand Down Expand Up @@ -617,6 +619,39 @@ impl ZoneKind {
ZoneKind::Oximeter => "oximeter",
}
}

/// Return a string used as an artifact name for control-plane zones.
/// This is **not guaranteed** to be stable.
pub fn artifact_name(self) -> &'static str {
match self {
ZoneKind::BoundaryNtp => "ntp",
ZoneKind::Clickhouse => "clickhouse",
ZoneKind::ClickhouseKeeper => "clickhouse_keeper",
ZoneKind::ClickhouseServer => "clickhouse",
ZoneKind::CockroachDb => "cockroachdb",
ZoneKind::Crucible => "crucible-zone",
ZoneKind::CruciblePantry => "crucible-pantry-zone",
ZoneKind::ExternalDns => "external-dns",
ZoneKind::InternalDns => "internal-dns",
ZoneKind::InternalNtp => "ntp",
ZoneKind::Nexus => "nexus",
ZoneKind::Oximeter => "oximeter",
}
}

/// Return true if an artifact represents a control plane zone image
/// of this kind.
pub fn is_control_plane_zone_artifact(
self,
artifact_id: &ArtifactId,
) -> bool {
artifact_id
.kind
.to_known()
.map(|kind| matches!(kind, KnownArtifactKind::Zone))
.unwrap_or(false)
&& artifact_id.name == self.artifact_name()
}
}

/// Where Sled Agent should get the image for a zone.
Expand Down
23 changes: 22 additions & 1 deletion nexus/db-queries/src/db/datastore/target_release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
use super::DataStore;
use crate::authz;
use crate::context::OpContext;
use crate::db::model::{SemverVersion, TargetRelease, TargetReleaseSource};
use crate::db::model::{
Generation, SemverVersion, TargetRelease, TargetReleaseSource,
};
use async_bb8_diesel::AsyncRunQueryDsl as _;
use diesel::insert_into;
use diesel::prelude::*;
Expand Down Expand Up @@ -44,6 +46,25 @@ impl DataStore {
Ok(current)
}

/// Fetch a target release by generation number.
pub async fn target_release_get_generation(
&self,
opctx: &OpContext,
generation: Generation,
) -> LookupResult<Option<TargetRelease>> {
opctx
.authorize(authz::Action::Read, &authz::TARGET_RELEASE_CONFIG)
.await?;
let conn = self.pool_connection_authorized(opctx).await?;
dsl::target_release
.select(TargetRelease::as_select())
.filter(dsl::generation.eq(generation))
.first_async(&*conn)
.await
.optional()
.map_err(|e| public_error_from_diesel(e, ErrorHandler::Server))
}

/// Insert a new target release row and return it. It will only become
/// the current target release if its generation is larger than any
/// existing row.
Expand Down
36 changes: 35 additions & 1 deletion nexus/db-queries/src/db/datastore/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use omicron_common::api::external::{
self, CreateResult, DataPageParams, Generation, ListResultVec,
LookupResult, LookupType, ResourceType, TufRepoInsertStatus,
};
use omicron_uuid_kinds::GenericUuid;
use omicron_uuid_kinds::TufRepoKind;
use omicron_uuid_kinds::TypedUuid;
use swrite::{SWrite, swrite};
Expand Down Expand Up @@ -106,8 +107,41 @@ impl DataStore {
})
}

/// Returns a TUF repo description.
pub async fn update_tuf_repo_get_by_id(
&self,
opctx: &OpContext,
repo_id: TypedUuid<TufRepoKind>,
) -> LookupResult<TufRepoDescription> {
opctx.authorize(authz::Action::Read, &authz::FLEET).await?;

use nexus_db_schema::schema::tuf_repo::dsl;

let conn = self.pool_connection_authorized(opctx).await?;
let repo_id = repo_id.into_untyped_uuid();
let repo = dsl::tuf_repo
.filter(dsl::id.eq(repo_id))
.select(TufRepo::as_select())
.first_async::<TufRepo>(&*conn)
.await
.map_err(|e| {
public_error_from_diesel(
e,
ErrorHandler::NotFoundByLookup(
ResourceType::TufRepo,
LookupType::ById(repo_id),
),
)
})?;

let artifacts = artifacts_for_repo(repo.id.into(), &conn)
.await
.map_err(|e| public_error_from_diesel(e, ErrorHandler::Server))?;
Ok(TufRepoDescription { repo, artifacts })
}

/// Returns the TUF repo description corresponding to this system version.
pub async fn update_tuf_repo_get(
pub async fn update_tuf_repo_get_by_version(
&self,
opctx: &OpContext,
system_version: SemverVersion,
Expand Down
2 changes: 2 additions & 0 deletions nexus/reconfigurator/execution/src/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1424,6 +1424,8 @@ mod test {
target_crucible_pantry_zone_count: CRUCIBLE_PANTRY_REDUNDANCY,
clickhouse_policy: None,
oximeter_read_policy: OximeterReadPolicy::new(1),
tuf_repo: None,
old_repo: None,
log,
}
.build()
Expand Down
1 change: 1 addition & 0 deletions nexus/reconfigurator/planning/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ omicron-uuid-kinds.workspace = true
once_cell.workspace = true
oxnet.workspace = true
rand.workspace = true
semver.workspace = true
sled-agent-client.workspace = true
slog.workspace = true
slog-error-chain.workspace = true
Expand Down
Loading
Loading