-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[nexus] add basic support for expunged sled policy and decommissioned…
… sled state (#5032) This PR does a few things: * Migrates our current `sled_provision_state` to a new `sled_policy` enum, which has more information (per [RFD 457](https://rfd.shared.oxide.computer/rfd/0457)). This PR implements the expunged state, not the graceful removal state. * Adds a `sled_state` enum, which describes Nexus's view of the sled. This PR adds the `active` and `decommissioned` states. * Adds **internal** code to move around between valid states. * Makes the blueprint execution code aware of sleds eligible for discretionary services. * Adds tests for all of this new stuff, as well as valid and invalid state transitions -- and also makes sure that if we _do_ end up in an invalid state, things don't break down. Not done here, but in future PRs (to try and keep this PR a manageable size): * We'll add the endpoint to mark the sled as expunged (this is an irreversible operation and will need the appropriate warnings): #5134 * We'll add blueprint code to start removing sleds. * We'll also remove the sled `time_deleted` because it has a lifecycle too complicated to be described that way -- instead, we'll add a `time_decommissioned` field: #5131
- Loading branch information
1 parent
a07cae6
commit a6ef7f9
Showing
53 changed files
with
2,115 additions
and
468 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
//! Database representation of a sled's operator-defined policy. | ||
//! | ||
//! This is related to, but different from `SledState`: a sled's **policy** is | ||
//! its disposition as specified by the operator, while its **state** refers to | ||
//! what's currently on it, as determined by Nexus. | ||
//! | ||
//! For example, a sled might be in the `Active` state, but have a policy of | ||
//! `Expunged` -- this would mean that Nexus knows about resources currently | ||
//! provisioned on the sled, but the operator has said that it should be marked | ||
//! as gone. | ||
use super::impl_enum_type; | ||
use nexus_types::external_api::views::{SledPolicy, SledProvisionPolicy}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
impl_enum_type!( | ||
#[derive(Clone, SqlType, Debug, QueryId)] | ||
#[diesel(postgres_type(name = "sled_policy", schema = "public"))] | ||
pub struct SledPolicyEnum; | ||
|
||
/// This type is not actually public, because [`SledPolicy`] has a somewhat | ||
/// different, friendlier shape while being equivalent -- external code | ||
/// should always use [`SledPolicy`]. | ||
/// | ||
/// However, it must be marked `pub` to avoid errors like `crate-private | ||
/// type `DbSledPolicy` in public interface`. Marking this type `pub`, | ||
/// without actually making it public, tricks rustc in a desirable way. | ||
#[derive(Clone, Copy, Debug, AsExpression, FromSqlRow, Serialize, Deserialize, PartialEq)] | ||
#[diesel(sql_type = SledPolicyEnum)] | ||
pub enum DbSledPolicy; | ||
|
||
// Enum values | ||
InService => b"in_service" | ||
NoProvision => b"no_provision" | ||
Expunged => b"expunged" | ||
); | ||
|
||
/// Converts a [`SledPolicy`] to a version that can be inserted into a | ||
/// database. | ||
pub fn to_db_sled_policy(policy: SledPolicy) -> DbSledPolicy { | ||
match policy { | ||
SledPolicy::InService { | ||
provision_policy: SledProvisionPolicy::Provisionable, | ||
} => DbSledPolicy::InService, | ||
SledPolicy::InService { | ||
provision_policy: SledProvisionPolicy::NonProvisionable, | ||
} => DbSledPolicy::NoProvision, | ||
SledPolicy::Expunged => DbSledPolicy::Expunged, | ||
} | ||
} | ||
|
||
impl From<DbSledPolicy> for SledPolicy { | ||
fn from(policy: DbSledPolicy) -> Self { | ||
match policy { | ||
DbSledPolicy::InService => SledPolicy::InService { | ||
provision_policy: SledProvisionPolicy::Provisionable, | ||
}, | ||
DbSledPolicy::NoProvision => SledPolicy::InService { | ||
provision_policy: SledProvisionPolicy::NonProvisionable, | ||
}, | ||
DbSledPolicy::Expunged => SledPolicy::Expunged, | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
//! Database representation of a sled's state as understood by Nexus. | ||
//! | ||
//! This is related to, but different from `SledState`: a sled's **policy** is | ||
//! its disposition as specified by the operator, while its **state** refers to | ||
//! what's currently on it, as determined by Nexus. | ||
//! | ||
//! For example, a sled might be in the `Active` state, but have a policy of | ||
//! `Expunged` -- this would mean that Nexus knows about resources currently | ||
//! provisioned on the sled, but the operator has said that it should be marked | ||
//! as gone. | ||
use super::impl_enum_type; | ||
use nexus_types::external_api::views; | ||
use serde::{Deserialize, Serialize}; | ||
use std::fmt; | ||
use strum::EnumIter; | ||
|
||
impl_enum_type!( | ||
#[derive(Clone, SqlType, Debug, QueryId)] | ||
#[diesel(postgres_type(name = "sled_state", schema = "public"))] | ||
pub struct SledStateEnum; | ||
|
||
#[derive(Clone, Copy, Debug, AsExpression, FromSqlRow, Serialize, Deserialize, PartialEq, Eq, EnumIter)] | ||
#[diesel(sql_type = SledStateEnum)] | ||
pub enum SledState; | ||
|
||
// Enum values | ||
Active => b"active" | ||
Decommissioned => b"decommissioned" | ||
); | ||
|
||
impl fmt::Display for SledState { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
// Forward to the canonical implementation in nexus-types. | ||
views::SledState::from(*self).fmt(f) | ||
} | ||
} | ||
|
||
impl From<SledState> for views::SledState { | ||
fn from(state: SledState) -> Self { | ||
match state { | ||
SledState::Active => views::SledState::Active, | ||
SledState::Decommissioned => views::SledState::Decommissioned, | ||
} | ||
} | ||
} | ||
|
||
impl From<views::SledState> for SledState { | ||
fn from(state: views::SledState) -> Self { | ||
match state { | ||
views::SledState::Active => SledState::Active, | ||
views::SledState::Decommissioned => SledState::Decommissioned, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.