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

wasm, kubernetes: support wasm for kubernetes infrastructure with side-cars with wasm-smart and compat-smart annotation #886

Merged
merged 2 commits into from
Mar 7, 2022

Conversation

flouthoc
Copy link
Collaborator

@flouthoc flouthoc commented Mar 7, 2022

Complex kubernetes infrastructure contains pod and most likely pod with
side-cars. Therefore wasm integration is not useful for cases where
side-cars are almost there in most of the deployments example
infrastrcuture setups with service-mesh like linkerd, gloo and istio
and proxy like envoy.

Following use-case is solved by adding two smart annotations for only
wasm-handlers i.e compat-smart and wasm-smart

compat-smart, wasm-smart: annotation is a smart switch which only toggles wasm
runtime if its necessary otherwise fallbacks to native container runtime
hence in deployments with side-cars only containers which contains
valid wasm workload will be treated be executed by wasm-handlers and
regular containers are treated as it is.

Simple tryout example with module.wasm.image/variant: compat-smart

apiVersion: v1
kind: Pod
metadata:
  name: wasm-hello
  annotations:
    module.wasm.image/variant: compat-smart
spec:
  containers:
  - image: busybox
    name: busybox
    command:
      - sleep
      - "3600"
    imagePullPolicy: IfNotPresent
  - name: wasm-hello
    image: your-wasm-image:latest
    imagePullPolicy: IfNotPresent
  tolerations:
  - key: "node-role.kubernetes.io/master"
    operator: "Exists"
    effect: "NoSchedule"

Closes: #829

@flouthoc
Copy link
Collaborator Author

flouthoc commented Mar 7, 2022

@giuseppe PTAL. I just need to confirm if wasmedge added support for wat or not other than that this PR should be good for review and makes wasm functional for kubernetes deployments in general i.e with side-cars and init-containers

@flouthoc flouthoc marked this pull request as draft March 7, 2022 07:46
Copy link
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

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

just a typo, otherwise LGTM

src/libcrun/handlers/wasmedge.c Outdated Show resolved Hide resolved
src/libcrun/handlers/wasmedge.c Outdated Show resolved Hide resolved
src/libcrun/handlers/wasmer.c Outdated Show resolved Hide resolved
src/libcrun/handlers/wasmer.c Outdated Show resolved Hide resolved
@flouthoc
Copy link
Collaborator Author

flouthoc commented Mar 7, 2022

Hi @0xE282B0 @gattytto I have tested this various side-car patterns and also added a tryout example. If someone wants to give this a try with k8s with any of the service-mesh like linkerd could you try this out ? otherwise we can get this merged.

@0xE282B0
Copy link
Contributor

0xE282B0 commented Mar 7, 2022

Thanks for working on that @flouthoc!
My Knative and DAPR examples are running fine with module.wasm.image/variant=compat-smart, LGTM.

The only thing I'm a bit concerned about is that a sidecars entrypoint maybe ends on wat. What do you think about checking on .wat? -Since this is a file extension, an entry point should be less likely to end with it.

Copy link
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

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

LGTM

@flouthoc
Copy link
Collaborator Author

flouthoc commented Mar 7, 2022

Thanks for working on that @flouthoc!
My Knative and DAPR examples are running fine with module.wasm.image/variant=compat-smart, LGTM.

Thanks for trying this out and confirming.

The only thing I'm a bit concerned about is that a sidecars entrypoint maybe ends on wat. What do you think about checking on .wat? -Since this is a file extension, an entry point should be less likely to end with it.

@0xE282B0 I did not understand this question completely. I have added .wat cause wasmer supports it and I can remove it from wasmedge if its a problem. But wasmer can compile .wat and can execute it on the fly and that is my intention behind adding a .wat and hopefully .wasmedge will also support it in future.

@0xE282B0
Copy link
Contributor

0xE282B0 commented Mar 7, 2022

Sorry for being imprecise. For me it looks like has_suffix just checks if the entrypoint ends on wat|wasm and I'd suggest to check on .wat|.wasm (just a dot added) just for the unlikely case that a sidecars entrypoint accidentally ends on one of the strings.
I'm totally fine with supporting wat files 😊

