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