-
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
Small IP pools fixes #4007
Merged
Merged
Small IP pools fixes #4007
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -6,7 +6,6 @@ | |||||||||||||||||||||
|
||||||||||||||||||||||
use super::DataStore; | ||||||||||||||||||||||
use crate::authz; | ||||||||||||||||||||||
use crate::authz::ApiResource; | ||||||||||||||||||||||
use crate::context::OpContext; | ||||||||||||||||||||||
use crate::db; | ||||||||||||||||||||||
use crate::db::collection_insert::AsyncInsertError; | ||||||||||||||||||||||
|
@@ -16,7 +15,6 @@ use crate::db::error::public_error_from_diesel_pool; | |||||||||||||||||||||
use crate::db::error::ErrorHandler; | ||||||||||||||||||||||
use crate::db::fixed_data::silo::INTERNAL_SILO_ID; | ||||||||||||||||||||||
use crate::db::identity::Resource; | ||||||||||||||||||||||
use crate::db::lookup::LookupPath; | ||||||||||||||||||||||
use crate::db::model::IpPool; | ||||||||||||||||||||||
use crate::db::model::IpPoolRange; | ||||||||||||||||||||||
use crate::db::model::IpPoolUpdate; | ||||||||||||||||||||||
|
@@ -111,32 +109,6 @@ impl DataStore { | |||||||||||||||||||||
.map_err(|e| public_error_from_diesel_pool(e, ErrorHandler::Server)) | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
/// Looks up an IP pool by name if it does not conflict with your current scope. | ||||||||||||||||||||||
pub(crate) async fn ip_pools_fetch( | ||||||||||||||||||||||
&self, | ||||||||||||||||||||||
opctx: &OpContext, | ||||||||||||||||||||||
name: &Name, | ||||||||||||||||||||||
) -> LookupResult<IpPool> { | ||||||||||||||||||||||
let authz_silo_id = opctx.authn.silo_required()?.id(); | ||||||||||||||||||||||
|
||||||||||||||||||||||
let (.., authz_pool, pool) = LookupPath::new(opctx, &self) | ||||||||||||||||||||||
.ip_pool_name(&name) | ||||||||||||||||||||||
// any authenticated user can CreateChild on an IP pool. this is | ||||||||||||||||||||||
// meant to represent allocating an IP | ||||||||||||||||||||||
.fetch_for(authz::Action::CreateChild) | ||||||||||||||||||||||
.await?; | ||||||||||||||||||||||
|
||||||||||||||||||||||
// You can't look up a pool by name if it conflicts with your current | ||||||||||||||||||||||
// scope, i.e., if it has a silo it is different from your current silo | ||||||||||||||||||||||
if let Some(pool_silo_id) = pool.silo_id { | ||||||||||||||||||||||
if pool_silo_id != authz_silo_id { | ||||||||||||||||||||||
return Err(authz_pool.not_found()); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
Ok(pool) | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
/// Looks up an IP pool intended for internal services. | ||||||||||||||||||||||
/// | ||||||||||||||||||||||
/// This method may require an index by Availability Zone in the future. | ||||||||||||||||||||||
|
@@ -465,7 +437,6 @@ mod test { | |||||||||||||||||||||
use crate::db::datastore::datastore_test; | ||||||||||||||||||||||
use crate::db::model::IpPool; | ||||||||||||||||||||||
use assert_matches::assert_matches; | ||||||||||||||||||||||
use nexus_db_model::Name; | ||||||||||||||||||||||
use nexus_test_utils::db::test_setup_database; | ||||||||||||||||||||||
use nexus_types::identity::Resource; | ||||||||||||||||||||||
use omicron_common::api::external::{Error, IdentityMetadataCreateParams}; | ||||||||||||||||||||||
|
@@ -510,12 +481,13 @@ mod test { | |||||||||||||||||||||
name: "non-default-for-silo".parse().unwrap(), | ||||||||||||||||||||||
description: "".to_string(), | ||||||||||||||||||||||
}; | ||||||||||||||||||||||
let _ = datastore | ||||||||||||||||||||||
datastore | ||||||||||||||||||||||
.ip_pool_create( | ||||||||||||||||||||||
&opctx, | ||||||||||||||||||||||
IpPool::new(&identity, Some(silo_id), /*default= */ false), | ||||||||||||||||||||||
) | ||||||||||||||||||||||
.await; | ||||||||||||||||||||||
.await | ||||||||||||||||||||||
.expect("Failed to create silo non-default IP pool"); | ||||||||||||||||||||||
|
||||||||||||||||||||||
// because that one was not a default, when we ask for the silo default | ||||||||||||||||||||||
// pool, we still get the fleet default | ||||||||||||||||||||||
|
@@ -530,9 +502,10 @@ mod test { | |||||||||||||||||||||
name: "default-for-silo".parse().unwrap(), | ||||||||||||||||||||||
description: "".to_string(), | ||||||||||||||||||||||
}; | ||||||||||||||||||||||
let _ = datastore | ||||||||||||||||||||||
datastore | ||||||||||||||||||||||
.ip_pool_create(&opctx, IpPool::new(&identity, Some(silo_id), true)) | ||||||||||||||||||||||
.await; | ||||||||||||||||||||||
.await | ||||||||||||||||||||||
.expect("Failed to create silo default IP pool"); | ||||||||||||||||||||||
|
||||||||||||||||||||||
// now when we ask for the default pool, we get the one we just made | ||||||||||||||||||||||
let ip_pool = datastore | ||||||||||||||||||||||
|
@@ -541,13 +514,6 @@ mod test { | |||||||||||||||||||||
.expect("Failed to get silo's default IP pool"); | ||||||||||||||||||||||
assert_eq!(ip_pool.name().as_str(), "default-for-silo"); | ||||||||||||||||||||||
|
||||||||||||||||||||||
// if we ask for the fleet default by name, we can still get that one | ||||||||||||||||||||||
let ip_pool = datastore | ||||||||||||||||||||||
.ip_pools_fetch(&opctx, &Name("default".parse().unwrap())) | ||||||||||||||||||||||
.await | ||||||||||||||||||||||
.expect("Failed to get fleet default IP pool"); | ||||||||||||||||||||||
assert_eq!(ip_pool.id(), fleet_default_pool.id()); | ||||||||||||||||||||||
|
||||||||||||||||||||||
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't do this anymore because the method is gone, but this integration test covers it. omicron/nexus/tests/integration_tests/instances.rs Lines 3442 to 3451 in 01e730a
|
||||||||||||||||||||||
// and we can't create a second default pool for the silo | ||||||||||||||||||||||
let identity = IdentityMetadataCreateParams { | ||||||||||||||||||||||
name: "second-default-for-silo".parse().unwrap(), | ||||||||||||||||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 did not make sense as a function here. All the logic was related to the calling context.