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

System Update API #2100

Merged
merged 50 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
b7b60c0
stub system update status, list, and detail
david-crespo Dec 29, 2022
9a5ae8c
wrap semver::Version and impl JsonSchema for it
david-crespo Dec 29, 2022
468a263
/components endpoints for update detail and system version, tweak names
david-crespo Dec 29, 2022
1ce8ae6
add update start and stop without deciding what their responses are
david-crespo Dec 29, 2022
9d86f52
move AssetIdentityMetadata next to Asset, add identity() method
david-crespo Dec 30, 2022
24ab40c
add system updates table
david-crespo Dec 30, 2022
cde4429
stub integration tests for stubbed endpoints
david-crespo Jan 2, 2023
859605c
so damn close with the component join table but it doesn't compile
david-crespo Jan 2, 2023
e3e3123
thanks @smklein
david-crespo Jan 2, 2023
4eed1d7
update openapi spec, fix nexus method name
david-crespo Jan 2, 2023
afe32c1
Merge branch 'main' into stub-update-api
david-crespo Jan 2, 2023
186994e
paginate list of updates
david-crespo Jan 3, 2023
ea4bbde
implement to/from sql for semver version
david-crespo Jan 4, 2023
38e3444
Merge branch 'main' into stub-update-api
david-crespo Jan 4, 2023
dea5ada
fix VersionStatus enum in openapi spec with serde tag
david-crespo Jan 4, 2023
a7d898c
use list of component types from RFD 300
david-crespo Jan 4, 2023
54e1f45
updateable components table (TODO: status and reason)
david-crespo Jan 4, 2023
34ebe77
nexus method to create a system update + test for it
david-crespo Jan 5, 2023
4c59334
create_component_update() and working test
david-crespo Jan 5, 2023
7aa207c
other system update should not be associated with any component updates
david-crespo Jan 5, 2023
b9ac8b6
create updateable component, test for it
david-crespo Jan 5, 2023
c143f8a
make the unauthorized things pass, mediocrely
david-crespo Jan 5, 2023
c6f9dff
update iam roles policy test and nexus_tags.txt
david-crespo Jan 5, 2023
78e3fb7
make existing system update refresh endpoint match the rest
david-crespo Jan 7, 2023
8ffa99a
Merge branch 'main' into stub-update-api
david-crespo Jan 12, 2023
1eeaf4e
make version the PK of the system update, fetch by version instead of id
david-crespo Jan 12, 2023
c5b6264
remove id from system_update. horrible because it goes against the grain
david-crespo Jan 12, 2023
ffea521
Revert "remove id from system_update. horrible because it goes agains…
david-crespo Jan 12, 2023
190af7c
change comment: we're not getting rid of the ID. update openapi spec
david-crespo Jan 12, 2023
fde6e98
clean up around TODO comments, add SystemUpdateDeployment view, fix t…
david-crespo Jan 13, 2023
3ef6f38
can't give the params the same name as the view
david-crespo Jan 13, 2023
f8898a8
Merge branch 'main' into stub-update-api
david-crespo Jan 19, 2023
c145d60
Merge branch 'main' into stub-update-api
david-crespo Jan 19, 2023
2660a52
add update deployments table and list/view endpoints
david-crespo Jan 23, 2023
b3df99c
Merge main into stub-update-api
david-crespo Jan 23, 2023
9ec0773
fix clippy and tests
david-crespo Jan 23, 2023
e992960
Merge branch 'main' into stub-update-api
david-crespo Jan 25, 2023
3dc2bb0
plumb through UpdateStatus, SystemUpdateDeployment -> UpdateDeployment
david-crespo Jan 25, 2023
0746adf
version_sort column that lets us sort by version
david-crespo Jan 25, 2023
5a2b99f
validate that semver version has low enough numbers for our sort hack
david-crespo Jan 26, 2023
a28b371
add version_sort to updateable_component so we can get low/high for s…
david-crespo Jan 26, 2023
0d22dd0
better test to prove we're not doing normal string sort on versions
david-crespo Jan 26, 2023
53d7d03
component tree and component update tree are no longer trees
david-crespo Jan 26, 2023
07dea02
use a transaction, working integration test for system version endpoint
david-crespo Jan 26, 2023
05635bd
put verb first in nexus function names
david-crespo Jan 26, 2023
9575587
create_update_deployment (doesn't check if we're already updating)
david-crespo Jan 27, 2023
6cdfe40
fix ON CONFLICT by not doing that. add tests for version conflicts
david-crespo Jan 27, 2023
b7a0b93
change system update pk back to ID, exempt /system/version from auth …
david-crespo Jan 27, 2023
a1772af
updateable component should have both own version and system version
david-crespo Jan 28, 2023
f109cfe
don't blame buildomat. look inward
david-crespo Jan 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ ring = "0.16"
rustfmt-wrapper = "0.2"
samael = { git = "https://github.com/njaremko/samael", features = ["xmlsec"], branch = "master" }
schemars = "0.8.10"
semver = { version = "1.0.16", features = ["std", "serde"] }
serde = { version = "1.0", default-features = false, features = [ "derive" ] }
serde_derive = "1.0"
serde_json = "1.0.91"
Expand Down
1 change: 1 addition & 0 deletions common/src/api/external/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ pub enum ResourceType {
MetricProducer,
RoleBuiltin,
UpdateAvailableArtifact,
SystemUpdate,
UserBuiltin,
Zpool,
}
Expand Down
14 changes: 14 additions & 0 deletions common/src/sql/dbinit.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1419,6 +1419,20 @@ CREATE INDEX ON omicron.public.update_available_artifact (
targets_role_version
);

