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

Generalize network_interface table to allow for new kinds of NICs. #2767

Merged
merged 7 commits into from
Apr 6, 2023

Conversation

luqmana
Copy link
Contributor

@luqmana luqmana commented Apr 5, 2023

Since I wanted to split up #2419 a bit, took the opportunity to get rid of the
duplicate table I added to get going initially.

Previously, all NIC records in the DB were tied to a guest instance. In
enabling OPTE usage for services, it'd be nice to be able to reuse a lot
of the same NetworkInterface machinery we already have without
duplicating it completely. This commit adds a new kind column to the
network_interface table which at the moment will be either 'instance'
(NICs attached to a guest VM and exposed in the external API) or
'service' (NIC associated with an internal control plane service). The
previous instance_id column is renamed to parent_id and the table to
which it refers to as a FK is now dependant on the kind (either
instance or service).

Since a lot of the db and authz lookup macros end up relying on the
specific column name, this also introduces database views for each kind
which can be queried as if they were their own tables. This also allows
differentiating the different kinds of NICs as necessary.

CockroachDB, unlike Postgres, does not allow inserting or updating into
simple view and so we also model the base table itself to execute
queries that modify it.

From an external perspective, this doesn't change anything (modulo some
renaming from NetworkInterface* -> InstanceNetworkInterface*) in
that all external APIs still only deal with instance NICs.

There are some basic definitions for service NICs included but those
will be more fleshed in subsequent commits.

luqmana added 3 commits April 4, 2023 19:32
Previously, all NIC records in the DB were tied to a guest instance. In
enabling OPTE usage for services, it'd be nice to be able to reuse a lot
of the same NetworkInterface machinery we already have without
duplicating it completely. This commit adds a new `kind` column to the
`network_interface` table which at the moment will be either 'instance'
(NICs attached to a guest VM and exposed in the external API) or
'service' (NIC associated with an internal control plane service). The
previous `instance_id` column is renamed to `parent_id` and the table to
which it refers to as a FK is now dependant on the kind (either
`instance` or `service`).

Since a lot of the db and authz lookup macros end up relying on the
specific column name, this also introduces database views for each kind
which can be queried as if they were their own tables. This also allows
differentiating the different kinds of NICs as necessary.

CockroachDB, unlike Postgres, does not allow inserting or updating into
simple view and so we also model the base table itself to execute
queries that modify it.

From an external perspective, this doesn't change anything (modulo some
renaming from `NetworkInterface*` -> `InstanceNetworkInterface*`) in
that all external APIs still only deal with instance NICs.

There are some basic definitions for service NICs included but those
will be more fleshed in subsequent commits.
@zephraph
Copy link
Contributor

zephraph commented Apr 5, 2023

This is great. I was working on implementing silo level images and doing it in a way that was much harder than what you've done here. I'm definitely interested in following this approach.

Co-authored-by: Justin Bennett <oxide@just-be.dev>
Copy link
Contributor

@jmpesp jmpesp left a comment

Choose a reason for hiding this comment

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

Looks good, one comment needs fixing

nexus/db-queries/src/db/datastore/network_interface.rs Outdated Show resolved Hide resolved
@luqmana luqmana merged commit a9680cb into main Apr 6, 2023
@luqmana luqmana deleted the luqmana/generic-instance-table branch April 6, 2023 18:50
zephraph added a commit that referenced this pull request Apr 19, 2023
Implements silo level images as a replacement for global images. 

This implementation preserves a single API endpoint `/v1/images` and a
single database table to store all images. It uses database views like
#2767 to map the notion of `ProjectImage` and `SiloImage` to the images
table. From an authz perspective there are actually _three_ resources
represented:`SiloImage`, `ProjectImage`, and `Image`. As the names
suggest, `SiloImage` is the child of a silo and `ProjectImage` is the
child of a project. `Image` occupies an odd space where it's currently
considered the child of a Silo though it technically straddles both
positions in the hierarchy.

---------

Co-authored-by: David Crespo <david-crespo@users.noreply.github.com>
Co-authored-by: David Crespo <david@oxidecomputer.com>
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.

3 participants