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(
&self,
dt: &Self::DynamicType,
) -> Option<OwnerReference> { ... }
fn owner_ref(&self, 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
.metadata.name
And these optional properties:
.metadata.namespace
.metadata.resource_version
This avoids a bunch of the unnecessary unwrap mechanics for apps.
Required Associated Types§
sourcetype DynamicType: Send + Sync + 'static
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.
Required Methods§
sourcefn kind(dt: &Self::DynamicType) -> Cow<'_, str>
fn kind(dt: &Self::DynamicType) -> Cow<'_, str>
Returns kind of this object
sourcefn group(dt: &Self::DynamicType) -> Cow<'_, str>
fn group(dt: &Self::DynamicType) -> Cow<'_, str>
Returns group of this object
sourcefn version(dt: &Self::DynamicType) -> Cow<'_, str>
fn version(dt: &Self::DynamicType) -> Cow<'_, str>
Returns version of this object
sourcefn plural(dt: &Self::DynamicType) -> Cow<'_, str>
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.
sourcefn meta(&self) -> &ObjectMeta
fn meta(&self) -> &ObjectMeta
Metadata that all persisted resources must have
sourcefn meta_mut(&mut self) -> &mut ObjectMeta
fn meta_mut(&mut self) -> &mut ObjectMeta
Metadata that all persisted resources must have
Provided Methods§
sourcefn api_version(dt: &Self::DynamicType) -> Cow<'_, str>
fn api_version(dt: &Self::DynamicType) -> Cow<'_, str>
Returns apiVersion of this object
sourcefn url_path(dt: &Self::DynamicType, namespace: Option<&str>) -> String
fn url_path(dt: &Self::DynamicType, namespace: Option<&str>) -> String
Creates a url path for http requests for this resource
sourcefn object_ref(&self, dt: &Self::DynamicType) -> ObjectReference
fn object_ref(&self, dt: &Self::DynamicType) -> ObjectReference
Generates an object reference for the resource
sourcefn controller_owner_ref(&self, dt: &Self::DynamicType) -> Option<OwnerReference>
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.
use k8s_openapi::api::core::v1::ConfigMap;
use k8s_openapi::api::core::v1::Pod;
use k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta;
use kube_core::Resource;
let p = Pod::default();
let controller_ref = p.controller_owner_ref(&());
let cm = ConfigMap {
metadata: ObjectMeta {
name: Some("pod-configmap".to_string()),
owner_references: Some(controller_ref.into_iter().collect()),
..ObjectMeta::default()
},
..Default::default()
};
sourcefn owner_ref(&self, dt: &Self::DynamicType) -> Option<OwnerReference>
fn owner_ref(&self, dt: &Self::DynamicType) -> Option<OwnerReference>
Generates an owner reference pointing to this resource
Note: this returns an Option
, but for objects populated from the apiserver,
this Option can be safely unwrapped.
use k8s_openapi::api::core::v1::ConfigMap;
use k8s_openapi::api::core::v1::Pod;
use k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta;
use kube_core::Resource;
let p = Pod::default();
let owner_ref = p.owner_ref(&());
let cm = ConfigMap {
metadata: ObjectMeta {
name: Some("pod-configmap".to_string()),
owner_references: Some(owner_ref.into_iter().collect()),
..ObjectMeta::default()
},
..Default::default()
};
Object Safety§
Implementors§
source§impl Resource for DynamicObject
impl Resource for DynamicObject
type DynamicType = ApiResource
type Scope = DynamicResourceScope
source§impl<K> Resource for PartialObjectMeta<K>where
K: Resource,
impl<K> Resource for PartialObjectMeta<K>where
K: Resource,
type DynamicType = <K as Resource>::DynamicType
type Scope = <K as Resource>::Scope
source§impl<K> Resource for DeserializeGuard<K>where
K: Resource,
impl<K> Resource for DeserializeGuard<K>where
K: Resource,
type DynamicType = <K as Resource>::DynamicType
type Scope = <K as Resource>::Scope
source§impl<K, S> Resource for K
impl<K, S> Resource for K
Implement accessor trait for any ObjectMeta-using Kubernetes Resource