/*
* System updates
*/
CREATE TABLE omicron.public.system_update (
/* Unique identifier for this update package */
id UUID PRIMARY KEY,
time_created TIMESTAMPTZ NOT NULL,
time_modified TIMESTAMPTZ NOT NULL

/* Unique semver version */
/* TODO: If the version is really supposed to be unique, we could make it the PK? */
version STRING(40) NOT NULL,

This comment was marked as resolved.

);

/*******************************************************************/

/*
Expand Down
1 change: 1 addition & 0 deletions nexus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ reqwest = { workspace = true, features = [ "json" ] }
ring.workspace = true
samael.workspace = true
schemars = { workspace = true, features = ["chrono", "uuid1"] }
semver.workspace = true
serde.workspace = true
serde_json.workspace = true
serde_urlencoded.workspace = true
Expand Down
2 changes: 2 additions & 0 deletions nexus/db-model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ mod organization;
mod oximeter_info;
mod producer_endpoint;
mod project;
mod system_update;
// These actually represent subqueries, not real table.
// However, they must be defined in the same crate as our tables
// for join-based marker trait generation.
Expand Down Expand Up @@ -124,6 +125,7 @@ pub use silo_user_password_hash::*;
pub use sled::*;
pub use snapshot::*;
pub use ssh_key::*;
pub use system_update::*;
pub use update_artifact::*;
pub use user_builtin::*;
pub use vni::*;
Expand Down
4 changes: 2 additions & 2 deletions nexus/db-model/src/rack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use crate::schema::rack;
use db_macros::Asset;
use nexus_types::external_api::views;
use nexus_types::{external_api::views, identity::Asset};
use uuid::Uuid;

/// Information about a local rack.
Expand All @@ -30,6 +30,6 @@ impl Rack {

impl From<Rack> for views::Rack {
fn from(rack: Rack) -> Self {
Self { identity: views::AssetIdentityMetadata::from(&rack) }
Self { identity: rack.identity() }
}
}
12 changes: 12 additions & 0 deletions nexus/db-model/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,18 @@ table! {
}
}

table! {
system_update (id) {
id -> Uuid,
name -> Text,
description -> Text,
time_created -> Timestamptz,
time_modified -> Timestamptz,

version -> Text,
}
}

allow_tables_to_appear_in_same_query!(ip_pool_range, ip_pool);
joinable!(ip_pool_range -> ip_pool (ip_pool_id));

Expand Down
7 changes: 2 additions & 5 deletions nexus/db-model/src/sled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::ipv6;
use crate::schema::{service, sled, zpool};
use chrono::{DateTime, Utc};
use db_macros::Asset;
use nexus_types::external_api::views;
use nexus_types::{external_api::views, identity::Asset};
use std::net::Ipv6Addr;
use std::net::SocketAddrV6;
use uuid::Uuid;
Expand Down Expand Up @@ -77,10 +77,7 @@ impl Sled {

impl From<Sled> for views::Sled {
fn from(sled: Sled) -> Self {
Self {
identity: views::AssetIdentityMetadata::from(&sled),
service_address: sled.address(),
}
Self { identity: sled.identity(), service_address: sled.address() }
}
}

Expand Down
32 changes: 32 additions & 0 deletions nexus/db-model/src/system_update.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use crate::schema::system_update;
use db_macros::Asset;
use nexus_types::{external_api::views, identity::Asset};
use serde::{Deserialize, Serialize};

#[derive(
Queryable,
Insertable,
Selectable,
Clone,
Debug,
Asset,
Serialize,
Deserialize,
)]
#[diesel(table_name = system_update)]
pub struct SystemUpdate {
#[diesel(embed)]
identity: SystemUpdateIdentity,
pub version: String,
}

impl From<SystemUpdate> for views::SystemUpdate {
fn from(system_update: SystemUpdate) -> Self {
Self {
identity: system_update.identity(),
// TODO: figure out how to ser/de semver versions
// version: system_update.version,
version: views::SemverVersion::new(1, 0, 0),
}
}
}
20 changes: 17 additions & 3 deletions nexus/src/app/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@

use crate::authz;
use crate::context::OpContext;
use crate::db;
use crate::db::identity::Asset;
use crate::db::lookup::LookupPath;
use crate::db::model::UpdateArtifactKind;
use hex;
use omicron_common::api::external::DataPageParams;
use omicron_common::api::external::Error;
use omicron_common::api::external::PaginationOrder;
use omicron_common::api::external::{
DataPageParams, Error, LookupResult, PaginationOrder,
};
use omicron_common::api::internal::nexus::UpdateArtifact;
use rand::Rng;
use ring::digest;
use std::convert::TryFrom;
use std::num::NonZeroU32;
use std::path::Path;
use tokio::io::AsyncWriteExt;
use uuid::Uuid;

static BASE_ARTIFACT_DIR: &str = "/var/tmp/oxide_artifacts";

Expand Down Expand Up @@ -276,4 +278,16 @@ impl super::Nexus {
})?;
Ok(body)
}

pub async fn system_update_fetch_by_id(
&self,
opctx: &OpContext,
update_id: &Uuid,
) -> LookupResult<db::model::SystemUpdate> {
let (.., db_system_update) = LookupPath::new(opctx, &self.db_datastore)
.system_update_id(*update_id)
.fetch()
.await?;
Ok(db_system_update)
}
}
8 changes: 8 additions & 0 deletions nexus/src/authz/api_resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,14 @@ authz_resource! {
polar_snippet = FleetChild,
}

authz_resource! {
name = "SystemUpdate",
parent = "Fleet",
primary_key = Uuid,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

just noticed this is wrong if version is the pk

roles_allowed = false,
polar_snippet = FleetChild,
}

authz_resource! {
name = "GlobalImage",
parent = "Fleet",
Expand Down
14 changes: 14 additions & 0 deletions nexus/src/db/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@ impl<'a> LookupPath<'a> {
)
}

/// Select a resource of type SystemUpdate, identified by its id
pub fn system_update_id(self, id: Uuid) -> SystemUpdate<'a> {
SystemUpdate::PrimaryKey(Root { lookup_root: self }, id)
}

/// Select a resource of type UserBuiltin, identified by its `name`
pub fn user_builtin_name<'b, 'c>(self, name: &'b Name) -> UserBuiltin<'c>
where
Expand Down Expand Up @@ -686,6 +691,15 @@ lookup_resource! {
]
}

lookup_resource! {
name = "SystemUpdate",
ancestors = [],
children = [],
lookup_by_name = false,
soft_deletes = false,
primary_key_columns = [ { column_name = "id", rust_type = Uuid } ]
}

lookup_resource! {
name = "UserBuiltin",
ancestors = [],
Expand Down
Loading