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