From 078b90ba8e6c357c859714d36da1ae16deb6917d Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Wed, 4 Sep 2024 09:28:58 -0700 Subject: [PATCH] post-rebase update for nullable restart policies Commit 86b0ae678a9b31d5f0d2b3915ca558b847ee0a0e 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 https://github.com/oxidecomputer/omicron/pull/6499#issuecomment-2327573124 --- nexus/db-model/src/instance.rs | 11 +++++++++-- nexus/types/src/external_api/params.rs | 5 +---- openapi/nexus.json | 7 +++---- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/nexus/db-model/src/instance.rs b/nexus/db-model/src/instance.rs index 52cee475f2..966be5e75f 100644 --- a/nexus/db-model/src/instance.rs +++ b/nexus/db-model/src/instance.rs @@ -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(), @@ -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) } } diff --git a/nexus/types/src/external_api/params.rs b/nexus/types/src/external_api/params.rs index 6c8c029a35..d57c2a60b4 100644 --- a/nexus/types/src/external_api/params.rs +++ b/nexus/types/src/external_api/params.rs @@ -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, } #[inline] diff --git a/openapi/nexus.json b/openapi/nexus.json index 7d8d574704..713670fc07 100644 --- a/openapi/nexus.json +++ b/openapi/nexus.json @@ -15227,10 +15227,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"