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

Support trigger command #50

Merged
merged 1 commit into from
Apr 5, 2024

Conversation

radu-matei
Copy link
Member

This commit allows Spin apps to be init containers, based on https://github.com/fermyon/spin-trigger-command:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: spin-test-init
spec:
  replicas: 1
  selector:
    matchLabels:
      app: spin-test
  template:
    metadata:
      labels:
        app: spin-test
    spec:
      runtimeClassName: wasmtime-spin-v2
      initContainers:
      - name: spin-init
        image: ttl.sh/spinkube-init:24h
        command: ["/"]
      containers:
      - name: spin-test
        image: ghcr.io/deislabs/containerd-wasm-shims/examples/spin-rust-hello:v0.10.0
        command: ["/"]
        ports:
        - containerPort: 80

@devigned
Copy link
Contributor

@radu-matei I think I get mechanically how this works, but I'm not quite clear on the use case for init container having a command trigger. Can you explain what it would be used for?

@radu-matei
Copy link
Member Author

radu-matei commented Mar 26, 2024

I should have added a bit more context to this — we've had a lot of conversations during KubeCon with people who are interested in using Wasm as init containers — where their init containers take dozens of seconds to start, even if all they do is a tiny bit of work.

So they are interested in seeing how to use Wasm because of its tiny footprint and fast startup.

At the same time, we've also long been interested in a Spin trigger that ran a WASI (CLI) component to completion (regardless of what it does exactly).

So this brings the two together and a) lets you execute a "main" function to completion through Spin, and b) enables using that as an init container.

Turning this into a draft for now, as we want to discuss this in the next SpinKube meeting.

@radu-matei radu-matei marked this pull request as draft March 26, 2024 14:14
.context("failed to build spin trigger")?;

info!(" >>> running spin trigger");
command_trigger.run(spin_trigger::cli::NoArgs)
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you want to pass in the args from the entrypoint of the container spec?

@jsturtevant
Copy link
Contributor

So this brings the two together and a) lets you execute a "main" function to completion through Spin, and b) enables using that as an init container.

There isn't anything in here that makes it specifically for init containers, this could be used to run the main pod to completion as well? Thinking something like a kubernetes Job.

@jsturtevant
Copy link
Contributor

LGTM, We might add a workload test for the init container scenario: https://github.com/spinkube/containerd-shim-spin/tree/main/tests/workloads

@radu-matei
Copy link
Member Author

@jsturtevant correct, this can definitely be used for other kinds of workloads, not just init containers.

@Mossaka
Copy link
Member

Mossaka commented Mar 28, 2024

Is the spin command trigger implementing the wasip2 wasi-cli world? That is, does it have the sockets APIs?

@radu-matei
Copy link
Member Author

@Mossaka yeah, the trigger now supports both WASI Preview 1 and WASI Preview 2 components (using the CLI world). Tested with a Rust component that uses sockets, so that definitely works (will push an example on this over the next few days).

On passing arguments, we have a proposal for that here:

fermyon/spin-trigger-command#4 (comment)

Copy link
Member

@Mossaka Mossaka left a comment

Choose a reason for hiding this comment

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

LGTM

@radu-matei radu-matei force-pushed the feat/trigger-command branch from a55e5d2 to 98b7d1e Compare April 5, 2024 00:26
@radu-matei
Copy link
Member Author

This app manifest works in the shim using the command trigger:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: spin-test-init
spec:
  replicas: 1
  selector:
    matchLabels:
      app: spin-test
  template:
    metadata:
      labels:
        app: spin-test
    spec:
      runtimeClassName: wasmtime-spin-v2
      initContainers:
      - name: spin-init
        image: ttl.sh/spinkube-init-args:24h
        args: ["these", "are", "some", "args"]
      containers:
      - name: spin-test
        image: ghcr.io/deislabs/containerd-wasm-shims/examples/spin-rust-hello:v0.10.0
        command: ["/"]
        ports:
        - containerPort: 80

Getting the logs from the init container:

$ kubectl logs pods/spin-test-init-5f4d994596-q8wfh -c spin-init
hiwasi
these
are
some
args

@radu-matei radu-matei marked this pull request as ready for review April 5, 2024 08:45
This commit implements support for running "command" triggers in the
shim, based on https://github.com/fermyon/spin-trigger-command.

Specifically, it runs a WASI command component to completion, with
support for both classical WASI preview 1 core modules and WASI preview
2 CLI components.

Finally, this supports passing Kubernetes arguments:

```yaml
      - name: spin-command
        image: <command-component-that-prints-args>
        args: ["these", "are", "some", "args"]
```

These arguments are passed in the component and can be read at runtime
using WASI.

Signed-off-by: Radu Matei <radu@fermyon.com>
@radu-matei radu-matei force-pushed the feat/trigger-command branch from 7c14e3a to 36b2365 Compare April 5, 2024 09:00
@radu-matei
Copy link
Member Author

I'll merge this so we can iterate. Thank you all for the feedback!

@radu-matei radu-matei merged commit 75dc359 into spinkube:main Apr 5, 2024
9 checks passed
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.

4 participants