Trait kube::core::Resource

source ·
pub trait Resource {
    type DynamicType: Send + Sync + 'static;
    type Scope;

    // Required methods
    fn kind(dt: &Self::DynamicType) -> Cow<'_, str>;
    fn group(dt: &Self::DynamicType) -> Cow<'_, str>;
    fn version(dt: &Self::DynamicType) -> Cow<'_, str>;
    fn plural(dt: &Self::DynamicType) -> Cow<'_, str>;
    fn meta(&self) -> &ObjectMeta;
    fn meta_mut(&mut self) -> &mut ObjectMeta;

    // Provided methods
    fn api_version(dt: &Self::DynamicType) -> Cow<'_, str> { ... }
    fn url_path(dt: &Self::DynamicType, namespace: Option<&str>) -> String { ... }
    fn object_ref(&self, dt: &Self::DynamicType) -> ObjectReference { ... }
    fn controller_owner_ref(
        dt: &Self::DynamicType
    ) -> Option<OwnerReference> { ... }
Expand description

An accessor trait for a kubernetes Resource.

This is for a subset of Kubernetes type that do not end in List. These types, using ObjectMeta, SHOULD all have required properties:

  • .metadata

And these optional properties:

  • .metadata.namespace
  • .metadata.resource_version

This avoids a bunch of the unnecessary unwrap mechanics for apps.

Required Associated Types§


type DynamicType: Send + Sync + 'static

Type information for types that do not know their resource information at compile time.

Types that know their metadata at compile time should select DynamicType = (). Types that require some information at runtime should select DynamicType as type of this information.

See DynamicObject for a valid implementation of non-k8s-openapi resources.


type Scope

Type information for the api scope of the resource when known at compile time

Types from k8s_openapi come with an explicit k8s_openapi::ResourceScope Dynamic types should select Scope = DynamicResourceScope

Required Methods§


fn kind(dt: &Self::DynamicType) -> Cow<'_, str>

Returns kind of this object


fn group(dt: &Self::DynamicType) -> Cow<'_, str>

Returns group of this object


fn version(dt: &Self::DynamicType) -> Cow<'_, str>

Returns version of this object


fn plural(dt: &Self::DynamicType) -> Cow<'_, str>

Returns the plural name of the kind

This is known as the resource in apimachinery, we rename it for disambiguation.


fn meta(&self) -> &ObjectMeta

Metadata that all persisted resources must have


fn meta_mut(&mut self) -> &mut ObjectMeta

Metadata that all persisted resources must have

Provided Methods§


fn api_version(dt: &Self::DynamicType) -> Cow<'_, str>

Returns apiVersion of this object


fn url_path(dt: &Self::DynamicType, namespace: Option<&str>) -> String

Creates a url path for http requests for this resource


fn object_ref(&self, dt: &Self::DynamicType) -> ObjectReference

Generates an object reference for the resource


fn controller_owner_ref(&self, dt: &Self::DynamicType) -> Option<OwnerReference>

Generates a controller owner reference pointing to this resource

Note: this returns an Option, but for objects populated from the apiserver, this Option can be safely unwrapped.

Object Safety§

This trait is not object safe.



impl Resource for DynamicObject


impl<K> Resource for PartialObjectMeta<K>where K: Resource,


impl<K, S> Resource for Kwhere K: Metadata<Ty = ObjectMeta, Scope = S> + Resource,

Implement accessor trait for any ObjectMeta-using Kubernetes Resource


type DynamicType = ()


type Scope = S


impl<P, U> Resource for Object<P, U>where P: Clone, U: Clone,