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§
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§
- Composite
Function - 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>. - Into
Response Meta - Allows transforming this object into a
response_metaobject. Mainly used to extend theRequestMetatype. Sealed (cannot be implemented by users). - TryFrom
Resource - Type mapping from a crossplane resource (protobuf json format) into a rust type.
All trait functions have default implementations using
serdethat should be sufficient for common use cases. - TryInto
Resource - 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.