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

fix: use correct wasm shims names #9519

Merged
merged 2 commits into from
Mar 5, 2024
Merged

Conversation

flavio
Copy link
Contributor

@flavio flavio commented Feb 16, 2024

Proposed Changes

Change how containerd configuration is generated with regards to WebAssembly shims.

Types of Changes

Use correct binary names and the associated RuntimeType. Prior to this, there was quite a mixup between v1 and v2 shims.

Verification

  • Download spin and the slight shims from here
  • Unpack the tarball and move the files to /usr/bin/containerd-shim-spin-v2 and /usr/bin/containerd-shim-slight-v1
  • Install/restart the patched version of k3s

Check the contents of /var/lib/rancher/k3s/agent/etc/containerd/config.toml, it should have the following lines:

[plugins."io.containerd.grpc.v1.cri".containerd.runtimes."slight"]
  runtime_type = "io.containerd.slight.v1"
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes."slight".options]
  BinaryName = "/usr/bin/containerd-shim-slight-v1"
  SystemdCgroup = true

[plugins."io.containerd.grpc.v1.cri".containerd.runtimes."spin"]
  runtime_type = "io.containerd.spin.v2"
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes."spin".options]
  BinaryName = "/usr/bin/containerd-shim-spin-v2"
  SystemdCgroup = true

Then, to test the slight-shim is actually working, create the following Deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: wasm-slight
spec:
  replicas: 1
  selector:
    matchLabels:
      app: wasm-slight
  template:
    metadata:
      labels:
        app: wasm-slight
    spec:
      runtimeClassName: slight
      containers:
        - name: slight-hello
          image: ghcr.io/deislabs/containerd-wasm-shims/examples/slight-rust-hello:v0.9.1
          command: ["/"]
          resources: # limit the resources to 128Mi of memory and 100m of CPU
            limits:
              cpu: 100m
              memory: 128Mi
            requests:
              cpu: 100m
              memory: 128Mi

Then, to test the spin-shim is actually working, create the following Deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: wasm-spin
spec:
  replicas: 1
  selector:
    matchLabels:
      app: wasm-spin
  template:
    metadata:
      labels:
        app: wasm-spin
    spec:
      runtimeClassName: spin
      containers:
        - name: spin-hello
          image: ghcr.io/deislabs/containerd-wasm-shims/examples/spin-rust-hello:v0.11.1
          command: ["/"]
          resources: # limit the resources to 128Mi of memory and 100m of CPU
            limits:
              cpu: 100m
              memory: 128Mi
            requests:
              cpu: 100m
              memory: 128Mi

You should now have 2 Pod running.

Both Pods are small web application. To access them we have to create the following resources:

# create a traefik middleware
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: strip-prefix
  namespace: default
spec:
  stripPrefix:
    forceSlash: false
    prefixes:
      - /spin
      - /slight
---
# define slight service
apiVersion: v1
kind: Service
metadata:
  name: wasm-slight
spec:
  ports:
    - protocol: TCP
      port: 80
      targetPort: 3000
  selector:
    app: wasm-slight
---
# define spin service
apiVersion: v1
kind: Service
metadata:
  name: wasm-spin
spec:
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
  selector:
    app: wasm-spin
---
# define a single ingress, that exposes both services
# using a path route
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: wasm-ingress
  annotations:
    ingress.kubernetes.io/ssl-redirect: "false"
    kubernetes.io/ingress.class: traefik
    traefik.ingress.kubernetes.io/router.middlewares: default-strip-prefix@kubernetescrd
spec:
  rules:
    - http:
        paths:
          - path: /slight
            pathType: Prefix
            backend:
              service:
                name: wasm-slight
                port:
                  number: 80
          - path: /spin
            pathType: Prefix
            backend:
              service:
                name: wasm-spin
                port:
                  number: 80

Then run the following commands:

