Skip to content

Commit

Permalink
[nexus] allow reconfiguring auto-restart policies (#6743)
Browse files Browse the repository at this point in the history
This commit extends the `instance-reconfigure` API endpoint added in
#6585 to also allow setting instance auto-restart policies (as added in
#6503).

I've also added the actual auto-restart policy to the external API
instance view, along with the boolean `auto_restart_enabled` added in
#6503. This way, it's possible to change just the boot disk by providing
the current auto-restart policy in an instance POST.
  • Loading branch information
hawkw authored Oct 3, 2024
1 parent aa7b087 commit c52827d
Show file tree
Hide file tree
Showing 10 changed files with 490 additions and 231 deletions.
18 changes: 17 additions & 1 deletion common/src/api/external/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,20 @@ pub struct InstanceAutoRestartStatus {
#[serde(rename = "auto_restart_enabled")]
pub enabled: bool,

/// The auto-restart policy configured for this instance, or `None` if no
/// explicit policy is configured.
///
/// If this is not present, then this instance uses the default auto-restart
/// policy, which may or may not allow it to be restarted. The
/// `auto_restart_enabled` field indicates whether the instance will be
/// automatically restarted.
//
// Rename this field, as the struct is `#[serde(flatten)]`ed into the
// `Instance` type, and we would like the field to be prefixed with
// `auto_restart`.
#[serde(rename = "auto_restart_policy")]
pub policy: Option<InstanceAutoRestartPolicy>,

/// The time at which the auto-restart cooldown period for this instance
/// completes, permitting it to be automatically restarted again. If the
/// instance enters the `Failed` state, it will not be restarted until after
Expand All @@ -1233,7 +1247,9 @@ pub struct InstanceAutoRestartStatus {

/// A policy determining when an instance should be automatically restarted by
/// the control plane.
#[derive(Copy, Clone, Debug, Deserialize, Serialize, JsonSchema)]
#[derive(
Copy, Clone, Debug, Deserialize, Serialize, JsonSchema, Eq, PartialEq,
)]
#[serde(rename_all = "snake_case")]
pub enum InstanceAutoRestartPolicy {
/// The instance should not be automatically restarted by the control plane
Expand Down
5 changes: 5 additions & 0 deletions nexus/db-model/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,4 +537,9 @@ mod optional_time_delta {
pub struct InstanceUpdate {
#[diesel(column_name = boot_disk_id)]
pub boot_disk_id: Option<Uuid>,

/// The auto-restart policy for this instance. If this is `None`, it will
/// set the instance's auto-restart policy to `NULL`.
#[diesel(column_name = auto_restart_policy)]
pub auto_restart_policy: Option<InstanceAutoRestartPolicy>,
}
Loading

0 comments on commit c52827d

Please sign in to comment.