Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
target/
**/target/
14 changes: 11 additions & 3 deletions crates/wash-runtime/src/engine/workload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{

use anyhow::{Context as _, bail, ensure};
use tokio::{sync::RwLock, task::JoinHandle, time::timeout};
use tracing::{debug, info, trace, warn};
use tracing::{debug, error, info, trace, warn};
use wasmtime::component::{
Component, Instance, InstancePre, Linker, ResourceAny, ResourceType, Val, types::ComponentItem,
};
Expand Down Expand Up @@ -713,7 +713,16 @@ impl ResolvedWorkload {

let func = instance
.get_func(&mut store, func_idx)
.context("function not found")?;
.context("function not found");

let func = match func {
Ok(func) => func,
Err(e) => {
error!("Error in gettin func: {:?}", e);
return Err(e);
}
};

trace!(
name = %import_name,
fn_name = %export_name,
Expand Down Expand Up @@ -821,7 +830,6 @@ impl ResolvedWorkload {
);
continue;
}

trace!(name = import_name, resource = export_name, ty = ?resource_ty, "linking resource import");

linker_instance
Expand Down
4 changes: 4 additions & 0 deletions crates/wash-runtime/src/host/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,10 @@ impl HostApi for Host {
"Workload stopped successfully".to_string(),
)
} else {
warn!(
"Tried to stop non existing workload: {}",
request.workload_id
);
(WorkloadState::Unspecified, "Workload not found".to_string())
};

Expand Down
14 changes: 12 additions & 2 deletions crates/wash-runtime/src/washlet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ async fn workload_start(
config: &HostConfig,
) -> anyhow::Result<types::v2::WorkloadStartResponse> {
let Some(types::v2::Workload {
workload_id,
namespace,
name,
annotations,
Expand Down Expand Up @@ -370,7 +371,7 @@ async fn workload_start(
let volumes = volumes.into_iter().map(Into::into).collect();

let request = crate::types::WorkloadStartRequest {
workload_id: uuid::Uuid::new_v4().to_string(),
workload_id: workload_id,
workload: crate::types::Workload {
namespace,
name,
Expand All @@ -388,7 +389,16 @@ async fn workload_start(
name=?request.workload.name,
"Starting workload");

Ok(host.workload_start(request).await?.into())
match host.workload_start(request).await {
Ok(resp) => Ok(resp.into()),
Err(e) => Ok(types::v2::WorkloadStartResponse {
workload_status: Some(types::v2::WorkloadStatus {
workload_id: "".into(),
workload_state: types::v2::WorkloadState::Error.into(),
message: format!("failed to start workload: {}", e),
}),
}),
}
}

async fn workload_stop(
Expand Down
7 changes: 7 additions & 0 deletions proto/docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,13 @@ <h3 id="wasmcloud.runtime.v2.Workload">Workload</h3>
<td><p> </p></td>
</tr>

<tr>
<td>workload_id</td>
<td><a href="#string">string</a></td>
<td></td>
<td><p> </p></td>
</tr>

</tbody>
</table>

Expand Down
2 changes: 2 additions & 0 deletions proto/wasmcloud/runtime/v2/workload.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ message Workload {
WitWorld wit_world = 5;

repeated Volume volumes = 6;

string workload_id = 7;
}

enum WorkloadState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ func (r *WorkloadReconciler) reconcilePlacement(ctx context.Context, workload *r

req := &runtimev2.WorkloadStartRequest{
Workload: &runtimev2.Workload{
WorkloadId: string(workload.UID),
Namespace: workload.Namespace,
Name: workload.Name,
Annotations: workload.GetAnnotations(),
Expand All @@ -275,13 +276,13 @@ func (r *WorkloadReconciler) reconcilePlacement(ctx context.Context, workload *r
ctx, cancel := context.WithTimeout(ctx, workloadStartTimeout)
defer cancel()

resp, err := client.Start(ctx, req)
_, err := client.Start(ctx, req)
if err != nil {
return err
}

// Set the WorkloadID in the status
workload.Status.WorkloadID = resp.WorkloadStatus.WorkloadId
workload.Status.WorkloadID = string(workload.UID)
condition.ForceStatusUpdate(ctx)
return condition.ErrSkipReconciliation()
}
Expand Down Expand Up @@ -320,14 +321,9 @@ func (r *WorkloadReconciler) reconcileReady(_ context.Context, workload *runtime
}

func (r *WorkloadReconciler) finalize(ctx context.Context, workload *runtimev1alpha1.Workload) error {
if !workload.Status.AllTrue(runtimev1alpha1.WorkloadConditionPlacement) {
// nothing to do, the workload was never placed
return nil
}

client := NewWashHostClient(r.Bus, workload.Status.HostID)
req := &runtimev2.WorkloadStopRequest{
WorkloadId: workload.Status.WorkloadID,
WorkloadId: string(workload.UID),
}

ctx, cancel := context.WithTimeout(ctx, workloadStopTimeout)
Expand Down
Loading
Loading