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

Clean up IP pool resolution from NameOrId #5674

Merged
merged 3 commits into from
May 1, 2024
Merged

Conversation

david-crespo
Copy link
Contributor

Followup to #5660, specifically #5660 (comment). I didn't do it quite as suggested, basically because I think datastore functions being aware of NameOrId is a bad thing as that is, to me, an API concept that we should have resolved to something real by the time we get to the datastore functions. This is still a little odd and a little redundant, but it is cleaner and more consistent.

In each case (floating IP create, probe create, instance ephemeral IP allocated) we are doing the following:

  1. In the Nexus layer, turn Option<NameOrId> into Option<authz::IpPool> (this is a DB query of course)
  2. In the datastore, call the new resolve_pool_for_allocation, which
    a. If a pool is specified, makes sure it's linked to the current silo, otherwise 404
    b. If a pool is not specified, get the default pool for the current silo
    c. Either way, make sure we have CreateChild on the pool (we always do if we're authenticated at all, but that could change in the future)
  3. At this point we definitely have an authz::IpPool and can get on with whatever allocation

@@ -50,7 +50,6 @@ use omicron_common::api::external::Error;
use omicron_common::api::external::IdentityMetadataCreateParams;
use omicron_common::api::external::ListResultVec;
use omicron_common::api::external::LookupResult;
use omicron_common::api::external::NameOrId;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getting this out of here is a good thing

@@ -15,7 +15,6 @@ use diesel::{ExpressionMethods, QueryDsl, SelectableHelper};
use nexus_db_model::IncompleteNetworkInterface;
use nexus_db_model::Probe;
use nexus_db_model::VpcSubnet;
use nexus_types::external_api::params;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getting this out of here is a good thing

let (.., pool) = LookupPath::new(opctx, &self)
.ip_pool_id(authz_pool.id())
.fetch_for(authz::Action::CreateChild)
.await?;
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 fetch was not necessary at all — replaced by opctx.authorize call in resolve_pool_for_allocation

.0,
),
None => None,
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While overall I think this PR is a net improvement already, I might try to roll up this logic further with what's in resolve_pool_for_allocation because it is awkward to split up this part of the resolution of the pool from the rest.

@david-crespo david-crespo requested a review from luqmana April 30, 2024 20:49
Copy link
Contributor

@luqmana luqmana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for cleaning that up! LGTM w/ one suggestion

@@ -84,33 +83,14 @@ impl DataStore {
opctx: &OpContext,
ip_id: Uuid,
probe_id: Uuid,
pool_name: Option<NameOrId>,
pool: Option<authz::IpPool>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind giving allocate_instance_snat_ip similar treatment so we're consistent across everything here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes. I didn’t look hard enough.

Copy link
Contributor Author

@david-crespo david-crespo May 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Splitting this into yet another PR (#5678) because it fixes #5043 and changes semantics.

@david-crespo david-crespo merged commit d901636 into main May 1, 2024
20 checks passed
@david-crespo david-crespo deleted the fip-attach-refactor branch May 1, 2024 03:24
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.

2 participants