1#![cfg_attr(feature = "pedantic", warn(clippy::pedantic))]
2#![warn(clippy::cast_possible_truncation)]
3#![warn(clippy::cloned_instead_of_copied)]
4#![warn(clippy::flat_map_option)]
5#![warn(clippy::implicit_clone)]
6#![warn(clippy::map_flatten)]
7#![warn(clippy::map_unwrap_or)]
8#![warn(clippy::unused_trait_names)]
9#![warn(clippy::use_self)]
10#![warn(deprecated_in_future)]
11#![warn(future_incompatible)]
12#![warn(noop_method_call)]
13#![warn(unreachable_pub)]
14#![warn(redundant_imports)]
15#![warn(missing_debug_implementations)]
16#![warn(rust_2018_compatibility)]
17#![warn(rust_2021_compatibility)]
18#![warn(rust_2024_compatibility)]
19#![warn(rust_2018_idioms)]
20#![warn(unused)]
21#![deny(warnings)]
22
23pub use k8s_openapi as openapi;
24
25pub use openapi::api::admissionregistration::v1 as admissionregistrationv1;
26pub use openapi::api::apps::v1 as appsv1;
27pub use openapi::api::authentication::v1 as authenticationv1;
28pub use openapi::api::authorization::v1 as authorizationv1;
29pub use openapi::api::autoscaling::v1 as autoscalingv1;
30pub use openapi::api::autoscaling::v2 as autoscalingv2;
31pub use openapi::api::batch::v1 as batchv1;
32pub use openapi::api::certificates::v1 as certificatesv1;
33pub use openapi::api::coordination::v1 as coordinationv1;
34pub use openapi::api::core::v1 as corev1;
35pub use openapi::api::events::v1 as eventsv1;
36pub use openapi::api::flowcontrol::v1 as flowcontrolv1;
37pub use openapi::api::node::v1 as nodev1;
38pub use openapi::api::policy::v1 as policyv1;
39pub use openapi::api::rbac::v1 as rbacv1;
40pub use openapi::api::scheduling::v1 as schedulingv1;
41pub use openapi::api::storage::v1 as storagev1;
42pub use openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1 as apiextensionsv1;
43pub use openapi::apimachinery::pkg::api::resource;
44pub use openapi::apimachinery::pkg::apis::meta::v1 as metav1;
45pub use openapi::apimachinery::pkg::util::intstr;
46pub use openapi::kube_aggregator::pkg::apis::apiregistration::v1 as apiregistrationv1;
47pub use openapi::ByteString;
48pub use openapi::Metadata;
49pub use openapi::Resource;
50
51pub use ext::ClusterRoleBindingExt;
52pub use ext::ClusterRoleExt;
53pub use ext::ConfigMapExt;
54pub use ext::ConfigMapVolumeSourceExt;
55pub use ext::ContainerExt;
56pub use ext::ContainerPortExt;
57pub use ext::CronJobExt;
58pub use ext::DaemonSetExt;
59pub use ext::DeploymentExt;
60pub use ext::EnvVarExt;
61pub use ext::HorizontalPodAutoscalerExt;
62pub use ext::JobExt;
63pub use ext::LabelSelectorExt;
64pub use ext::LocalObjectReferenceExt;
65pub use ext::MetricExt;
66pub use ext::NamespaceExt;
67pub use ext::NodeExt;
68pub use ext::OwnerReferenceExt;
69pub use ext::PodExt;
70pub use ext::PodSpecExt;
71pub use ext::PodTemplateSpecExt;
72pub use ext::PolicyRuleExt;
73pub use ext::ProbeExt;
74pub use ext::ReplicaSetExt;
75pub use ext::ResourceBuilder;
76pub use ext::RoleBindingExt;
77pub use ext::RoleExt;
78pub use ext::RoleRefExt;
79pub use ext::SecretEnvSourceExt;
80pub use ext::SecretExt;
81pub use ext::SecretExt2;
82pub use ext::SecretReferenceExt;
83pub use ext::SecretVolumeSourceExt;
84pub use ext::SecurityContextExt;
85pub use ext::ServiceAccountExt;
86pub use ext::ServiceExt;
87pub use ext::ServicePortExt;
88pub use ext::StatefulSetExt;
89pub use ext::StorageClassExt;
90pub use ext::SubjectExt;
91pub use ext::TaintExt;
92pub use ext::TimeExt;
93pub use ext::ToEnvFrom;
94pub use ext::ToEnvVar;
95pub use ext::TolerationBuilder;
96pub use ext::TolerationExt;
97pub use ext::TypedObjectReferenceExt;
98pub use ext::VolumeExt;
99pub use ext::VolumeMountExt;
100pub use get::ComponentConditionGetExt;
101pub use get::ComponentStatusGetExt;
102pub use get::ConditionGetExt;
103pub use get::ConfigMapGetExt;
104pub use get::ContainerGetExt;
105pub use get::ContainerStateTerminatedGetExt;
106pub use get::ContainerStateWaitingGetExt;
107pub use get::ContainerStatusGetExt;
108pub use get::DeploymentGetExt;
109pub use get::EphemeralContainerGetExt;
110pub use get::NamespaceGetExt;
111pub use get::PodConditionGetExt;
112pub use get::PodGetExt;
113pub use get::ReplicaSetConditionGetExt;
114pub use get::ReplicaSetGetExt;
115pub use get::SecretGetExt;
116pub use get::SelfSubjectReviewGetExt;
117pub use get::ServiceGetExt;
118pub use get::ServicePortGetExt;
119pub use get::StatefulSetGetExt;
120
121mod ext;
122mod get;
123
124pub mod label;
125
126pub mod namespace {
127 pub const DEFAULT: &str = "default";
128 pub const KUBE_PUBLIC: &str = "kube-public";
129 pub const KUBE_SYSTEM: &str = "kube-system";
130}
131
132pub fn typed_ref(
133 object: Option<&corev1::ObjectReference>,
134) -> Option<corev1::TypedLocalObjectReference> {
135 let object = object?;
136 let kind = object.kind.as_ref()?.clone();
137 let name = object.name.as_ref()?.clone();
138 let typed = corev1::TypedLocalObjectReference {
139 kind,
140 name,
141 ..default()
142 };
143 Some(typed)
144}
145
146pub fn local_ref(object: &corev1::ObjectReference) -> Option<corev1::LocalObjectReference> {
147 object.name.as_ref().map(corev1::LocalObjectReference::new)
148}
149
150pub fn owner_reference(
151 owner: corev1::ObjectReference,
152 is_controller: bool,
153 block_owner_deletion: bool,
154) -> Option<metav1::OwnerReference> {
155 Some(metav1::OwnerReference {
156 block_owner_deletion: Some(block_owner_deletion),
157 controller: Some(is_controller),
158 api_version: owner.api_version?,
159 kind: owner.kind?,
160 name: owner.name?,
161 uid: owner.uid?,
162 })
163}
164
165fn default<T: Default>() -> T {
166 T::default()
167}
168
169pub trait ToIntOrString {
170 fn to_int_or_string(self) -> intstr::IntOrString;
171}
172
173impl ToIntOrString for u8 {
174 fn to_int_or_string(self) -> intstr::IntOrString {
175 intstr::IntOrString::Int(self.into())
176 }
177}
178
179impl ToIntOrString for i8 {
180 fn to_int_or_string(self) -> intstr::IntOrString {
181 intstr::IntOrString::Int(self.into())
182 }
183}
184
185impl ToIntOrString for u16 {
186 fn to_int_or_string(self) -> intstr::IntOrString {
187 intstr::IntOrString::Int(self.into())
188 }
189}
190
191impl ToIntOrString for i16 {
192 fn to_int_or_string(self) -> intstr::IntOrString {
193 intstr::IntOrString::Int(self.into())
194 }
195}
196
197impl ToIntOrString for i32 {
198 fn to_int_or_string(self) -> intstr::IntOrString {
199 intstr::IntOrString::Int(self)
200 }
201}
202
203impl ToIntOrString for u64 {
204 fn to_int_or_string(self) -> intstr::IntOrString {
205 intstr::IntOrString::Int(self.try_into().unwrap_or(i32::MAX))
206 }
207}
208
209impl ToIntOrString for String {
210 fn to_int_or_string(self) -> intstr::IntOrString {
211 intstr::IntOrString::String(self)
212 }
213}
214
215impl ToIntOrString for &str {
216 fn to_int_or_string(self) -> intstr::IntOrString {
217 intstr::IntOrString::String(self.to_string())
218 }
219}