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::StatefulSetExt;
83pub use ext::StorageClassExt;
84pub use ext::SubjectExt;
85pub use ext::TaintExt;
86pub use ext::TimeExt;
87pub use ext::ToEnvFrom;
88pub use ext::ToEnvVar;
89pub use ext::TolerationBuilder;
90pub use ext::TolerationExt;
91pub use ext::TypedObjectReferenceExt;
92pub use ext::VolumeExt;
93pub use ext::VolumeMountExt;
94pub use get::ComponentConditionGetExt;
95pub use get::ComponentStatusGetExt;
96pub use get::ConfigMapGetExt;
97pub use get::ContainerGetExt;
98pub use get::ContainerStateTerminatedGetExt;
99pub use get::ContainerStateWaitingGetExt;
100pub use get::ContainerStatusGetExt;
101pub use get::DeploymentGetExt;
102pub use get::EphemeralContainerGetExt;
103pub use get::NamespaceGetExt;
104pub use get::PodConditionGetExt;
105pub use get::PodGetExt;
106pub use get::ReplicaSetConditionGetExt;
107pub use get::ReplicaSetGetExt;
108pub use get::SelfSubjectReviewGetExt;
109pub use get::StatefulSetGetExt;
110
111mod ext;
112mod get;
113
114pub mod label;
115
116pub mod namespace {
117    pub const DEFAULT: &str = "default";
118    pub const KUBE_PUBLIC: &str = "kube-public";
119    pub const KUBE_SYSTEM: &str = "kube-system";
120}
121
122pub fn typed_ref(
123    object: Option<&corev1::ObjectReference>,
124) -> Option<corev1::TypedLocalObjectReference> {
125    let object = object?;
126    let kind = object.kind.as_ref()?.clone();
127    let name = object.name.as_ref()?.clone();
128    let typed = corev1::TypedLocalObjectReference {
129        kind,
130        name,
131        ..default()
132    };
133    Some(typed)
134}
135
136pub fn local_ref(object: &corev1::ObjectReference) -> Option<corev1::LocalObjectReference> {
137    object.name.as_ref().map(corev1::LocalObjectReference::new)
138}
139
140pub fn owner_reference(
141    owner: corev1::ObjectReference,
142    is_controller: bool,
143    block_owner_deletion: bool,
144) -> Option<metav1::OwnerReference> {
145    Some(metav1::OwnerReference {
146        block_owner_deletion: Some(block_owner_deletion),
147        controller: Some(is_controller),
148        api_version: owner.api_version?,
149        kind: owner.kind?,
150        name: owner.name?,
151        uid: owner.uid?,
152    })
153}
154
155fn default<T: Default>() -> T {
156    T::default()
157}
158
159pub trait ToIntOrString {
160    fn to_int_or_string(self) -> intstr::IntOrString;
161}
162
163impl ToIntOrString for u8 {
164    fn to_int_or_string(self) -> intstr::IntOrString {
165        intstr::IntOrString::Int(self.into())
166    }
167}
168
169impl ToIntOrString for i8 {
170    fn to_int_or_string(self) -> intstr::IntOrString {
171        intstr::IntOrString::Int(self.into())
172    }
173}
174
175impl ToIntOrString for u16 {
176    fn to_int_or_string(self) -> intstr::IntOrString {
177        intstr::IntOrString::Int(self.into())
178    }
179}
180
181impl ToIntOrString for i16 {
182    fn to_int_or_string(self) -> intstr::IntOrString {
183        intstr::IntOrString::Int(self.into())
184    }
185}
186
187impl ToIntOrString for i32 {
188    fn to_int_or_string(self) -> intstr::IntOrString {
189        intstr::IntOrString::Int(self)
190    }
191}
192
193impl ToIntOrString for u64 {
194    fn to_int_or_string(self) -> intstr::IntOrString {
195        intstr::IntOrString::Int(self as i32)
196    }
197}
198
199impl ToIntOrString for String {
200    fn to_int_or_string(self) -> intstr::IntOrString {
201        intstr::IntOrString::String(self)
202    }
203}
204
205impl ToIntOrString for &str {
206    fn to_int_or_string(self) -> intstr::IntOrString {
207        intstr::IntOrString::String(self.to_string())
208    }
209}