Skip to content

Commit

Permalink
post-rebase update for nullable restart policies
Browse files Browse the repository at this point in the history
Commit 86b0ae6 changed the default
value for `instance.auto_restart_policy` to `NULL` when it hasn't been
explicitly specified, so this branch has to be updated to track that.
See #6499 (comment)
  • Loading branch information
hawkw committed Sep 4, 2024
1 parent 98484f6 commit 2b3716c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
11 changes: 9 additions & 2 deletions nexus/db-model/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ impl Instance {
ncpus: params.ncpus.into(),
memory: params.memory.into(),
hostname: params.hostname.to_string(),
auto_restart_policy: params.auto_restart_policy.clone().into(),
auto_restart_policy: params
.auto_restart_policy
.clone()
.map(Into::into),
runtime_state,

updater_gen: Generation::new(),
Expand All @@ -124,7 +127,11 @@ impl Instance {

/// Returns `true` if this instance can be automatically restarted.
pub fn can_reincarnate(&self) -> bool {
self.runtime_state.can_reincarnate(self.auto_restart_policy)
self.auto_restart_policy
.map(|policy| self.runtime_state.can_reincarnate(policy))
// If the instance does not have a specified auto-restart policy,
// assume it cannot be restarted.
.unwrap_or(false)
}
}

Expand Down
5 changes: 1 addition & 4 deletions nexus/types/src/external_api/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,11 +1061,8 @@ pub struct InstanceCreate {

/// A policy that indicates whether the control plane should automatically
/// restart this instance if it fails.
///
/// If this is not provided, it defaults to the "sled_failures_only"
/// auto-restart policy.
#[serde(default)]
pub auto_restart_policy: InstanceAutoRestart,
pub auto_restart_policy: Option<InstanceAutoRestart>,
}

#[inline]
Expand Down
7 changes: 3 additions & 4 deletions openapi/nexus.json
Original file line number Diff line number Diff line change
Expand Up @@ -15243,10 +15243,9 @@
"type": "object",
"properties": {
"auto_restart_policy": {
"description": "A policy that indicates whether the control plane should automatically restart this instance if it fails.\n\nIf this is not provided, it defaults to the \"sled_failures_only\" auto-restart policy.",
"default": {
"type": "sled_failures_only"
},
"nullable": true,
"description": "A policy that indicates whether the control plane should automatically restart this instance if it fails.",
"default": null,
"allOf": [
{
"$ref": "#/components/schemas/InstanceAutoRestart"
Expand Down

0 comments on commit 2b3716c

Please sign in to comment.