Skip to content
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

Conversation

sunshowers
Copy link
Contributor

@sunshowers sunshowers commented Apr 27, 2024

(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. A TriMap is
a 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 of TriMap
instances via an intermediate OmicronZoneNetworkResources struct.

A TriMap is implemented as a vector with three indexes. It's a pretty
straightforward implementation, and I've also added property-based tests
to ensure that a TriMap is always valid (including always deserializing
to 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 TriMaps
aren'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 the
BlueprintBuilder use this struct, so that blueprints are validated
whenever they're being mutated. We can also add this to the general code
that validates blueprints.

Created using spr 1.3.6-beta.1
@sunshowers sunshowers changed the title [RFC] [nexus-types] more validation for PlanningInput [nexus-types] more validation for PlanningInput Apr 27, 2024
/// - A given external IP or vNIC is only associated with a single Omicron
/// zone.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PlanningInput {
Copy link
Contributor Author

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.
Copy link
Contributor Author

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.)

nexus/types/src/deployment/tri_map.rs Outdated Show resolved Hide resolved
Created using spr 1.3.6-beta.1
@sunshowers sunshowers enabled auto-merge (squash) May 14, 2024 03:02
@sunshowers sunshowers merged commit 949c6ab into main May 14, 2024
21 checks passed
@sunshowers sunshowers deleted the sunshowers/spr/rfc-nexus-types-more-validation-for-planninginput-1 branch May 14, 2024 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants