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::node::v1 as nodev1;
31pub use openapi::api::policy::v1 as policyv1;
32pub use openapi::api::rbac::v1 as rbacv1;
33pub use openapi::api::scheduling::v1 as schedulingv1;
34pub use openapi::api::storage::v1 as storagev1;
35pub use openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1 as apiextensionsv1;
36pub use openapi::apimachinery::pkg::api::resource;
37pub use openapi::apimachinery::pkg::apis::meta::v1 as metav1;
38pub use openapi::apimachinery::pkg::util::intstr;
39pub use openapi::kube_aggregator::pkg::apis::apiregistration::v1 as apiregistrationv1;
40pub use openapi::ByteString;
41pub use openapi::Metadata;
42pub use openapi::Resource;
43
44openapi::k8s_if_ge_1_29! {
45pub use openapi::api::flowcontrol::v1 as flowcontrolv1;
46}
47
48pub use ext::ClusterRoleBindingExt;
49pub use ext::ClusterRoleExt;
50pub use ext::ConfigMapExt;
51pub use ext::ConfigMapVolumeSourceExt;
52pub use ext::ContainerExt;
53pub use ext::ContainerPortExt;
54pub use ext::CronJobExt;
55pub use ext::DaemonSetExt;
56pub use ext::DeploymentExt;
57pub use ext::EnvVarExt;
58pub use ext::HorizontalPodAutoscalerExt;
59pub use ext::JobExt;
60pub use ext::LabelSelectorExt;
61pub use ext::LocalObjectReferenceExt;
62pub use ext::MetricExt;
63pub use ext::NamespaceExt;
64pub use ext::NodeExt;
65pub use ext::OwnerReferenceExt;
66pub use ext::PodExt;
67pub use ext::PodSpecExt;
68pub use ext::PodTemplateSpecExt;
69pub use ext::PolicyRuleExt;
70pub use ext::ProbeExt;
71pub use ext::ReplicaSetExt;
72pub use ext::ResourceBuilder;
73pub use ext::RoleBindingExt;
74pub use ext::RoleExt;
75pub use ext::RoleRefExt;
76pub use ext::SecretEnvSourceExt;
77pub use ext::SecretExt;
78pub use ext::SecretExt2;
79pub use ext::SecretReferenceExt;
80pub use ext::SecretVolumeSourceExt;
81pub use ext::SecurityContextExt;
82pub use ext::ServiceAccountExt;
83pub use ext::ServiceExt;
84pub use ext::ServicePortExt;
85pub use ext::StorageClassExt;
86pub use ext::SubjectExt;
87pub use ext::TaintExt;
88pub use ext::TimeExt;
89pub use ext::ToEnvFrom;
90pub use ext::ToEnvVar;
91pub use ext::TolerationBuilder;
92pub use ext::TolerationExt;
93pub use ext::TypedObjectReferenceExt;
94pub use ext::VolumeExt;
95pub use ext::VolumeMountExt;
96pub use get::ConfigMapGetExt;
97pub use get::ContainerGetExt;
98pub use get::ContainerStatusGetExt;
99pub use get::DeploymentGetExt;
100pub use get::EphemeralContainerGetExt;
101pub use get::NamespaceGetExt;
102pub use get::PodConditionGetExt;
103pub use get::PodGetExt;
104pub use get::ReplicaSetConditionGetExt;
105pub use get::ReplicaSetGetExt;
106
107mod ext;
108mod get;
109
110pub mod namespace {
111    pub const DEFAULT: &str = "default";
112    pub const KUBE_PUBLIC: &str = "kube-public";
113    pub const KUBE_SYSTEM: &str = "kube-system";
114}
115
116pub mod label {
117    pub const APP_NAME: &str = "app.kubernetes.io/name";
118    pub const APP_INSTANCE: &str = "app.kubernetes.io/instance";
119    pub const APP_VERSION: &str = "app.kubernetes.io/version";
120    pub const APP_COMPONENT: &str = "app.kubernetes.io/component";
121    pub const APP_PART_OF: &str = "app.kubernetes.io/part-of";
122    pub const APP_MANAGED_BY: &str = "app.kubernetes.io/managed-by";
123    pub const DEFAULT_DEPLOYMENT_UNIQUE_LABEL_KEY: &str = "pod-template-hash";
124}
125
126pub fn typed_ref(
127    object: Option<&corev1::ObjectReference>,
128) -> Option<corev1::TypedLocalObjectReference> {
129    let object = object?;
130    let kind = object.kind.as_ref()?.clone();
131    let name = object.name.as_ref()?.clone();
132    let typed = corev1::TypedLocalObjectReference {
133        kind,
134        name,
135        ..default()
136    };
137    Some(typed)
138}
139
140pub fn local_ref(object: &corev1::ObjectReference) -> Option<corev1::LocalObjectReference> {
141    object.name.as_ref().map(corev1::LocalObjectReference::new)
142}
143
144pub fn owner_reference(
145    owner: corev1::ObjectReference,
146    is_controller: bool,
147    block_owner_deletion: bool,
148) -> Option<metav1::OwnerReference> {
149    Some(metav1::OwnerReference {
150        block_owner_deletion: Some(block_owner_deletion),
151        controller: Some(is_controller),
152        api_version: owner.api_version?,
153        kind: owner.kind?,
154        name: owner.name?,
155        uid: owner.uid?,
156    })
157}
158
159fn default<T: Default>() -> T {
160    T::default()
161}
162
163pub trait ToIntOrString {
164    fn to_int_or_string(self) -> intstr::IntOrString;
165}
166
167impl ToIntOrString for u8 {
168    fn to_int_or_string(self) -> intstr::IntOrString {
169        intstr::IntOrString::Int(self.into())
170    }
171}
172
173impl ToIntOrString for i8 {
174    fn to_int_or_string(self) -> intstr::IntOrString {
175        intstr::IntOrString::Int(self.into())
176    }
177}
178
179impl ToIntOrString for u16 {
180    fn to_int_or_string(self) -> intstr::IntOrString {
181        intstr::IntOrString::Int(self.into())
182    }
183}
184
185impl ToIntOrString for i16 {
186    fn to_int_or_string(self) -> intstr::IntOrString {
187        intstr::IntOrString::Int(self.into())
188    }
189}
190
191impl ToIntOrString for i32 {
192    fn to_int_or_string(self) -> intstr::IntOrString {
193        intstr::IntOrString::Int(self)
194    }
195}
196
197impl ToIntOrString for u64 {
198    fn to_int_or_string(self) -> intstr::IntOrString {
199        intstr::IntOrString::Int(self as i32)
200    }
201}
202
203impl ToIntOrString for String {
204    fn to_int_or_string(self) -> intstr::IntOrString {
205        intstr::IntOrString::String(self)
206    }
207}
208
209impl ToIntOrString for &str {
210    fn to_int_or_string(self) -> intstr::IntOrString {
211        intstr::IntOrString::String(self.to_string())
212    }
213}