1use super::*;
2
3pub trait KubeClientExt: Clone {
4 fn delete_params(&self) -> api::DeleteParams {
5 api::DeleteParams::default().grace_period(0)
6 }
7
8 fn background_delete(&self) -> api::DeleteParams {
9 api::DeleteParams::background().grace_period(0)
10 }
11
12 fn foreground_delete(&self) -> api::DeleteParams {
13 api::DeleteParams::foreground().grace_period(0)
14 }
15
16 fn orphan_delete(&self) -> api::DeleteParams {
17 api::DeleteParams::orphan().grace_period(0)
18 }
19
20 fn list_params(&self) -> api::ListParams {
21 api::ListParams::default()
22 }
23
24 fn watch_params(&self) -> api::WatchParams {
25 api::WatchParams::default()
26 }
27
28 fn post_params(&self) -> api::PostParams {
29 api::PostParams::default()
30 }
31
32 fn post_params_with_manager(&self, manager: &str) -> api::PostParams {
33 let mut pp = self.post_params();
34 pp.field_manager = Some(manager.to_string());
35 pp
36 }
37
38 fn patch_params(&self) -> api::PatchParams {
39 api::PatchParams::default()
40 }
41
42 fn patch_params_with_manager(&self, manager: &str) -> api::PatchParams {
43 api::PatchParams::apply(manager)
44 }
45
46 fn log_params(&self) -> api::LogParams {
47 api::LogParams::default()
48 }
49
50 fn log_params_previous(&self) -> api::LogParams {
51 api::LogParams {
52 previous: true,
53 ..api::LogParams::default()
54 }
55 }
56 fn api<K>(&self) -> api::Api<K>
57 where
58 K: client::Resource,
59 <K as client::Resource>::DynamicType: Default;
60
61 fn default_namespaced_api<K>(&self) -> api::Api<K>
62 where
63 K: client::Resource<Scope = k8s::openapi::NamespaceResourceScope>,
64 <K as client::Resource>::DynamicType: Default;
65
66 fn namespaced_api<K>(&self, namespace: &str) -> api::Api<K>
67 where
68 K: client::Resource<Scope = k8s::openapi::NamespaceResourceScope>,
69 <K as client::Resource>::DynamicType: Default;
70
71 fn apiservices(&self) -> api::Api<apiregistrationv1::APIService> {
72 self.api()
73 }
74
75 fn clusterroles(&self) -> api::Api<rbacv1::ClusterRole> {
76 self.api()
77 }
78
79 fn clusterrolebindings(&self) -> api::Api<rbacv1::ClusterRoleBinding> {
80 self.api()
81 }
82
83 fn crds(&self) -> api::Api<apiextensionsv1::CustomResourceDefinition> {
84 self.api()
85 }
86
87 fn endpoints<'a>(&self, namespace: impl Into<Option<&'a str>>) -> api::Api<corev1::Endpoints> {
88 self.namespaced_k(namespace)
89 }
90
91 fn nodes(&self) -> api::Api<corev1::Node> {
92 self.api()
93 }
94
95 fn namespaces(&self) -> api::Api<corev1::Namespace> {
96 self.api()
97 }
98
99 fn persistentvolumes(&self) -> api::Api<corev1::PersistentVolume> {
100 self.api()
101 }
102
103 fn storageclasses(&self) -> api::Api<storagev1::StorageClass> {
104 self.api()
105 }
106
107 fn configmaps<'a>(&self, namespace: impl Into<Option<&'a str>>) -> api::Api<corev1::ConfigMap> {
108 self.namespaced_k(namespace)
109 }
110
111 fn daemonsets<'a>(&self, namespace: impl Into<Option<&'a str>>) -> api::Api<appsv1::DaemonSet> {
112 self.namespaced_k(namespace)
113 }
114
115 fn deployments<'a>(
116 &self,
117 namespace: impl Into<Option<&'a str>>,
118 ) -> api::Api<appsv1::Deployment> {
119 self.namespaced_k(namespace)
120 }
121
122 fn horizontalpodautoscalers<'a>(
123 &self,
124 namespace: impl Into<Option<&'a str>>,
125 ) -> api::Api<autoscalingv2::HorizontalPodAutoscaler> {
126 self.namespaced_k(namespace)
127 }
128
129 fn jobs<'a>(&self, namespace: impl Into<Option<&'a str>>) -> api::Api<batchv1::Job> {
130 self.namespaced_k(namespace)
131 }
132
133 fn cronjobs<'a>(&self, namespace: impl Into<Option<&'a str>>) -> api::Api<batchv1::CronJob> {
134 self.namespaced_k(namespace)
135 }
136
137 fn persistentvolumeclaims<'a>(
138 &self,
139 namespace: impl Into<Option<&'a str>>,
140 ) -> api::Api<corev1::PersistentVolumeClaim> {
141 self.namespaced_k(namespace)
142 }
143
144 fn replicasets<'a>(
145 &self,
146 namespace: impl Into<Option<&'a str>>,
147 ) -> api::Api<appsv1::ReplicaSet> {
148 self.namespaced_k(namespace)
149 }
150
151 fn roles<'a>(&self, namespace: impl Into<Option<&'a str>>) -> api::Api<rbacv1::Role> {
152 self.namespaced_k(namespace)
153 }
154
155 fn rolebindings<'a>(
156 &self,
157 namespace: impl Into<Option<&'a str>>,
158 ) -> api::Api<rbacv1::RoleBinding> {
159 self.namespaced_k(namespace)
160 }
161 fn secrets<'a>(&self, namespace: impl Into<Option<&'a str>>) -> api::Api<corev1::Secret> {
162 self.namespaced_k(namespace)
163 }
164
165 fn pods<'a>(&self, namespace: impl Into<Option<&'a str>>) -> api::Api<corev1::Pod> {
166 self.namespaced_k(namespace)
167 }
168
169 fn serviceaccounts<'a>(
170 &self,
171 namespace: impl Into<Option<&'a str>>,
172 ) -> api::Api<corev1::ServiceAccount> {
173 self.namespaced_k(namespace)
174 }
175
176 fn services<'a>(&self, namespace: impl Into<Option<&'a str>>) -> api::Api<corev1::Service> {
177 self.namespaced_k(namespace)
178 }
179
180 fn statefulsets<'a>(
181 &self,
182 namespace: impl Into<Option<&'a str>>,
183 ) -> api::Api<appsv1::StatefulSet> {
184 self.namespaced_k(namespace)
185 }
186
187 fn namespaced_k<'a, K>(&self, namespace: impl Into<Option<&'a str>>) -> api::Api<K>
188 where
189 K: client::Resource<Scope = k8s::openapi::NamespaceResourceScope>,
190 <K as client::Resource>::DynamicType: Default,
191 {
192 let namespace = namespace.into();
193 if let Some(namespace) = namespace {
194 self.namespaced_api(namespace)
195 } else {
196 self.default_namespaced_api()
197 }
198 }
199}
200
201impl KubeClientExt for client::Client {
202 fn api<K>(&self) -> api::Api<K>
203 where
204 K: client::Resource,
205 <K as client::Resource>::DynamicType: Default,
206 {
207 api::Api::<K>::all(self.clone())
208 }
209
210 fn default_namespaced_api<K>(&self) -> api::Api<K>
211 where
212 K: client::Resource<Scope = k8s::openapi::NamespaceResourceScope>,
213 <K as client::Resource>::DynamicType: Default,
214 {
215 api::Api::<K>::default_namespaced(self.clone())
216 }
217
218 fn namespaced_api<K>(&self, namespace: &str) -> api::Api<K>
219 where
220 K: client::Resource<Scope = k8s::openapi::NamespaceResourceScope>,
221 <K as client::Resource>::DynamicType: Default,
222 {
223 api::Api::<K>::namespaced(self.clone(), namespace)
224 }
225}