kube_derive

Derive Macro Resource

Source
#[derive(Resource)]
{
    // Attributes available to this derive:
    #[resource]
}
Expand description

A custom derive for inheriting Resource impl for the type.

This will generate a kube::Resource trait implementation, inheriting from a specified resource trait implementation.

This allows strict typing to some typical resources like Secret or ConfigMap, in cases when implementing CRD is not desirable or it does not fit the use-case.

Once derived, the type can be used with kube::Api.

ยงExample

use kube::api::ObjectMeta;
use k8s_openapi::api::core::v1::ConfigMap;
use kube_derive::Resource;
use kube::Client;
use kube::Api;
use serde::Deserialize;

#[derive(Resource, Clone, Debug, Deserialize)]
#[resource(inherit = "ConfigMap")]
struct FooMap {
    metadata: ObjectMeta,
    data: Option<FooMapSpec>,
}

#[derive(Clone, Debug, Deserialize)]
struct FooMapSpec {
    field: String,
}

let client: Client = todo!();
let api: Api<FooMap> = Api::default_namespaced(client);
let config_map = api.get("with-field");

The example above will generate:

// impl kube::Resource for FooMap { .. }