Skip to main content

OwnerRefExt

Trait OwnerRefExt 

Source
pub trait OwnerRefExt: Resource {
    // Required methods
    fn has_owner_reference(&self, uid: &str) -> bool;
    fn set_owner_reference<Owner: Resource>(
        &mut self,
        owner: &Owner,
        dt: &Owner::DynamicType,
    ) -> Option<()>;
    fn set_controller_reference<Owner: Resource>(
        &mut self,
        owner: &Owner,
        dt: &Owner::DynamicType,
    ) -> Result<(), AlreadyOwnedError>;
}
Expand description

Extension trait for managing owner references on any Resource

Like FinalizerExt, it is kept separate from ResourceExt and is only in scope when imported explicitly.

use k8s_openapi::api::core::v1::{ConfigMap, Pod};
use k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta;
use kube_core::OwnerRefExt;

let pod = Pod {
    metadata: ObjectMeta {
        name: Some("my-pod".to_string()),
        uid: Some("pod-uid".to_string()),
        ..Default::default()
    },
    ..Default::default()
};
let mut cm = ConfigMap::default();
assert!(!cm.has_owner_reference("pod-uid"));
cm.set_owner_reference(&pod, &());
assert!(cm.has_owner_reference("pod-uid"));

Required Methods§

Source

fn has_owner_reference(&self, uid: &str) -> bool

Returns whether the object has an owner reference with the given uid

Source

fn set_owner_reference<Owner: Resource>( &mut self, owner: &Owner, dt: &Owner::DynamicType, ) -> Option<()>

Sets owner as a (non-controlling) owner reference on the object

If the object already has an owner reference with the same uid, it is replaced in place; otherwise the new owner reference is appended.

Returns None if owner does not have a .metadata.name/.metadata.uid set yet (see Resource::owner_ref), in which case the object is left unchanged.

Source

fn set_controller_reference<Owner: Resource>( &mut self, owner: &Owner, dt: &Owner::DynamicType, ) -> Result<(), AlreadyOwnedError>

Sets owner as the controller reference on the object

Errors with AlreadyOwnedError if the object already has a controller reference pointing at a different owner. Idempotent (a no-op returning Ok(())) if the existing controller reference already points at owner.

Returns Ok(()) without changes if owner does not have a .metadata.name/.metadata.uid set yet.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§