# optain the public IP of the ingress
export PUBLIC_IP=$(kubectl get ingress wasm-ingress -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
# verify the slight application
curl -v http://$PUBLIC_IP/slight/hello
# verify the spin application
curl -v http://$PUBLIC_IP/spin/go-hello
curl -v http://$PUBLIC_IP/spin/hello

Testing

This was already covered by the unit tests, however that didn't help with the detection of the issue.

Does k3s have the concept of integration tests? The idea would be to automate the verification steps. I would be happy to write this integration test.

Linked Issues

User-Facing Change

Further Comments

CC @brandond and @vitorsavian who initially reviewed #8751

Fix the wasm shim detection and the containerd configuration generation.

Prior to this commit, the binary and the `RuntimeType` values were not
correct.

Signed-off-by: Flavio Castelli <fcastelli@suse.com>
@flavio flavio requested a review from a team as a code owner February 16, 2024 16:17
@brandond
Copy link
Member

Does k3s have the concept of integration tests? The idea would be to automate the verification steps. I would be happy to write this integration test.

You might take a look at https://github.com/k3s-io/k3s/tree/master/tests/integration and https://github.com/k3s-io/k3s/tree/master/tests/e2e and see where you think this might fit best.

brandond
brandond previously approved these changes Feb 16, 2024
Copy link

codecov bot commented Feb 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 42.92%. Comparing base (085ccbb) to head (33e541c).
Report is 5 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9519      +/-   ##
==========================================
- Coverage   49.12%   42.92%   -6.20%     
==========================================
  Files         151      154       +3     
  Lines       13475    13523      +48     
==========================================
- Hits         6619     5805     -814     
- Misses       5515     6550    +1035     
+ Partials     1341     1168     -173     
Flag Coverage Δ
e2etests ?
inttests 39.49% <100.00%> (+<0.01%) ⬆️
unittests 15.96% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dereknola
Copy link
Member

Since this can be validated on a single server node, this should be written as an integration test.

dereknola
dereknola previously approved these changes Feb 16, 2024
@flavio
Copy link
Contributor Author

flavio commented Feb 16, 2024

Since this can be validated on a single server node, this should be written as an integration test.

The test needs to download some binaries from the internet and put them on specific locations on the filesystem. From what I've seen, the integration tests are not doing that (see for example the longhorn one, which bails out if iscsiadm is not installed).

The e2e tests, on the other hand, seem to allow this kind of operations.

Because of that, I was more inclined towards writing a e2e tests.

Thoughts?

@dereknola
Copy link
Member

Hmm, thats fair, we don't want to add binaries to a host without them knowing, so E2E it is.

@flavio flavio dismissed stale reviews from dereknola and brandond via f920b03 February 20, 2024 09:06
@flavio
Copy link
Contributor Author

flavio commented Feb 20, 2024

@brandond , @dereknola: I've added a new e2e test. I've taken inspiration from other tests that are already inside of the code base. Let me know if there's anything I have to change to make it more idiomatic

tests/e2e/wasm/wasm_test.go Outdated Show resolved Hide resolved
Copy link
Member

@dereknola dereknola left a comment

Choose a reason for hiding this comment

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

You accidentally butchered the LICENSE and README files. Can you revert those changes?

Add a e2e test that runs some demo WebAssembly applications
using the dedicated containerd shims.

Note: this is not an integration test because we need to install some
binaries (the special containerd shims) on the host.

Signed-off-by: Flavio Castelli <fcastelli@suse.com>
@flavio
Copy link
Contributor Author

flavio commented Feb 22, 2024

@dereknola doh! sorry about that...

I've fixed the issue with a force push

@flavio
Copy link
Contributor Author

flavio commented Feb 23, 2024

It seems the amount of e2e tests ran by drone is limited (see here).

Is that done by purpose?

Should I add my new e2e test over there?

@Mossaka
Copy link

Mossaka commented Mar 13, 2024

I am assuming that this change was not in v1.28.7+k3s1, right?

@flavio
Copy link
Contributor Author

flavio commented Mar 14, 2024

@Mossaka no, they are not part of a tagged release of k3s. They will be part of the next release

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