k8_metadata_client/
nothing.rs

1// implementation of metadata client do nothing
2// it is used for testing where to satisfy metadata contract
3use std::fmt::Debug;
4use std::fmt::Display;
5use std::sync::Arc;
6
7use anyhow::Result;
8use async_trait::async_trait;
9use futures_util::stream::BoxStream;
10use futures_util::stream::StreamExt;
11use serde::de::DeserializeOwned;
12use serde::Serialize;
13use serde_json::Value;
14
15use k8_types::{InputK8Obj, K8List, K8Meta, K8Obj, DeleteStatus, K8Watch, Spec, UpdateK8ObjStatus};
16use k8_types::options::DeleteOptions;
17use crate::client::ObjectKeyNotFound;
18use crate::diff::PatchMergeType;
19
20use crate::{ListArg, MetadataClient, NameSpace, TokenStreamResult};
21
22pub struct DoNothingClient();
23
24#[async_trait]
25impl MetadataClient for DoNothingClient {
26    async fn retrieve_item<S, M>(&self, _metadata: &M) -> Result<Option<K8Obj<S>>>
27    where
28        K8Obj<S>: DeserializeOwned,
29        S: Spec,
30        M: K8Meta + Send + Sync,
31    {
32        Ok(None)
33    }
34
35    async fn retrieve_items_with_option<S, N>(
36        &self,
37        _namespace: N,
38        _option: Option<ListArg>,
39    ) -> Result<K8List<S>>
40    where
41        S: Spec,
42        N: Into<NameSpace> + Send + Sync,
43    {
44        Ok(K8List::default())
45    }
46
47    fn retrieve_items_in_chunks<'a, S, N>(
48        self: Arc<Self>,
49        _namespace: N,
50        _limit: u32,
51        _option: Option<ListArg>,
52    ) -> BoxStream<'a, K8List<S>>
53    where
54        S: Spec + 'static,
55        N: Into<NameSpace> + Send + Sync + 'static,
56    {
57        futures_util::stream::empty().boxed()
58    }
59
60    async fn delete_item_with_option<S, M>(
61        &self,
62        metadata: &M,
63        _options: Option<DeleteOptions>,
64    ) -> Result<DeleteStatus<S>>
65    where
66        S: Spec,
67        M: K8Meta + Send + Sync,
68    {
69        Err(ObjectKeyNotFound::new(metadata.name().into()).into())
70    }
71
72    async fn create_item<S>(&self, _value: InputK8Obj<S>) -> Result<K8Obj<S>>
73    where
74        InputK8Obj<S>: Serialize + Debug,
75        K8Obj<S>: DeserializeOwned,
76        S: Spec + Send,
77    {
78        Err(ObjectKeyNotFound::new(_value.metadata.name().into()).into())
79    }
80
81    async fn update_status<S>(&self, _value: &UpdateK8ObjStatus<S>) -> Result<K8Obj<S>>
82    where
83        UpdateK8ObjStatus<S>: Serialize + Debug,
84        K8Obj<S>: DeserializeOwned,
85        S: Spec + Send + Sync,
86        S::Status: Send + Sync,
87    {
88        Err(ObjectKeyNotFound::new(_value.metadata.name().into()).into())
89    }
90
91    async fn patch<S, M>(
92        &self,
93        metadata: &M,
94        _patch: &Value,
95        _merge_type: PatchMergeType,
96    ) -> Result<K8Obj<S>>
97    where
98        S: Spec,
99        M: K8Meta + Display + Send + Sync,
100    {
101        Err(ObjectKeyNotFound::new(metadata.name().into()).into())
102    }
103
104    async fn patch_status<S, M>(
105        &self,
106        metadata: &M,
107        _patch: &Value,
108        _merge_type: PatchMergeType,
109    ) -> Result<K8Obj<S>>
110    where
111        S: Spec,
112        M: K8Meta + Display + Send + Sync,
113    {
114        Err(ObjectKeyNotFound::new(metadata.name().into()).into())
115    }
116
117    async fn patch_subresource<S, M>(
118        &self,
119        metadata: &M,
120        _subresource: String,
121        _patch: &Value,
122        _merge_type: PatchMergeType,
123    ) -> Result<K8Obj<S>>
124    where
125        S: Spec,
126        M: K8Meta + Display + Send + Sync,
127    {
128        Err(ObjectKeyNotFound::new(metadata.name().into()).into())
129    }
130
131    fn watch_stream_since<S, N>(
132        &self,
133        _namespace: N,
134        _resource_version: Option<String>,
135    ) -> BoxStream<'_, TokenStreamResult<S>>
136    where
137        K8Watch<S>: DeserializeOwned,
138        S: Spec + Send + 'static,
139        S::Header: Send + 'static,
140        S::Status: Send + 'static,
141        N: Into<NameSpace>,
142    {
143        futures_util::stream::empty().boxed()
144    }
145}