-
Notifications
You must be signed in to change notification settings - Fork 64
Put type specific information into DiskType #9543
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1433,11 +1433,22 @@ impl SimpleIdentityOrName for AntiAffinityGroupMember { | |
|
|
||
| // DISKS | ||
|
|
||
| #[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)] | ||
| #[serde(rename_all = "snake_case")] | ||
| #[derive(Clone, Debug, Deserialize, Serialize, JsonSchema, PartialEq)] | ||
| #[serde(tag = "type", rename_all = "snake_case")] | ||
| pub enum DiskType { | ||
| Distributed, | ||
| Local, | ||
| Distributed { | ||
| /// ID of snapshot from which disk was created, if any | ||
| snapshot_id: Option<Uuid>, | ||
| /// ID of image from which disk was created, if any | ||
| image_id: Option<Uuid>, | ||
| }, | ||
|
|
||
| Local { | ||
| /// ID of the sled this local disk is allocated on, if it has been | ||
| /// allocated. Once allocated it cannot be changed or migrated. | ||
| #[schemars(with = "Option<Uuid>")] | ||
| sled_id: Option<SledUuid>, | ||
| }, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 done in 8f96790
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The downside here is you're now looking at diff --git a/common/src/api/external/mod.rs b/common/src/api/external/mod.rs
index 287f1c8e53..3879572af5 100644
--- a/common/src/api/external/mod.rs
+++ b/common/src/api/external/mod.rs
@@ -1434,7 +1434,7 @@
// DISKS
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema, PartialEq)]
-#[serde(tag = "type", rename_all = "snake_case")]
+#[serde(tag = "disk_type", content = "details", rename_all = "snake_case")]
pub enum DiskType {
Distributed {
/// ID of snapshot from which disk was created, if any
@@ -1460,6 +1460,7 @@
pub size: ByteCount,
pub block_size: ByteCount,
pub state: DiskState,
+ #[serde(flatten)]
pub disk_type: DiskType,
}
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking about it more, I think However, I can't really picture how the types for that would work in TypeScript (I thought TS wants a discriminator inside the The most elegant thing I can come up with in TypeScript is something like type Disk = { /* shared fields */ } & (
| { disk_type: "distributed", /* dist fields */ }
| { disk_type: "local", /* local fields */ }
)Turns out TypeScript does actually handle this pretty well, but I'm not sure whether I could generate this code from the schema.
And here it is with
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ahl would appreciate your opinion on whether
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for catching this! We rely on a discriminator field in the Go SDK and not having it would have been a pain to work around. |
||
| } | ||
|
|
||
| /// View of a Disk | ||
|
|
@@ -1446,14 +1457,9 @@ pub struct Disk { | |
| #[serde(flatten)] | ||
| pub identity: IdentityMetadata, | ||
| pub project_id: Uuid, | ||
| /// ID of snapshot from which disk was created, if any | ||
| pub snapshot_id: Option<Uuid>, | ||
| /// ID of image from which disk was created, if any | ||
| pub image_id: Option<Uuid>, | ||
| pub size: ByteCount, | ||
| pub block_size: ByteCount, | ||
| pub state: DiskState, | ||
| pub device_path: String, | ||
| pub disk_type: DiskType, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. perhaps disk_details or disk_info
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kind of generic but it's probably better than
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think "details" implies "specific to whatever the fuck this thing is", but I'm happy to let you have this one since I had the last one ;-)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally this would be something like I'm game for There's more fields than just
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don’t love backend anyway because while you can only have an image ID if you have the distributed backend, the image ID isn’t a property of the backend, it’s just metadata on the disk you can have when you use the distributed backend. I think you’re right that
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, you know, I kind of like
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm game for that. It gives us some symmetry across the create and read paths. |
||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -263,40 +263,34 @@ impl Into<api::external::Disk> for Disk { | |
| fn into(self) -> api::external::Disk { | ||
| match self { | ||
| Disk::Crucible(CrucibleDisk { disk, disk_type_crucible }) => { | ||
| // XXX can we remove this? | ||
| let device_path = format!("/mnt/{}", disk.name().as_str()); | ||
| api::external::Disk { | ||
| identity: disk.identity(), | ||
| project_id: disk.project_id, | ||
| snapshot_id: disk_type_crucible.create_snapshot_id, | ||
| image_id: disk_type_crucible.create_image_id, | ||
| size: disk.size.into(), | ||
| block_size: disk.block_size.into(), | ||
| state: disk.state().into(), | ||
| device_path, | ||
| disk_type: api::external::DiskType::Distributed, | ||
| disk_type: api::external::DiskType::Distributed { | ||
| snapshot_id: disk_type_crucible.create_snapshot_id, | ||
| image_id: disk_type_crucible.create_image_id, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| Disk::LocalStorage(LocalStorageDisk { | ||
| disk, | ||
| disk_type_local_storage: _, | ||
| local_storage_dataset_allocation: _, | ||
| }) => { | ||
| // XXX can we remove this? | ||
| let device_path = format!("/mnt/{}", disk.name().as_str()); | ||
|
Comment on lines
-286
to
-287
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CAN WE??? |
||
| api::external::Disk { | ||
| identity: disk.identity(), | ||
| project_id: disk.project_id, | ||
| snapshot_id: None, | ||
| image_id: None, | ||
| size: disk.size.into(), | ||
| block_size: disk.block_size.into(), | ||
| state: disk.state().into(), | ||
| device_path, | ||
| disk_type: api::external::DiskType::Local, | ||
| } | ||
| } | ||
| local_storage_dataset_allocation, | ||
| }) => api::external::Disk { | ||
| identity: disk.identity(), | ||
| project_id: disk.project_id, | ||
| size: disk.size.into(), | ||
| block_size: disk.block_size.into(), | ||
| state: disk.state().into(), | ||
| disk_type: api::external::DiskType::Local { | ||
| sled_id: local_storage_dataset_allocation | ||
| .map(|allocation| allocation.sled_id()), | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
| } | ||
|
|
||




There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the utility of this? I'm always loth to give users data that they can only misuse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's in there to have something to point to when users get errors trying to attach disks to instances, or start instances: if the attached local storage disks are on different sleds then it will never work. It's only on the view of Disk, it will never be something we accept as a parameter.
Nexus doesn't currently reject disk attachment requests that would create this situation, that's still work to do (#9520)