k8s_openapi_ext/
lib.rs

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