Skip to content

Commit

Permalink
Merge branch 'nightly' into release/nightly/bin/nanocl/0.16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
leon3s authored Oct 21, 2024
2 parents 68dd8c4 + 196e3e2 commit 747e34a
Show file tree
Hide file tree
Showing 31 changed files with 396 additions and 257 deletions.
134 changes: 65 additions & 69 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions bin/nanocl/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ impl UserConfig {
Ok(s) => s,
Err(_) => return UserConfig::default(),
};
match serde_yaml::from_str::<UserConfig>(&s) {
Ok(config) => config,
Err(_) => UserConfig::default(),
}
serde_yaml::from_str::<UserConfig>(&s).unwrap_or_default()
}
}

Expand Down
2 changes: 1 addition & 1 deletion bin/nanocld/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ chrono = { version = "0.4", default-features = false, features = [
"clock",
"serde",
] }
jsonschema = { version = "0.22", default-features = false }
jsonschema = { version = "0.23", default-features = false }
nanocld_client = { version = "0.16", features = ["tokio"] }
metrsd_client = "0.5"
nanocl_stubs = { version = "0.16", features = ["serde", "clap"] }
Expand Down
8 changes: 4 additions & 4 deletions bin/nanocld/specs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3259,7 +3259,7 @@ components:
Name:
type: string
IpAddress:
type: string
$ref: '#/components/schemas/NetworkKind'
additionalProperties: false
Driver:
type: object
Expand Down Expand Up @@ -5774,7 +5774,7 @@ components:
nullable: true
minimum: 0
Network:
$ref: '#/components/schemas/ProxyNetwork'
$ref: '#/components/schemas/NetworkKind'
LimitReqZone:
allOf:
- $ref: '#/components/schemas/LimitReqZone'
Expand Down Expand Up @@ -5805,7 +5805,7 @@ components:
- Target
properties:
Network:
$ref: '#/components/schemas/ProxyNetwork'
$ref: '#/components/schemas/NetworkKind'
Protocol:
$ref: '#/components/schemas/ProxyStreamProtocol'
Port:
Expand Down Expand Up @@ -6039,7 +6039,7 @@ components:
- Entries
properties:
Network:
type: string
$ref: '#/components/schemas/NetworkKind'
Entries:
type: array
items:
Expand Down
1 change: 0 additions & 1 deletion bin/nanocld/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ async fn main() -> std::io::Result<()> {
err.print_and_exit();
}
Ok(config) => config,
// gfg
};
// Boot internal dependencies (database, event bus, etc...)
let daemon_state = match system::init(&config).await {
Expand Down
12 changes: 8 additions & 4 deletions bin/nanocld/src/objects/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,12 @@ impl ObjDelByPk for CargoDb {
state: &SystemState,
) -> HttpResult<Self::ObjDelOut> {
let cargo = CargoDb::transform_read_by_pk(pk, &state.inner.pool).await?;
let processes =
ProcessDb::read_by_kind_key(&cargo.spec.cargo_key, &state.inner.pool)
.await?;
let processes = ProcessDb::read_by_kind_key(
&cargo.spec.cargo_key,
None,
&state.inner.pool,
)
.await?;
let (_, _, _, running) =
utils::container::generic::count_status(&processes);
if running > 0 && !opts.force.unwrap_or(false) {
Expand Down Expand Up @@ -272,7 +275,8 @@ impl ObjInspectByPk for CargoDb {
state: &SystemState,
) -> HttpResult<Self::ObjInspectOut> {
let cargo = CargoDb::transform_read_by_pk(pk, &state.inner.pool).await?;
let processes = ProcessDb::read_by_kind_key(pk, &state.inner.pool).await?;
let processes =
ProcessDb::read_by_kind_key(pk, None, &state.inner.pool).await?;
let (_, _, _, running_instances) =
utils::container::generic::count_status(&processes);
let status = ObjPsStatusDb::read_by_pk(pk, &state.inner.pool).await?;
Expand Down
3 changes: 2 additions & 1 deletion bin/nanocld/src/objects/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ impl ObjInspectByPk for JobDb {
state: &crate::models::SystemState,
) -> HttpResult<Self::ObjInspectOut> {
let job = JobDb::transform_read_by_pk(pk, &state.inner.pool).await?;
let instances = ProcessDb::read_by_kind_key(pk, &state.inner.pool).await?;
let instances =
ProcessDb::read_by_kind_key(pk, None, &state.inner.pool).await?;
let (instance_total, instance_failed, instance_success, instance_running) =
utils::container::generic::count_status(&instances);
let job_inspect = JobInspect {
Expand Down
3 changes: 2 additions & 1 deletion bin/nanocld/src/objects/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ impl ObjInspectByPk for VmDb {
) -> HttpResult<Self::ObjInspectOut> {
let vm = VmDb::transform_read_by_pk(pk, &state.inner.pool).await?;
let processes =
ProcessDb::read_by_kind_key(&vm.spec.vm_key, &state.inner.pool).await?;
ProcessDb::read_by_kind_key(&vm.spec.vm_key, None, &state.inner.pool)
.await?;
let (total, _, _, running_instances) =
utils::container::generic::count_status(&processes);
Ok(VmInspect {
Expand Down
21 changes: 17 additions & 4 deletions bin/nanocld/src/repositories/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,17 +238,30 @@ impl CargoDb {
let spec = SpecDb::read_by_pk(&cargo.spec.key, &state.inner.pool)
.await?
.try_to_cargo_spec()?;
let processes =
ProcessDb::read_by_kind_key(&cargo.spec.cargo_key, &state.inner.pool)
.await?;
let filter = GenericFilter::new().r#where(
"data",
GenericClause::Contains(serde_json::json!({
"Config": {
"Labels": {
"io.nanocl.not-init-c": "true"
}
}
})),
);
let processes = ProcessDb::read_by_kind_key(
&cargo.spec.cargo_key,
Some(filter),
&state.inner.pool,
)
.await?;
let (_, _, _, running) =
utils::container::generic::count_status(&processes);
cargo_summaries.push(CargoSummary {
created_at: cargo.created_at,
status: cargo.status,
namespace_name: cargo.namespace_name,
instance_total: processes.len(),
instance_running: running,
instance_total: processes.len(),
spec: spec.clone(),
});
}
Expand Down
3 changes: 2 additions & 1 deletion bin/nanocld/src/repositories/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ impl JobDb {
.iter()
.map(|job| async {
let instances =
ProcessDb::read_by_kind_key(&job.name, &state.inner.pool).await?;
ProcessDb::read_by_kind_key(&job.name, None, &state.inner.pool)
.await?;
let (
instance_total,
instance_failed,
Expand Down
4 changes: 3 additions & 1 deletion bin/nanocld/src/repositories/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,11 @@ impl RepositoryReadByTransform for ProcessDb {
impl ProcessDb {
pub async fn read_by_kind_key(
kind_key: &str,
filter: Option<GenericFilter>,
pool: &Pool,
) -> IoResult<Vec<Process>> {
let filter = GenericFilter::new()
let filter = filter
.unwrap_or_default()
.r#where("kind_key", GenericClause::Eq(kind_key.to_owned()));
ProcessDb::transform_read_by(&filter, pool).await
}
Expand Down
2 changes: 1 addition & 1 deletion bin/nanocld/src/repositories/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl VmDb {
.await?
.try_to_vm_spec()?;
let processes =
ProcessDb::read_by_kind_key(&vm.spec.vm_key, pool).await?;
ProcessDb::read_by_kind_key(&vm.spec.vm_key, None, pool).await?;
let (_, _, _, running_instances) =
utils::container::generic::count_status(&processes);
vm_summaries.push(VmSummary {
Expand Down
6 changes: 3 additions & 3 deletions bin/nanocld/src/services/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async fn logs_processes(
let kind = kind.parse().map_err(HttpError::bad_request)?;
let kind_key = utils::key::gen_kind_key(&kind, &name, &qs.namespace);
let processes =
ProcessDb::read_by_kind_key(&kind_key, &state.inner.pool).await?;
ProcessDb::read_by_kind_key(&kind_key, None, &state.inner.pool).await?;
log::debug!("process::logs_process: {kind_key}");
let options: LogsOptions<String> = qs.into_inner().into();
let futures = processes
Expand Down Expand Up @@ -337,7 +337,7 @@ pub async fn wait_processes(
condition: qs.condition.clone().unwrap_or_default(),
};
let processes =
ProcessDb::read_by_kind_key(&kind_pk, &state.inner.pool).await?;
ProcessDb::read_by_kind_key(&kind_pk, None, &state.inner.pool).await?;
let mut streams = Vec::new();
for process in processes {
let options = Some(opts.clone());
Expand Down Expand Up @@ -410,7 +410,7 @@ pub async fn stats_processes(
let kind_key = utils::key::gen_kind_key(&kind, &name, &qs.namespace);
let opts: StatsOptions = qs.clone().into();
let processes =
ProcessDb::read_by_kind_key(&kind_key, &state.inner.pool).await?;
ProcessDb::read_by_kind_key(&kind_key, None, &state.inner.pool).await?;
let streams =
processes
.into_iter()
Expand Down
2 changes: 1 addition & 1 deletion bin/nanocld/src/system/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async fn job_ttl(actor: &EventActor, state: &SystemState) -> IoResult<()> {
_ => {}
}
let instances =
ProcessDb::read_by_kind_key(&job.name, &state.inner.pool).await?;
ProcessDb::read_by_kind_key(&job.name, None, &state.inner.pool).await?;
let (_, instance_failed, _, running) =
utils::container::generic::count_status(&instances);
log::debug!(
Expand Down
Loading

0 comments on commit 747e34a

Please sign in to comment.