Skip to main content

Crate crossplane_fn_sdk_unofficial

Crate crossplane_fn_sdk_unofficial 

Source
Expand description

This is an unofficial Rust composite function sdk for crossplane.

Crossplane composite functions are implemented as gRPC server that have to handle specific cli args to setup mtls. This sdk cares about this part and has generated rust types from the published Crossplane protocol buffer schema. Furthermore, it provides some helper functions to simplify function writing.

The central functionality besides some type mapping helper traits is provided via the run_server-function which will start a gRPC server that handles the composite function requests with the business logic provided by the sdk-user.

Crossplane expects it’s users to only output those fields they want to influence into the desired state. If you are looking for a crate that helps deriving partial representation of Kubernetes types my other crate optionable might be useful as well.

§Compile-time dependencies

The protocol buffer library prost-wkt-types used by the sdk requires protoc at compile-time.

§Examples

§Direct composite function (synchronous)

fn composite_function(request: RunFunctionRequest) -> Result<RunFunctionResponse,Status> {
    // Business logic goes here
    Ok(RunFunctionResponse {
        context: request.context,
        meta: Some(request.meta.into_response_meta(60)),
        desired: request.desired,
        ..Default::default()
    })
}

run_server(Args::parse(), composite_function).await?

§Explicit Trait-implementation (asynchronous)

struct ExampleFunction{}

#[tonic::async_trait]
impl CompositeFunction for ExampleFunction {
    async fn run_function(&self,request: RunFunctionRequest) -> Result<RunFunctionResponse,Status> {
        // Business logic goes here
        Ok(RunFunctionResponse {
            context: request.context,
            meta: Some(request.meta.into_response_meta(60)),
            desired: request.desired,
            ..Default::default()
        })
    }
}

run_server(Args::parse(), ExampleFunction{}).await?

Re-exports§

pub use clap;
pub use tokio;
pub use tonic;

Modules§

crossplane
Rust types generated from the official crossplane protobuf types for composite function.

Structs§

Args
CLI arguments as required by the composite function spec.

Traits§

CompositeFunction
Implement this trait to process composite functions, intended to be used with run_server. It is automatically implemented for any synchronous [Fn](RunFunctionRequest) -> Result<RunFunctionResponse,Status>.
IntoResponseMeta
Allows transforming this object into a response_meta object. Mainly used to extend the RequestMeta type. Sealed (cannot be implemented by users).
TryFromResource
Type mapping from a crossplane resource (protobuf json format) into a rust type. All trait functions have default implementations using serde that should be sufficient for common use cases.
TryIntoResource
Takes a Kubernetes object and transforms it into a Crossplane managed resource

Functions§

run_server
Reads the cli arguments, configures and starts the grpc server and handles sigterm/sigint for shutdown. Calls the provided CompositeFunction-impl for the core business logic of the composite function. The cli follows the official composite function spec.