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

containerd-shim-spin shoud support outbound capabilities (eg redis) #58

Closed
ThorstenHans opened this issue Dec 11, 2022 · 11 comments
Closed

Comments

@ThorstenHans
Copy link

containerd-shim-spin currently supports simple workloads only. It should support all outbound capabilities provided by Spin like Redis and PostgreSQL.

When deploying a Spin application that uses outbound-redis::publish currently results in the "pod" failing with:

Normal   Created  1s (x3 over 18s)  kubelet   Created container main
Warning  Failed   1s (x3 over 18s)  kubelet   Error: failed to start containerd task "main": unknown import: `outbound-redis::publish` has not been defined: unknown
@Mossaka
Copy link
Member

Mossaka commented Dec 13, 2022

Yes, as of today, the spin trigger only support the HTTP capability.

Let me try to describe the work needed to support other capabilities:

update build_spin_trigger function to include other triggers based on spin application struct https://github.com/deislabs/containerd-wasm-shims/blob/main/containerd-shim-spin-v1/src/main.rs#L83-L98.

The trigger type can be found in https://github.dev/fermyon/spin/blob/8dfc4d6fbb31d624eb034f78640cb207bec1f682/src/commands/up.rs#L146-L149.

@ThorstenHans
Copy link
Author

ThorstenHans commented Dec 13, 2022

Hey @Mossaka thanks for the details, however I was referring to outbound redis in this particular issue, not about the redis trigger

@Mossaka
Copy link
Member

Mossaka commented Dec 13, 2022

Ah okay. The outbound redis should be avialable in spin v0.6.0, which I added in this PR #55 . I will try to create an example that uses the outbound redis capability.

@ThorstenHans
Copy link
Author

Yes spin isn't the problem here. The shim has to load the output capabilities from spin explicitly, which is not done at the moment.

@ChristianWeyer
Copy link

Do you have any idea what to do here @Mossaka ?

@Mossaka
Copy link
Member

Mossaka commented Jan 10, 2023

Yes, sorry for getting back to you late. I am looking into in this week.

@Mossaka
Copy link
Member

Mossaka commented Jan 12, 2023

I just tried creating a Spin application with using the outbound redis capability. The spin application is written in rust:

use anyhow::{anyhow, Result};
use spin_sdk::{
    http::{internal_server_error, Request, Response},
    http_component, redis,
};

const REDIS_ADDRESS_ENV: &str = "REDIS_ADDRESS";
const REDIS_CHANNEL_ENV: &str = "REDIS_CHANNEL";

#[http_component]
fn hello_world(_req: Request) -> Result<Response> {
    let address = std::env::var(REDIS_ADDRESS_ENV)?;
    let channel = std::env::var(REDIS_CHANNEL_ENV)?;

    // Get the message to publish from the Redis key "mykey"
    let payload = redis::get(&address, "mykey").map_err(|_| anyhow!("Error querying Redis"))?;

    // Set the Redis key "spin-example" to value "Eureka!"
    redis::set(&address, "spin-example", &b"Eureka!"[..])
        .map_err(|_| anyhow!("Error executing Redis set command"))?;

    // Set the Redis key "int-key" to value 0
    redis::set(&address, "int-key", format!("{:x}", 0).as_bytes())
        .map_err(|_| anyhow!("Error executing Redis set command"))?;
    let int_value = redis::incr(&address, "int-key")
        .map_err(|_| anyhow!("Error executing Redis incr command",))?;
    assert_eq!(int_value, 1);

    // Publish to Redis
    match redis::publish(&address, &channel, &payload) {
        Ok(()) => Ok(http::Response::builder().status(200).body(None)?),
        Err(_e) => internal_server_error(),
    }
    Ok(http::Response::builder().status(200).body(None)?)
}

Then I deployed this spin service and a redis service in kubernetes using the spin shim.

Everything works fine for me.
image

One thing I found interesting is that for some reason, spin redis cannot find the redis-server using kubernetes DNS service's A/AAAA records like redis://redis-service.default.svc.cluster.local:6379. I had to find the redis service IP address by running k exec -it redis -- env and set the value of REDIS_SERVICE_SERVICE_HOST to REDIS_ADDRESS environment in spin.toml.

I am not sure if this is a shim's bug or spin's bug.

Hope this helps!

@squillace
Copy link
Contributor

hey @ThorstenHans it appears that the version of spin in the shim does do outbound redis work successfully (with some oddities, as @Mossaka mentions). Can you confirm this? If you're using AKS to test, Microsoft needs to rebuild the shim and update the service, which it hopes to do this month.

@Mossaka
Copy link
Member

Mossaka commented Feb 15, 2023

Closing this one out as we can't reproduce ths issue.

@Mossaka Mossaka closed this as completed Feb 15, 2023
@ThorstenHans
Copy link
Author

I'll spin up a new AKS cluster these days and give it a try again. I'll keep you posted @Mossaka

@squillace
Copy link
Contributor

wait wait... new one flying in very shortly!!!

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

No branches or pull requests

4 participants