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] Endpoint to list IP pools for silo, add is_default to silo-scoped IP pools list #4843

Merged
merged 6 commits into from
Jan 20, 2024

Conversation

david-crespo
Copy link
Contributor

@david-crespo david-crespo commented Jan 18, 2024

Fixes #4752
Fixes #4763

The main trick here is introducing views::SiloIpPool, which is the same as views::IpPool except it also has is_default on it. It only makes sense in the context of a particular silo because is_default is only defined for a (pool, silo) pair, not for a pool alone.

  • Add GET /v1/system/silos/{silo}/ip-pools
  • /v1/ip-pools and /v1/ip-pools/{pool} should return SiloIpPool too
  • Tests for /v1/system/silos/{silo}/ip-pools
  • We can't have both SiloIpPool and IpPoolSilo, cleaned up by changing:
    • views::IpPoolSilo -> views::SiloIpSiloLink
    • params::IpPoolSiloLink -> views::IpPoolLinkSilo

@david-crespo david-crespo force-pushed the silo-ip-pools-endpoint branch from b432677 to 06d1fea Compare January 18, 2024 22:24
@david-crespo david-crespo marked this pull request as ready for review January 19, 2024 17:17
@david-crespo david-crespo requested a review from zephraph January 19, 2024 17:23
.filter(ip_pool::time_deleted.is_null())
.select(db::model::IpPool::as_select())
.select(<(IpPool, IpPoolResource)>::as_select())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

neat trick. initially I tried (IpPool::as_select(), IpPoolResource::as_select()) but it wanted the above

)
.await
.map_err(|e| public_error_from_diesel(e, ErrorHandler::Server))
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just realized this query is exactly the same as the one above — the only difference is whether you're passing in a silo or pulling the current silo from auth context. I will extract a shared function.

Copy link
Contributor

Choose a reason for hiding this comment

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

This came up in some of my work too. I just dropped the current version altogether and only left on that takes a given argument. The app layer can pass in the current silo when needed.

Comment on lines +1542 to +1549
// TODO: this could just list views::Silo -- it's not like knowing silo_id
// and nothing else is particularly useful -- except we also want to say
// whether the pool is marked default on each silo. So one option would
// be to do the same as we did with SiloIpPool -- include is_default on
// whatever the thing is. Still... all we'd have to do to make this usable
// in both places would be to make it { ...IpPool, silo_id, silo_name,
// is_default }
) -> Result<HttpResponseOk<ResultsPage<views::IpPoolSiloLink>>, HttpError> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if views::Silo shouldn't just be updated with default_ip_pool: Option<Uuid> and the silo just be returned here. There's only ever one default pool, it seems like a good thing to latch onto the silo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would mean every query for silos would have to join to the ip_pool_resource table and return both the silo and the link so we can tack on the pool ID.

Copy link
Contributor

Choose a reason for hiding this comment

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

Despite the increased cost I still think it'd be a UX improvement for the API. That said, it doesn't need to be done here. I'm not a huge fan of returning the link, but it's fine for now. It gives them all the info they need to get whatever else they need.

Copy link
Contributor

@zephraph zephraph left a comment

Choose a reason for hiding this comment

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

Other than removing the duplicate query, this mostly looks good.


// check ability to list silos in general
opctx.authorize(authz::Action::ListChildren, &authz::FLEET).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.

Noticed this check was missing here

@david-crespo david-crespo enabled auto-merge (squash) January 19, 2024 21:33
@david-crespo david-crespo merged commit 205382f into main Jan 20, 2024
21 checks passed
@david-crespo david-crespo deleted the silo-ip-pools-endpoint branch January 20, 2024 07:30
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.

Need operator endpoint to list IP pools for a silo Give end user a way to tell which IP pool is silo default
2 participants