-
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
Fix duplicate entries in IP pools list #4808
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
09f354f
fix list ip pools by deduping results of left outer join
david-crespo 6c0518c
use service IP pool name to filter out internal pool from normal endp…
david-crespo d9d8701
use name lookup helper to look up thing by name!
david-crespo 5896550
fix auth test, which I think is more correct now
david-crespo 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,11 +10,12 @@ use crate::context::OpContext; | |
use crate::db; | ||
use crate::db::collection_insert::AsyncInsertError; | ||
use crate::db::collection_insert::DatastoreCollection; | ||
use crate::db::datastore::SERVICE_IP_POOL_NAME; | ||
use crate::db::error::public_error_from_diesel; | ||
use crate::db::error::public_error_from_diesel_lookup; | ||
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::ExternalIp; | ||
use crate::db::model::IpKind; | ||
use crate::db::model::IpPool; | ||
|
@@ -56,7 +57,6 @@ impl DataStore { | |
pagparams: &PaginatedBy<'_>, | ||
) -> ListResultVec<IpPool> { | ||
use db::schema::ip_pool; | ||
use db::schema::ip_pool_resource; | ||
|
||
opctx | ||
.authorize(authz::Action::ListChildren, &authz::IP_POOL_LIST) | ||
|
@@ -71,14 +71,7 @@ impl DataStore { | |
&pagparams.map_name(|n| Name::ref_cast(n)), | ||
), | ||
} | ||
.left_outer_join(ip_pool_resource::table) | ||
.filter( | ||
ip_pool_resource::resource_id | ||
.ne(*INTERNAL_SILO_ID) | ||
// resource_id is not nullable -- null here means the | ||
// pool has no entry in the join table | ||
.or(ip_pool_resource::resource_id.is_null()), | ||
) | ||
.filter(ip_pool::name.ne(SERVICE_IP_POOL_NAME)) | ||
.filter(ip_pool::time_deleted.is_null()) | ||
.select(IpPool::as_select()) | ||
.get_results_async(&*self.pool_connection_authorized(opctx).await?) | ||
|
@@ -225,48 +218,15 @@ impl DataStore { | |
}) | ||
} | ||
|
||
/// Looks up an IP pool intended for internal services. | ||
/// Look up IP pool intended for internal services by its well-known name. | ||
/// | ||
/// This method may require an index by Availability Zone in the future. | ||
pub async fn ip_pools_service_lookup( | ||
&self, | ||
opctx: &OpContext, | ||
) -> LookupResult<(authz::IpPool, IpPool)> { | ||
use db::schema::ip_pool; | ||
use db::schema::ip_pool_resource; | ||
|
||
opctx | ||
.authorize(authz::Action::ListChildren, &authz::IP_POOL_LIST) | ||
.await?; | ||
|
||
// Look up IP pool by its association with the internal silo. | ||
// We assume there is only one pool for that silo, or at least, | ||
// if there is more than one, it doesn't matter which one we pick. | ||
let (authz_pool, pool) = ip_pool::table | ||
.inner_join(ip_pool_resource::table) | ||
.filter(ip_pool::time_deleted.is_null()) | ||
.filter( | ||
ip_pool_resource::resource_type | ||
.eq(IpPoolResourceType::Silo) | ||
.and(ip_pool_resource::resource_id.eq(*INTERNAL_SILO_ID)), | ||
) | ||
.select(IpPool::as_select()) | ||
.get_result_async(&*self.pool_connection_authorized(opctx).await?) | ||
.await | ||
.map_err(|e| public_error_from_diesel(e, ErrorHandler::Server)) | ||
.map(|ip_pool| { | ||
( | ||
authz::IpPool::new( | ||
authz::FLEET, | ||
ip_pool.id(), | ||
LookupType::ByCompositeId( | ||
"Service IP Pool".to_string(), | ||
), | ||
), | ||
ip_pool, | ||
) | ||
})?; | ||
Ok((authz_pool, pool)) | ||
let name = SERVICE_IP_POOL_NAME.parse().unwrap(); | ||
LookupPath::new(&opctx, self).ip_pool_name(&Name(name)).fetch().await | ||
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. 🤦 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 count this as a win, haha. |
||
} | ||
|
||
/// Creates a new IP pool. | ||
|
@@ -374,15 +334,10 @@ impl DataStore { | |
authz_pool: &authz::IpPool, | ||
) -> LookupResult<bool> { | ||
use db::schema::ip_pool; | ||
use db::schema::ip_pool_resource; | ||
|
||
ip_pool::table | ||
.inner_join(ip_pool_resource::table) | ||
.filter(ip_pool::id.eq(authz_pool.id())) | ||
.filter( | ||
ip_pool_resource::resource_type.eq(IpPoolResourceType::Silo), | ||
) | ||
.filter(ip_pool_resource::resource_id.eq(*INTERNAL_SILO_ID)) | ||
.filter(ip_pool::name.eq(SERVICE_IP_POOL_NAME)) | ||
.filter(ip_pool::time_deleted.is_null()) | ||
.select(ip_pool::id) | ||
.first_async::<Uuid>( | ||
|
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
Oops, something went wrong.
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.
Yeah, so much better 🙌