Giter Club home page Giter Club logo

knative-rs's Introduction

Knative

CI Crates.io

A Rust implementation of Knative and Knative Eventing custom resource defintions and objects, leveraging kube-rs.

This implementation is incomplete and should be considered pre-alpha. It contains only a small subset of the full specification.

Currently, you can use this crate to manage the status of a custom event source CustomResource in accordance with knative's expectations.

use schemars::JsonSchema;
use serde::{Serialize, Deserialize};
use kube::{Api, CustomResource, Resource, ResourceExt};
use kube::runtime::controller::{Action, Context};
use knative::source_types::{
    SourceSpec,
    SourceStatus,
    SourceCondition,
    SinkManager,
};
use std::sync::Arc;

#[derive(Serialize, Deserialize, CustomResource, Clone, Debug, JsonSchema)]
#[kube(group = "mysource.dev", version = "v1", kind = "MySource", status = "MySourceStatus", namespaced)]
struct MySourceSpec {
    #[serde(flatten)]
    source_spec: SourceSpec,
}

#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)]
struct MySourceStatus {
    #[serde(flatten)]
    source_status: SourceStatus<SourceCondition>,
}

#[derive(Clone)]
struct Data {
    client: kube::Client,
}

async fn reconcile(my_resource: Arc<MySource>, ctx: Context<Data>) -> Result<Action, kube::Error> {
    let client = ctx.get_ref().client.clone();
    let api = Api::<MySource>::namespaced(
        client.clone(),
        my_resource.namespace().as_ref().unwrap()
    );
    let mut resource = api.get_status(&my_resource.name()).await?;

    if let Some(ref mut status) = resource.status {
        status.source_status.mark_sink("http://hardcoded-sink".parse().unwrap());

        // ...set the K_SINK environment variable on the receive-adapter that this controller manages

        // ...patch the new status with the api
    }

    Ok(Action::requeue(std::time::Duration::from_secs(60 * 60)))
}

Additional reference usage of this crate is currently WIP!

knative-rs's People

Contributors

rusty-jules avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.