@flouthoc
Copy link
Collaborator Author

flouthoc commented Mar 7, 2022

Sorry for being imprecise. For me it looks like has_suffix just checks if the entrypoint ends on wat|wasm and I'd suggest to check on .wat|.wasm (just a dot added) just for the unlikely case that a sidecars entrypoint accidentally ends on one of the strings. I'm totally fine with supporting wat files blush

Oh fair request. Let me amend the the commit.

@flouthoc flouthoc marked this pull request as ready for review March 7, 2022 11:47
@flouthoc flouthoc requested a review from giuseppe March 7, 2022 12:16
@flouthoc
Copy link
Collaborator Author

flouthoc commented Mar 7, 2022

@rhatdan @giuseppe Pushed refactor to a new commit could you PTAL.

…e-cars

Complex kubernetes infrastructure contains pod and most likely pod with
side-cars. Therefore `wasm` integration is not useful for cases where
side-cars are almost there in most of the deployments example
infrastrcuture setups with `service-mesh` like `linkerd` and `istio`.

Following use-case is solved by adding two smart annotations for only
wasm-handlers i.e `compat-smart` and `wasm-smart`

compat-smart, wasm-smart: annotation is a smart switch which only toggles wasm
runtime if its necessary otherwise fallbacks to native container runtime
hence in deployments with `side-cars` only containers which contains
valid `wasm` workload will be treated be executed by `wasm-handlers` and
regular containers are treated as it is.

Simple tryout example with `module.wasm.image/variant: compat-smart`

```yaml
apiVersion: v1
kind: Pod
metadata:
  name: wasm-hello
  annotations:
    module.wasm.image/variant: compat-smart
spec:
  containers:
  - image: busybox
    name: busybox
    command:
      - sleep
      - "3600"
    imagePullPolicy: IfNotPresent
  - name: wasm-hello
    image: your-wasm-image:latest
    imagePullPolicy: IfNotPresent
  tolerations:
  - key: "node-role.kubernetes.io/master"
    operator: "Exists"
    effect: "NoSchedule"
```

* Commit also refactor's handler code into a shared handler-utils.c

Signed-off-by: Aditya R <arajan@redhat.com>
Update man page to document `compat-smart`, `wasm-smart` and rectify
known issues.

Signed-off-by: Aditya R <arajan@redhat.com>
/*
* crun - OCI runtime written in C
*
* Copyright (C) 2017, 2018, 2019 Giuseppe Scrivano <giuseppe@scrivano.org>
Copy link
Member

Choose a reason for hiding this comment

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

@giuseppe Might want to extend your copyright...

@rhatdan
Copy link
Member

rhatdan commented Mar 7, 2022

LGTM

Copy link
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

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

LGTM

@giuseppe giuseppe merged commit 3b3061a into containers:main Mar 7, 2022
@flouthoc
Copy link
Collaborator Author

flouthoc commented Mar 9, 2022

Hi @juntao @hydai, I think it would be nice if wasmedge docs could also point to these new annotations since they might be useful for dapr and other k8s infra.

Newly added annotations are

  • module.wasm.image/variant: compat-smart
  • run.oci.handler: wasm-smart

@0xE282B0
Copy link
Contributor

0xE282B0 commented Mar 9, 2022

@flouthoc I can open an issue in the wasmedge repo to add the annotations to the docs.

@flouthoc
Copy link
Collaborator Author

flouthoc commented Mar 9, 2022

@0xE282B0 Thanks.

@rhatdan
Copy link
Member

rhatdan commented Mar 9, 2022

We really need to have a nice blog/article/demo showing us using crun/wasm to run containers.

Would it make sense to have entrypoint oci-runtimes named wasm-smart and compat-smart and just specify the oci runtime rather then setting annotations?

@flouthoc
Copy link
Collaborator Author

flouthoc commented Mar 9, 2022

@rhatdan I think the convention was initially set by solo.io and it gives freedom to always not opt for wasm and use crun as regular runtime but yes I agree we need more comprehensive examples and write-up on this. I'll pick it up.

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.

Sidecars for WebAssembly Pods
4 participants