Skip to content

Commit

Permalink
Re-use bundles at startup for podman runtime (#386)
Browse files Browse the repository at this point in the history
* Add 1st part of reusing bundles for podman runtime

Issue-Id: #260

* Fix existing unit tests for bundle reuse

Issue-Id: #260

* Add unit tests for starting container

Issue-Id: #260

* Add unit tests

Issue-Id: #260

* Fix stests

Issue-Id: #260

* Update requirements for bundle reuse

Issue-Id: #260

* Update stests and requirements

Issue-Id: #260

* Adapt comment

Issue-Id: #260

* Fix review findings

Issue-Id: #260
  • Loading branch information
windsource authored Oct 29, 2024
1 parent 6435a87 commit 6dc056c
Show file tree
Hide file tree
Showing 25 changed files with 830 additions and 270 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
- name: Run unit tests
run: RUST_LOG=debug cargo nextest run
- name: Run clippy code checks
run: cargo clippy --all-targets --no-deps --all-features -- -D warnings
run: just clippy
- name: Prevent docker.io images in test
run: just check-test-images
- name: Check copyright headers
Expand Down Expand Up @@ -89,7 +89,7 @@ jobs:
- name: Create code coverage html report
run: |
rustup component add llvm-tools-preview
tools/generate_test_coverage_report.sh test --html
just coverage
- uses: actions/upload-artifact@v4.3.3
with:
name: code-coverage
Expand Down Expand Up @@ -163,8 +163,7 @@ jobs:
steps:
- uses: actions/checkout@v4.1.1
- run: |
mkdir -p dist
oft trace $(find . -type d -name "src" -o -name "doc") -a swdd,utest,itest,stest,impl -o html -f dist/req_tracing_report.html || true
just trace-requirements dist/req_tracing_report.html
- uses: actions/upload-artifact@v4.3.3
with:
name: requirement-tracing-report
Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"kind": "bin"
}
},
"args": [],
"args": ["--name", "agent_A"],
"cwd": "${workspaceFolder}"
},
{
Expand Down
54 changes: 46 additions & 8 deletions agent/doc/swdesign/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -750,11 +750,11 @@ Needs:
- utest

##### RuntimeManager handles existing workloads replace updated Workloads
`swdd~agent-existing-workloads-replace-updated~2`
`swdd~agent-existing-workloads-replace-updated~3`

Status: approved

When the agent handles existing workloads, for each found existing workload which is requested to be started and either the workload's configuration has changed or the workload is not running, the RuntimeManager shall do the following:
When the agent handles existing workloads, for each found existing workload which is requested to be started and either the workload's configuration has changed or the workload is not in state running or succeeded, the RuntimeManager shall do the following:

- request the RuntimeFacade to delete the existing workload
- request the RuntimeFacade to create the workload
Expand All @@ -771,6 +771,23 @@ Needs:
- utest
- stest

##### RuntimeManager handles existing workloads and reuses unmodified Workloads
`swdd~agent-existing-workloads-reuse-unmodified~1`

Status: approved

When the agent handles existing workloads, for each found existing workload which is requested to be started and the workload's configuration has not changed and the workload is in state succeeded, the RuntimeManager shall request the RuntimeFacade to reuse the existing workload.

Rationale: Starting an existing, succeeded workload is much faster than deleting and creating a workload. If an existing workload is in the failed state, it is not reused because its file system might be corrupted.

Tags:
- RuntimeManager

Needs:
- impl
- utest
- stest

##### RuntimeManager handles existing workloads deletes unneeded workloads
`swdd~agent-existing-workloads-delete-unneeded~1`

Expand Down Expand Up @@ -1837,11 +1854,11 @@ Needs:
- utest

##### Podman create workload runs the workload object
`swdd~podman-create-workload-runs-workload~1`
`swdd~podman-create-workload-runs-workload~2`

Status: approved

When the podman runtime connector is called to create workload, the podman runtime connector shall:
When the podman runtime connector is called to create a workload and no existing workload id is provided, the podman runtime connector shall:

* pull the workload image specified in the runtime configuration if the image is not already available locally
* create the container
Expand All @@ -1856,6 +1873,27 @@ Needs:
- utest
- stest

##### Podman create workload starts an existing the workload object
`swdd~podman-create-workload-starts-existing-workload~1`

Status: approved

When the podman runtime connector is called to create a workload and an existing workload id is provided, the podman runtime connector shall:

* start the existing container
* start a `GenericPollingStateChecker` to check the workload state

Rationale:
Starting a stopped container is much faster than creating a new container bundle and starting that. Short startup times are ususally crucial for automotive.

Tags:
- PodmanRuntimeConnector

Needs:
- impl
- utest
- stest

##### Podman create workload returns workload id
`swdd~podman-create-workload-returns-workload-id~1`

Expand Down Expand Up @@ -1891,11 +1929,11 @@ Needs:
- utest

##### Podman create workload creates labels
`swdd~podman-create-workload-creates-labels~1`
`swdd~podman-create-workload-creates-labels~2`

Status: approved

When the podman runtime connector is called to create workload, the podman runtime connector shall create following labels in the workload:
When the podman runtime connector is called without an existing workload id to create a new workload, the podman runtime connector shall create following labels in the workload:

* `name` as the key and workload execution name as the value
* `agent` as the key and the agent name where the workload is being created as the value
Expand All @@ -1908,11 +1946,11 @@ Needs:
- utest

##### Podman create workload sets optionally container name
`swdd~podman-create-workload-sets-optionally-container-name~1`
`swdd~podman-create-workload-sets-optionally-container-name~2`

Status: approved

When the podman runtime connector is called to create workload and the workload name is not set in the runtime configuration,
When the podman runtime connector is called is called without an existing workload id to create a new workload and the workload name is not set in the runtime configuration,
the podman runtime connector shall set the workload execution name as the workload name.

Tags:
Expand Down
4 changes: 2 additions & 2 deletions agent/src/generic_polling_state_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// SPDX-License-Identifier: Apache-2.0

use async_trait::async_trait;
use std::time::Duration;
use std::{str::FromStr, time::Duration};
use tokio::{task::JoinHandle, time};

use crate::{
Expand All @@ -34,7 +34,7 @@ pub struct GenericPollingStateChecker {
#[async_trait]
impl<WorkloadId> StateChecker<WorkloadId> for GenericPollingStateChecker
where
WorkloadId: ToString + Send + Sync + 'static,
WorkloadId: ToString + FromStr + Clone + Send + Sync + 'static,
{
// [impl->swdd~agent-provides-generic-state-checker-implementation~1]
fn start_checker(
Expand Down
4 changes: 3 additions & 1 deletion agent/src/runtime_connectors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ pub(crate) mod podman;
pub(crate) mod podman_kube;

mod runtime_connector;
pub use runtime_connector::{OwnableRuntime, RuntimeConnector, RuntimeError};
pub use runtime_connector::{
OwnableRuntime, ReusableWorkloadState, RuntimeConnector, RuntimeError,
};

#[cfg(test)]
pub use runtime_connector::test;
Expand Down
Loading

0 comments on commit 6dc056c

Please sign in to comment.