-
Notifications
You must be signed in to change notification settings - Fork 40
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
[nexus-types] more validation for PlanningInput #5644
[nexus-types] more validation for PlanningInput #5644
Conversation
Created using spr 1.3.6-beta.1
/// - A given external IP or vNIC is only associated with a single Omicron | ||
/// zone. | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct PlanningInput { |
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.
Decided to move this up-top because this file is called planning_input.rs
, and generally I think the main part of a struct should live at the top. (Also I was getting really confused :) )
The only differences here are that we now have a network_resources
field and method.
use derive_where::derive_where; | ||
use serde::{Deserialize, Serialize, Serializer}; | ||
|
||
/// An append-only 1:1:1 (trijective) map for three keys and a value. |
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.
This is append-only for now -- we may add the ability to remove entries in the future if really necessary. (I think at least at the moment it isn't necessary either here or in BlueprintBuilder
.)
Created using spr 1.3.6-beta.1
(Re-do of #5541.)
While reconciling the PlanningInput with the blueprint, I was a bit concerned
about getting nonsensical inputs (e.g. multiple zones get the same IPs) and the
system going haywire. In particular, I was concerned about the Serialize and
Deserialize impls which were seemingly added for reconfigurator-cli. However,
they were liabilities that didn't check for internal invariants.
To address this, this PR introduces the notion of a
TriMap
. ATriMap
isa 1:1:1 map which can be looked up by any one of three keys. Instead of storing
just a regular map, the
PlanningInput
now stores a couple ofTriMap
instances via an intermediate
OmicronZoneNetworkResources
struct.A
TriMap
is implemented as a vector with three indexes. It's a prettystraightforward implementation, and I've also added property-based tests
to ensure that a
TriMap
is always valid (including always deserializingto a valid structure).
At the moment, a
TriMap
does not allow removing entries. If necessary,removals can be implemented by just marking the entry as dead and removing
the keys from the indexes. This is fine for our use case, since
TriMap
saren't long-lived.
I've also factored out the omicron zone IP and NIC code into an
OmicronZoneNetworkResources
struct. In the future, we'll make theBlueprintBuilder
use this struct, so that blueprints are validatedwhenever they're being mutated. We can also add this to the general code
that validates blueprints.