From b9a9a94bbf5c6d2769c6b75de5d38f584977b29b Mon Sep 17 00:00:00 2001 From: clux Date: Sat, 19 Oct 2024 16:55:50 +0100 Subject: [PATCH 1/5] Add a k8s re-esport module for stable modules - Allows easier imports that bypasses the heavier k8s-openapi directory. - Doesn't really expose directly breakable apis (only stable v1/v2 modules) - Easier internal imports - Easier user imports (see later commit) Signed-off-by: clux --- kube-core/src/crd.rs | 2 +- kube-core/src/dynamic.rs | 4 ++-- kube-core/src/gvk.rs | 6 ++++-- kube-core/src/k8s.rs | 31 +++++++++++++++++++++++++++++++ kube-core/src/labels.rs | 2 +- kube-core/src/lib.rs | 2 ++ kube-core/src/metadata.rs | 5 ++--- kube-core/src/schema.rs | 2 +- kube-core/src/util.rs | 15 ++++++++------- kube/src/lib.rs | 2 +- 10 files changed, 53 insertions(+), 18 deletions(-) create mode 100644 kube-core/src/k8s.rs diff --git a/kube-core/src/crd.rs b/kube-core/src/crd.rs index 376e3d632..f48ac476d 100644 --- a/kube-core/src/crd.rs +++ b/kube-core/src/crd.rs @@ -1,6 +1,6 @@ //! Traits and tyes for CustomResources -use k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions as apiexts; +use crate::k8s::apiextensions_apiserver::pkg::apis::apiextensions as apiexts; /// Types for v1 CustomResourceDefinitions pub mod v1 { diff --git a/kube-core/src/dynamic.rs b/kube-core/src/dynamic.rs index ebaa7e3a6..16d03abc2 100644 --- a/kube-core/src/dynamic.rs +++ b/kube-core/src/dynamic.rs @@ -7,7 +7,7 @@ use crate::{ resource::{DynamicResourceScope, Resource}, }; -use k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta; +use crate::k8s::metav1::ObjectMeta; use std::borrow::Cow; use thiserror::Error; @@ -113,11 +113,11 @@ mod test { use crate::{ dynamic::{ApiResource, DynamicObject}, gvk::GroupVersionKind, + k8s::corev1::Pod, params::{Patch, PatchParams, PostParams}, request::Request, resource::Resource, }; - use k8s_openapi::api::core::v1::Pod; #[test] fn raw_custom_resource() { diff --git a/kube-core/src/gvk.rs b/kube-core/src/gvk.rs index 91b986601..482c1ba0a 100644 --- a/kube-core/src/gvk.rs +++ b/kube-core/src/gvk.rs @@ -1,8 +1,10 @@ //! Type information structs for dynamic resources. use std::str::FromStr; -use crate::TypeMeta; -use k8s_openapi::{api::core::v1::ObjectReference, apimachinery::pkg::apis::meta::v1::OwnerReference}; +use crate::{ + k8s::{corev1::ObjectReference, metav1::OwnerReference}, + TypeMeta, +}; use serde::{Deserialize, Serialize}; use thiserror::Error; diff --git a/kube-core/src/k8s.rs b/kube-core/src/k8s.rs new file mode 100644 index 000000000..1138aca34 --- /dev/null +++ b/kube-core/src/k8s.rs @@ -0,0 +1,31 @@ +//! Indirection layer for generated structs for easier imports + +/// Re-export k8s-openapi root modules +pub use k8s_openapi::{api, apiextensions_apiserver, apimachinery}; +/// Re-export versioned stable modules as the client-go like equivalent names +/// +/// Names should generally match https://pkg.go.dev/k8s.io/client-go/kubernetes/typed +#[rustfmt::skip] +pub use { + api::admissionregistration::v1 as admissionregistrationv1, + api::apps::v1 as appsv1, + api::authentication::v1 as authenticationv1, + api::authorization::v1 as authorizationv1, + api::autoscaling::v1 as autoscalingv1, + api::autoscaling::v2 as autoscalingv2, + api::batch::v1 as batchv1, + api::certificates::v1 as certificatesv1, + api::coordination::v1 as coordinationv1, + api::core::v1 as corev1, + api::discovery::v1 as discoveryv1, + api::events::v1 as eventsv1, + api::flowcontrol::v1 as flowcontrolv1, + api::networking::v1 as networkingv1, + api::node::v1 as nodev1, + api::policy::v1 as policyv1, + api::rbac::v1 as rbacv1, + api::scheduling::v1 as schedulingv1, + api::storage::v1 as storagev1, + apiextensions_apiserver::pkg::apis::apiextensions::v1 as apiextensionsv1, + apimachinery::pkg::apis::meta::v1 as metav1, +}; diff --git a/kube-core/src/labels.rs b/kube-core/src/labels.rs index eca0450e0..0b4cfcab7 100644 --- a/kube-core/src/labels.rs +++ b/kube-core/src/labels.rs @@ -1,6 +1,6 @@ //! Type safe label selector logic +use crate::k8s::metav1::{LabelSelector, LabelSelectorRequirement}; use core::fmt; -use k8s_openapi::apimachinery::pkg::apis::meta::v1::{LabelSelector, LabelSelectorRequirement}; use serde::{Deserialize, Serialize}; use std::{ cmp::PartialEq, diff --git a/kube-core/src/lib.rs b/kube-core/src/lib.rs index 969d10e0a..77ae65b3d 100644 --- a/kube-core/src/lib.rs +++ b/kube-core/src/lib.rs @@ -8,6 +8,8 @@ //! (even with zero features) under [`kube::core`]((https://docs.rs/kube/*/kube/core/index.html)). #![cfg_attr(docsrs, feature(doc_cfg))] +pub mod k8s; + #[cfg_attr(docsrs, doc(cfg(feature = "admission")))] #[cfg(feature = "admission")] pub mod admission; diff --git a/kube-core/src/metadata.rs b/kube-core/src/metadata.rs index 67edf6e16..a23af2647 100644 --- a/kube-core/src/metadata.rs +++ b/kube-core/src/metadata.rs @@ -1,7 +1,7 @@ //! Metadata structs used in traits, lists, and dynamic objects. use std::{borrow::Cow, marker::PhantomData}; -pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::{ListMeta, ObjectMeta}; +pub use crate::k8s::metav1::{ListMeta, ObjectMeta}; use serde::{Deserialize, Serialize}; use crate::{DynamicObject, Resource}; @@ -178,8 +178,7 @@ impl Resource for PartialObjectMeta { #[cfg(test)] mod test { use super::{ObjectMeta, PartialObjectMeta, PartialObjectMetaExt}; - use crate::Resource; - use k8s_openapi::api::core::v1::Pod; + use crate::{k8s::corev1::Pod, Resource}; #[test] fn can_convert_and_derive_partial_metadata() { diff --git a/kube-core/src/schema.rs b/kube-core/src/schema.rs index 5cdcd84ab..50c6802ff 100644 --- a/kube-core/src/schema.rs +++ b/kube-core/src/schema.rs @@ -1,6 +1,6 @@ //! Utilities for managing [`CustomResourceDefinition`] schemas //! -//! [`CustomResourceDefinition`]: `k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceDefinition` +//! [`CustomResourceDefinition`]: `crate::k8s::apiextensionsv1::CustomResourceDefinition` // Used in docs #[allow(unused_imports)] use schemars::gen::SchemaSettings; diff --git a/kube-core/src/util.rs b/kube-core/src/util.rs index 7f45e5500..2fd4f2c96 100644 --- a/kube-core/src/util.rs +++ b/kube-core/src/util.rs @@ -1,11 +1,11 @@ //! Utils and helpers use crate::{ + k8s::appsv1::{DaemonSet, Deployment, ReplicaSet, StatefulSet}, params::{Patch, PatchParams}, request, Request, }; use chrono::Utc; -use k8s_openapi::api::apps::v1::{DaemonSet, Deployment, ReplicaSet, StatefulSet}; /// Restartable Resource marker trait pub trait Restart {} @@ -61,12 +61,15 @@ impl Request { #[cfg(test)] mod test { - use crate::{params::Patch, request::Request, resource::Resource}; + use crate::{ + k8s::{appsv1, corev1}, + params::Patch, + request::Request, + resource::Resource, + }; #[test] fn restart_patch_is_correct() { - use k8s_openapi::api::apps::v1 as appsv1; - let url = appsv1::Deployment::url_path(&(), Some("ns")); let req = Request::new(url).restart("mydeploy").unwrap(); assert_eq!(req.uri(), "/apis/apps/v1/namespaces/ns/deployments/mydeploy?"); @@ -79,9 +82,7 @@ mod test { #[test] fn cordon_patch_is_correct() { - use k8s_openapi::api::core::v1::Node; - - let url = Node::url_path(&(), Some("ns")); + let url = corev1::Node::url_path(&(), Some("ns")); let req = Request::new(url).cordon("mynode").unwrap(); assert_eq!(req.uri(), "/api/v1/namespaces/ns/nodes/mynode?"); assert_eq!(req.method(), "PATCH"); diff --git a/kube/src/lib.rs b/kube/src/lib.rs index e7be35690..340af4fd8 100644 --- a/kube/src/lib.rs +++ b/kube/src/lib.rs @@ -173,7 +173,7 @@ pub use kube_derive::Resource; #[doc(inline)] pub use kube_runtime as runtime; -pub use crate::core::{CustomResourceExt, Resource, ResourceExt}; +pub use crate::core::{k8s, CustomResourceExt, Resource, ResourceExt}; #[doc(inline)] pub use kube_core as core; // Mock tests for the runtime From 1a229abf1db3c488e5243b590ebd2ccd4de9dc2f Mon Sep 17 00:00:00 2001 From: clux Date: Sat, 19 Oct 2024 16:57:08 +0100 Subject: [PATCH 2/5] Convert examples/ to use kube::k8s re-exports Signed-off-by: clux --- examples/cert_check.rs | 8 +++----- examples/configmapgen_controller.rs | 2 +- examples/crd_api.rs | 2 +- examples/crd_apply.rs | 4 +--- examples/crd_derive.rs | 2 +- examples/crd_derive_multi.rs | 2 +- examples/crd_derive_no_schema.rs | 6 ++---- examples/crd_derive_schema.rs | 2 +- examples/crd_reflector.rs | 2 +- examples/custom_client.rs | 3 +-- examples/custom_client_tls.rs | 3 +-- examples/custom_client_trace.rs | 3 +-- examples/dynamic_jsonpath.rs | 2 +- examples/dynamic_pod.rs | 10 +++++----- examples/errorbounded_configmap_watcher.rs | 2 +- examples/event_watcher.rs | 7 ++----- examples/job_api.rs | 2 +- examples/kubectl.rs | 3 ++- examples/log_stream.rs | 9 +++------ examples/multi_watcher.rs | 11 +++++------ examples/node_reflector.rs | 5 ++--- examples/node_watcher.rs | 2 +- examples/pod_api.rs | 5 ++--- examples/pod_attach.rs | 10 ++++------ examples/pod_cp.rs | 2 +- examples/pod_evict.rs | 5 ++--- examples/pod_exec.rs | 10 ++++------ examples/pod_log_kubelet_debug.rs | 2 +- examples/pod_paged.rs | 5 ++--- examples/pod_portforward.rs | 2 +- examples/pod_portforward_bind.rs | 2 +- examples/pod_portforward_hyper_http.rs | 2 +- examples/pod_reflector.rs | 5 ++--- examples/pod_shell.rs | 5 ++--- examples/pod_shell_crossterm.rs | 5 ++--- examples/pod_watcher.rs | 5 ++--- examples/request_raw.rs | 7 +++++-- examples/secret_reflector.rs | 5 ++--- examples/secret_syncer.rs | 2 +- examples/shared_stream_controllers.rs | 2 +- 40 files changed, 74 insertions(+), 99 deletions(-) diff --git a/examples/cert_check.rs b/examples/cert_check.rs index 99295d225..8c08c6b0e 100644 --- a/examples/cert_check.rs +++ b/examples/cert_check.rs @@ -1,12 +1,10 @@ use std::borrow::Cow; -use k8s_openapi::{ - api::core::v1::{ConfigMap, Namespace as Ns}, - NamespaceResourceScope, -}; use kube::{ api::ObjectMeta, client::scope::{Cluster, Namespace}, + core::NamespaceResourceScope, + k8s::corev1::{ConfigMap, Namespace as Ns}, Client, Resource, }; use serde::{Deserialize, Serialize}; @@ -20,7 +18,7 @@ struct CaConfigMapData { ca_crt: String, } -// Method 1 :: inherit resource implementation from k8s_openapi's ConfigMap +// Method 1 :: inherit resource implementation from the official ConfigMap #[derive(Resource, Serialize, Deserialize, Debug, Clone)] #[resource(inherit = ConfigMap)] struct CaConfigMap { diff --git a/examples/configmapgen_controller.rs b/examples/configmapgen_controller.rs index 41b1ad1e4..3312cbbef 100644 --- a/examples/configmapgen_controller.rs +++ b/examples/configmapgen_controller.rs @@ -3,9 +3,9 @@ use anyhow::Result; use futures::StreamExt; -use k8s_openapi::api::core::v1::ConfigMap; use kube::{ api::{Api, ObjectMeta, Patch, PatchParams, Resource}, + k8s::corev1::ConfigMap, runtime::{ controller::{Action, Config, Controller}, watcher, diff --git a/examples/crd_api.rs b/examples/crd_api.rs index dfbd52e7e..d3e393b66 100644 --- a/examples/crd_api.rs +++ b/examples/crd_api.rs @@ -8,10 +8,10 @@ use std::time::Duration; use tokio::time::sleep; use tracing::*; -use k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceDefinition; use kube::{ api::{Api, DeleteParams, ListParams, Patch, PatchParams, PostParams, ResourceExt}, core::crd::CustomResourceExt, + k8s::apiextensionsv1::CustomResourceDefinition, Client, CustomResource, }; diff --git a/examples/crd_apply.rs b/examples/crd_apply.rs index eae7d49fe..5c889ad6e 100644 --- a/examples/crd_apply.rs +++ b/examples/crd_apply.rs @@ -4,11 +4,9 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use tracing::*; -use apiexts::CustomResourceDefinition; -use k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1 as apiexts; - use kube::{ api::{Api, Patch, PatchParams, ResourceExt}, + k8s::apiextensionsv1::CustomResourceDefinition, runtime::wait::{await_condition, conditions}, Client, CustomResource, CustomResourceExt, }; diff --git a/examples/crd_derive.rs b/examples/crd_derive.rs index 4aace0193..d41faeeb4 100644 --- a/examples/crd_derive.rs +++ b/examples/crd_derive.rs @@ -1,6 +1,6 @@ -use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition; use kube::{ core::object::{HasSpec, HasStatus}, + k8s::metav1::Condition, CustomResource, CustomResourceExt, Resource, }; use schemars::JsonSchema; diff --git a/examples/crd_derive_multi.rs b/examples/crd_derive_multi.rs index f96342cc0..7ecb1ee1c 100644 --- a/examples/crd_derive_multi.rs +++ b/examples/crd_derive_multi.rs @@ -1,7 +1,7 @@ -use k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceDefinition; use kube::{ api::{Api, Patch, PatchParams}, core::crd::merge_crds, + k8s::apiextensionsv1::CustomResourceDefinition, runtime::wait::{await_condition, conditions}, Client, CustomResource, CustomResourceExt, ResourceExt, }; diff --git a/examples/crd_derive_no_schema.rs b/examples/crd_derive_no_schema.rs index d3d6cece4..de6019378 100644 --- a/examples/crd_derive_no_schema.rs +++ b/examples/crd_derive_no_schema.rs @@ -1,7 +1,5 @@ -use k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1::{ - CustomResourceDefinition, CustomResourceValidation, JSONSchemaProps, -}; -use kube_derive::CustomResource; +use apiext::{CustomResourceDefinition, CustomResourceValidation, JSONSchemaProps}; +use kube::{k8s::apiextensionsv1 as apiext, CustomResource}; use serde::{Deserialize, Serialize}; /// CustomResource with manually implemented schema diff --git a/examples/crd_derive_schema.rs b/examples/crd_derive_schema.rs index 8c58afacb..2c784cc6d 100644 --- a/examples/crd_derive_schema.rs +++ b/examples/crd_derive_schema.rs @@ -1,11 +1,11 @@ use anyhow::{anyhow, Result}; use futures::{StreamExt, TryStreamExt}; -use k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceDefinition; use kube::{ api::{ Api, ApiResource, DeleteParams, DynamicObject, GroupVersionKind, Patch, PatchParams, PostParams, WatchEvent, WatchParams, }, + k8s::apiextensionsv1::CustomResourceDefinition, runtime::wait::{await_condition, conditions}, Client, CustomResource, CustomResourceExt, }; diff --git a/examples/crd_reflector.rs b/examples/crd_reflector.rs index f01fb9165..a573a2b8d 100644 --- a/examples/crd_reflector.rs +++ b/examples/crd_reflector.rs @@ -1,9 +1,9 @@ use futures::{StreamExt, TryStreamExt}; -use k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceDefinition; use tracing::*; use kube::{ api::{Api, Patch, PatchParams, ResourceExt}, + k8s::apiextensionsv1::CustomResourceDefinition, runtime::{reflector, watcher, WatchStreamExt}, Client, CustomResource, CustomResourceExt, }; diff --git a/examples/custom_client.rs b/examples/custom_client.rs index 0b61a8810..e2ce3b71d 100644 --- a/examples/custom_client.rs +++ b/examples/custom_client.rs @@ -1,6 +1,5 @@ use hyper_util::rt::TokioExecutor; // Minimal custom client example. -use k8s_openapi::api::core::v1::Pod; use tower::BoxError; use tracing::*; @@ -20,7 +19,7 @@ async fn main() -> anyhow::Result<()> { .service(hyper_util::client::legacy::Client::builder(TokioExecutor::new()).build(https)); let client = Client::new(service, config.default_namespace); - let pods: Api = Api::default_namespaced(client); + let pods: Api = Api::default_namespaced(client); for p in pods.list(&Default::default()).await? { info!("{}", p.name_any()); } diff --git a/examples/custom_client_tls.rs b/examples/custom_client_tls.rs index 5b271e04f..58a278ba8 100644 --- a/examples/custom_client_tls.rs +++ b/examples/custom_client_tls.rs @@ -2,7 +2,6 @@ use hyper_util::rt::TokioExecutor; // Custom client supporting both openssl-tls and rustls-tls // Must enable `rustls-tls` feature to run this. // Run with `USE_RUSTLS=1` to pick rustls. -use k8s_openapi::api::core::v1::Pod; use tower::ServiceBuilder; use tracing::*; @@ -32,7 +31,7 @@ async fn main() -> anyhow::Result<()> { Client::new(service, config.default_namespace) }; - let pods: Api = Api::default_namespaced(client); + let pods: Api = Api::default_namespaced(client); for p in pods.list(&Default::default()).await? { info!("{}", p.name_any()); } diff --git a/examples/custom_client_trace.rs b/examples/custom_client_trace.rs index 25cb1aa6c..a55fb93d5 100644 --- a/examples/custom_client_trace.rs +++ b/examples/custom_client_trace.rs @@ -2,7 +2,6 @@ use http::{Request, Response}; use hyper::body::Incoming; use hyper_util::rt::TokioExecutor; -use k8s_openapi::api::core::v1::Pod; use std::time::Duration; use tower::{BoxError, ServiceBuilder}; use tower_http::{decompression::DecompressionLayer, trace::TraceLayer}; @@ -59,7 +58,7 @@ async fn main() -> anyhow::Result<()> { let client = Client::new(service, config.default_namespace); - let pods: Api = Api::default_namespaced(client); + let pods: Api = Api::default_namespaced(client); for p in pods.list(&Default::default()).await? { info!("{}", p.name_any()); } diff --git a/examples/dynamic_jsonpath.rs b/examples/dynamic_jsonpath.rs index 3fb670b84..ddae8fe5c 100644 --- a/examples/dynamic_jsonpath.rs +++ b/examples/dynamic_jsonpath.rs @@ -1,8 +1,8 @@ use anyhow::{Context, Error}; use jsonpath_rust::JsonPathInst; -use k8s_openapi::api::core::v1::Pod; use kube::{ api::{Api, ListParams}, + k8s::corev1::Pod, Client, }; use tracing::*; diff --git a/examples/dynamic_pod.rs b/examples/dynamic_pod.rs index 80d3556be..e67704ad3 100644 --- a/examples/dynamic_pod.rs +++ b/examples/dynamic_pod.rs @@ -1,6 +1,6 @@ use kube::{ api::{Api, ApiResource, NotUsed, Object, ResourceExt}, - Client, + k8s::corev1::Pod, }; use serde::Deserialize; use tracing::*; @@ -8,9 +8,9 @@ use tracing::*; #[tokio::main] async fn main() -> anyhow::Result<()> { tracing_subscriber::fmt::init(); - let client = Client::try_default().await?; + let client = kube::Client::try_default().await?; - // Here we replace heavy type k8s_openapi::api::core::v1::PodSpec with + // A slimmed down k8s::corev1::PodSpec #[derive(Clone, Deserialize, Debug)] struct PodSpecSimple { containers: Vec, @@ -22,8 +22,8 @@ async fn main() -> anyhow::Result<()> { } type PodSimple = Object; - // Here we simply steal the type info from k8s_openapi, but we could create this from scratch. - let ar = ApiResource::erase::(&()); + // Steal the type info, to avoid hand-typing / using discovery. + let ar = ApiResource::erase::(&()); let pods: Api = Api::default_namespaced_with(client, &ar); for p in pods.list(&Default::default()).await? { diff --git a/examples/errorbounded_configmap_watcher.rs b/examples/errorbounded_configmap_watcher.rs index db9e69830..6dda859eb 100644 --- a/examples/errorbounded_configmap_watcher.rs +++ b/examples/errorbounded_configmap_watcher.rs @@ -1,8 +1,8 @@ use futures::prelude::*; -use k8s_openapi::api::core::v1::ConfigMap; use kube::{ api::{Api, ObjectMeta}, core::DeserializeGuard, + k8s::corev1::ConfigMap, runtime::{reflector::ObjectRef, watcher, WatchStreamExt}, Client, Resource, }; diff --git a/examples/event_watcher.rs b/examples/event_watcher.rs index e6df87c2e..bd202dfcf 100644 --- a/examples/event_watcher.rs +++ b/examples/event_watcher.rs @@ -1,12 +1,9 @@ use std::pin::pin; use futures::TryStreamExt; -use k8s_openapi::{ - api::{core::v1::ObjectReference, events::v1::Event}, - apimachinery::pkg::apis::meta::v1::Time, - chrono::Utc, -}; +use k8s_openapi::chrono::Utc; use kube::{ + k8s::{corev1::ObjectReference, eventsv1::Event, metav1::Time}, runtime::{watcher, WatchStreamExt}, Api, Client, ResourceExt, }; diff --git a/examples/job_api.rs b/examples/job_api.rs index 6e980217e..17704cb51 100644 --- a/examples/job_api.rs +++ b/examples/job_api.rs @@ -1,6 +1,6 @@ -use k8s_openapi::api::batch::v1::Job; use kube::{ api::{Api, DeleteParams, PostParams}, + k8s::batchv1::Job, runtime::wait::{await_condition, conditions}, Client, }; diff --git a/examples/kubectl.rs b/examples/kubectl.rs index 2dcb3aa60..2a38eda28 100644 --- a/examples/kubectl.rs +++ b/examples/kubectl.rs @@ -3,11 +3,12 @@ //! with labels and namespace selectors supported. use anyhow::{bail, Context, Result}; use futures::{StreamExt, TryStreamExt}; -use k8s_openapi::{apimachinery::pkg::apis::meta::v1::Time, chrono::Utc}; +use k8s_openapi::chrono::Utc; use kube::{ api::{Api, DynamicObject, ListParams, Patch, PatchParams, ResourceExt}, core::GroupVersionKind, discovery::{ApiCapabilities, ApiResource, Discovery, Scope}, + k8s::metav1::Time, runtime::{ wait::{await_condition, conditions::is_deleted}, watcher, WatchStreamExt, diff --git a/examples/log_stream.rs b/examples/log_stream.rs index d78047202..2bc3b31d7 100644 --- a/examples/log_stream.rs +++ b/examples/log_stream.rs @@ -1,11 +1,8 @@ use futures::{AsyncBufReadExt, TryStreamExt}; -use k8s_openapi::{ - api::core::v1::Pod, - chrono::{DateTime, Utc}, -}; +use k8s_openapi::chrono::{DateTime, Utc}; use kube::{ api::{Api, LogParams}, - Client, + k8s::corev1::Pod, }; use tracing::*; @@ -39,7 +36,7 @@ struct App { async fn main() -> anyhow::Result<()> { tracing_subscriber::fmt::init(); let app: App = clap::Parser::parse(); - let client = Client::try_default().await?; + let client = kube::Client::try_default().await?; info!("Fetching logs for {:?}", app.pod); let pods: Api = Api::default_namespaced(client); diff --git a/examples/multi_watcher.rs b/examples/multi_watcher.rs index 9311a24ae..a85a2dd50 100644 --- a/examples/multi_watcher.rs +++ b/examples/multi_watcher.rs @@ -1,19 +1,18 @@ use futures::{stream, StreamExt, TryStreamExt}; -use k8s_openapi::api::{ - apps::v1::Deployment, - core::v1::{ConfigMap, Secret}, -}; use kube::{ api::{Api, ResourceExt}, + k8s::{ + appsv1::Deployment, + corev1::{ConfigMap, Secret}, + }, runtime::{watcher, WatchStreamExt}, - Client, }; use tracing::*; #[tokio::main] async fn main() -> anyhow::Result<()> { tracing_subscriber::fmt::init(); - let client = Client::try_default().await?; + let client = kube::Client::try_default().await?; let deploys: Api = Api::default_namespaced(client.clone()); let cms: Api = Api::default_namespaced(client.clone()); diff --git a/examples/node_reflector.rs b/examples/node_reflector.rs index 6859d8749..3c4ac3869 100644 --- a/examples/node_reflector.rs +++ b/examples/node_reflector.rs @@ -1,18 +1,17 @@ use std::pin::pin; use futures::TryStreamExt; -use k8s_openapi::api::core::v1::Node; use kube::{ api::{Api, ResourceExt}, + k8s::corev1::Node, runtime::{predicates, reflector, watcher, Predicate, WatchStreamExt}, - Client, }; use tracing::*; #[tokio::main] async fn main() -> anyhow::Result<()> { tracing_subscriber::fmt::init(); - let client = Client::try_default().await?; + let client = kube::Client::try_default().await?; let nodes: Api = Api::all(client.clone()); let wc = watcher::Config::default() diff --git a/examples/node_watcher.rs b/examples/node_watcher.rs index 4ed4c0d2e..dc0fdcb55 100644 --- a/examples/node_watcher.rs +++ b/examples/node_watcher.rs @@ -1,10 +1,10 @@ use std::pin::pin; use futures::TryStreamExt; -use k8s_openapi::api::core::v1::{Event, Node}; use kube::{ api::{Api, ListParams, ResourceExt}, client::{scope, Client}, + k8s::corev1::{Event, Node}, runtime::{watcher, WatchStreamExt}, }; use tracing::*; diff --git a/examples/pod_api.rs b/examples/pod_api.rs index b7c3db67e..908051eae 100644 --- a/examples/pod_api.rs +++ b/examples/pod_api.rs @@ -1,17 +1,16 @@ -use k8s_openapi::api::core::v1::Pod; use serde_json::json; use tracing::*; use kube::{ api::{Api, DeleteParams, ListParams, Patch, PatchParams, PostParams, ResourceExt}, + k8s::corev1::Pod, runtime::wait::{await_condition, conditions::is_pod_running}, - Client, }; #[tokio::main] async fn main() -> anyhow::Result<()> { tracing_subscriber::fmt::init(); - let client = Client::try_default().await?; + let client = kube::Client::try_default().await?; // Manage pods let pods: Api = Api::default_namespaced(client); diff --git a/examples/pod_attach.rs b/examples/pod_attach.rs index cb23b52d4..25ccadcb7 100644 --- a/examples/pod_attach.rs +++ b/examples/pod_attach.rs @@ -2,19 +2,17 @@ use std::io::Write; use tracing::*; use futures::{join, stream, StreamExt, TryStreamExt}; -use k8s_openapi::api::core::v1::Pod; use kube::{ - api::{ - Api, AttachParams, AttachedProcess, DeleteParams, PostParams, ResourceExt, WatchEvent, WatchParams, - }, - Client, + api::{AttachParams, AttachedProcess, DeleteParams, PostParams, WatchEvent, WatchParams}, + k8s::corev1::Pod, + Api, ResourceExt, }; #[tokio::main] async fn main() -> anyhow::Result<()> { tracing_subscriber::fmt::init(); - let client = Client::try_default().await?; + let client = kube::Client::try_default().await?; info!("Creating a Pod that outputs numbers for 15s"); let p: Pod = serde_json::from_value(serde_json::json!({ diff --git a/examples/pod_cp.rs b/examples/pod_cp.rs index ee3bed75e..7b4d4b1ce 100644 --- a/examples/pod_cp.rs +++ b/examples/pod_cp.rs @@ -1,5 +1,5 @@ use futures::{StreamExt, TryStreamExt}; -use k8s_openapi::api::core::v1::Pod; +use kube::k8s::corev1::Pod; use tracing::*; use kube::{ diff --git a/examples/pod_evict.rs b/examples/pod_evict.rs index 02be47fc1..2897cf9e3 100644 --- a/examples/pod_evict.rs +++ b/examples/pod_evict.rs @@ -1,17 +1,16 @@ use futures::{StreamExt, TryStreamExt}; -use k8s_openapi::api::core::v1::Pod; use serde_json::json; use tracing::*; use kube::{ api::{Api, EvictParams, PostParams, ResourceExt, WatchEvent, WatchParams}, - Client, + k8s::corev1::Pod, }; #[tokio::main] async fn main() -> anyhow::Result<()> { tracing_subscriber::fmt::init(); - let client = Client::try_default().await?; + let client = kube::Client::try_default().await?; // Create a Job let pod_name = "empty-pod"; diff --git a/examples/pod_exec.rs b/examples/pod_exec.rs index a671cbb01..7a868f3f8 100644 --- a/examples/pod_exec.rs +++ b/examples/pod_exec.rs @@ -1,19 +1,17 @@ use futures::{StreamExt, TryStreamExt}; -use k8s_openapi::api::core::v1::Pod; use tracing::*; use kube::{ - api::{ - Api, AttachParams, AttachedProcess, DeleteParams, PostParams, ResourceExt, WatchEvent, WatchParams, - }, - Client, + api::{Api, AttachParams, AttachedProcess, DeleteParams, PostParams, WatchEvent, WatchParams}, + k8s::corev1::Pod, + ResourceExt, }; use tokio::io::AsyncWriteExt; #[tokio::main] async fn main() -> anyhow::Result<()> { tracing_subscriber::fmt::init(); - let client = Client::try_default().await?; + let client = kube::Client::try_default().await?; let p: Pod = serde_json::from_value(serde_json::json!({ "apiVersion": "v1", diff --git a/examples/pod_log_kubelet_debug.rs b/examples/pod_log_kubelet_debug.rs index 3925dabb9..1a4349835 100644 --- a/examples/pod_log_kubelet_debug.rs +++ b/examples/pod_log_kubelet_debug.rs @@ -1,5 +1,4 @@ use futures::TryStreamExt; -use k8s_openapi::api::core::v1::Pod; use tracing::*; use futures::AsyncBufReadExt; @@ -7,6 +6,7 @@ use hyper::Uri; use kube::{ api::{Api, DeleteParams, ResourceExt}, core::{kubelet_debug::KubeletDebugParams, subresource::LogParams}, + k8s::corev1::Pod, Client, Config, }; use serde_json::json; diff --git a/examples/pod_paged.rs b/examples/pod_paged.rs index 1f5107ac2..12ae7acf9 100644 --- a/examples/pod_paged.rs +++ b/examples/pod_paged.rs @@ -1,7 +1,6 @@ -use k8s_openapi::api::core::v1::Pod; use kube::{ api::{Api, ListParams, ResourceExt}, - Client, + k8s::corev1::Pod, }; use tracing::*; @@ -14,7 +13,7 @@ const PAGE_SIZE: u32 = 5; #[tokio::main] async fn main() -> anyhow::Result<()> { tracing_subscriber::fmt::init(); - let client = Client::try_default().await?; + let client = kube::Client::try_default().await?; let api = Api::::default_namespaced(client); let mut continue_token: Option = None; diff --git a/examples/pod_portforward.rs b/examples/pod_portforward.rs index c4e751ce8..77238ecd7 100644 --- a/examples/pod_portforward.rs +++ b/examples/pod_portforward.rs @@ -1,9 +1,9 @@ use futures::StreamExt; -use k8s_openapi::api::core::v1::Pod; use tracing::*; use kube::{ api::{Api, DeleteParams, PostParams}, + k8s::corev1::Pod, runtime::wait::{await_condition, conditions::is_pod_running}, Client, ResourceExt, }; diff --git a/examples/pod_portforward_bind.rs b/examples/pod_portforward_bind.rs index e950a14d9..b8ff39e2e 100644 --- a/examples/pod_portforward_bind.rs +++ b/examples/pod_portforward_bind.rs @@ -10,9 +10,9 @@ use tokio::{ use tokio_stream::wrappers::TcpListenerStream; use tracing::*; -use k8s_openapi::api::core::v1::Pod; use kube::{ api::{Api, DeleteParams, PostParams}, + k8s::corev1::Pod, runtime::wait::{await_condition, conditions::is_pod_running}, Client, ResourceExt, }; diff --git a/examples/pod_portforward_hyper_http.rs b/examples/pod_portforward_hyper_http.rs index 64cf9aa1f..64bca1b3c 100644 --- a/examples/pod_portforward_hyper_http.rs +++ b/examples/pod_portforward_hyper_http.rs @@ -1,8 +1,8 @@ use bytes::Bytes; use hyper_util::rt::TokioIo; -use k8s_openapi::api::core::v1::Pod; use kube::{ api::{Api, DeleteParams, PostParams}, + k8s::corev1::Pod, runtime::wait::{await_condition, conditions::is_pod_running}, Client, ResourceExt, }; diff --git a/examples/pod_reflector.rs b/examples/pod_reflector.rs index 21a564c56..358982eeb 100644 --- a/examples/pod_reflector.rs +++ b/examples/pod_reflector.rs @@ -1,11 +1,10 @@ use std::pin::pin; use futures::TryStreamExt; -use k8s_openapi::api::core::v1::Pod; use kube::{ - api::Api, + k8s::corev1::Pod, runtime::{predicates, reflector, watcher, WatchStreamExt}, - Client, ResourceExt, + Api, Client, ResourceExt, }; use tracing::*; diff --git a/examples/pod_shell.rs b/examples/pod_shell.rs index 3f7a3e79a..a32ba7222 100644 --- a/examples/pod_shell.rs +++ b/examples/pod_shell.rs @@ -1,16 +1,15 @@ use futures::{StreamExt, TryStreamExt}; -use k8s_openapi::api::core::v1::Pod; use tracing::*; use kube::{ api::{Api, AttachParams, DeleteParams, PostParams, ResourceExt, WatchEvent, WatchParams}, - Client, + k8s::corev1::Pod, }; #[tokio::main] async fn main() -> anyhow::Result<()> { tracing_subscriber::fmt::init(); - let client = Client::try_default().await?; + let client = kube::Client::try_default().await?; let p: Pod = serde_json::from_value(serde_json::json!({ "apiVersion": "v1", diff --git a/examples/pod_shell_crossterm.rs b/examples/pod_shell_crossterm.rs index 4283603db..eaac47577 100644 --- a/examples/pod_shell_crossterm.rs +++ b/examples/pod_shell_crossterm.rs @@ -1,10 +1,9 @@ use futures::{channel::mpsc::Sender, SinkExt, StreamExt}; -use k8s_openapi::api::core::v1::Pod; use kube::{ api::{Api, AttachParams, AttachedProcess, DeleteParams, PostParams, ResourceExt, TerminalSize}, + k8s::corev1::Pod, runtime::wait::{await_condition, conditions::is_pod_running}, - Client, }; #[cfg(unix)] use tokio::signal; use tokio::{io::AsyncWriteExt, select}; @@ -39,7 +38,7 @@ async fn handle_terminal_size(mut channel: Sender) -> Result<(), a #[tokio::main] async fn main() -> anyhow::Result<()> { - let client = Client::try_default().await?; + let client = kube::Client::try_default().await?; let pods: Api = Api::default_namespaced(client); let p: Pod = serde_json::from_value(serde_json::json!({ diff --git a/examples/pod_watcher.rs b/examples/pod_watcher.rs index 7a1f2dcc0..985e7b23f 100644 --- a/examples/pod_watcher.rs +++ b/examples/pod_watcher.rs @@ -1,16 +1,15 @@ use futures::prelude::*; -use k8s_openapi::api::core::v1::Pod; use kube::{ api::{Api, ResourceExt}, + k8s::corev1::Pod, runtime::{watcher, WatchStreamExt}, - Client, }; use tracing::*; #[tokio::main] async fn main() -> anyhow::Result<()> { tracing_subscriber::fmt::init(); - let client = Client::try_default().await?; + let client = kube::Client::try_default().await?; let api = Api::::default_namespaced(client); let use_watchlist = std::env::var("WATCHLIST").map(|s| s == "1").unwrap_or(false); let wc = if use_watchlist { diff --git a/examples/request_raw.rs b/examples/request_raw.rs index 7a534ff74..6c72c9b50 100644 --- a/examples/request_raw.rs +++ b/examples/request_raw.rs @@ -6,8 +6,11 @@ //! By default, node summary metrics data is fetched by Kubernetes from the //! kubelet. The kubelet itself supports statistics access through CRI, or //! through cAdvisor. -use k8s_openapi::{api::core::v1::Node, apimachinery::pkg::api::resource::Quantity}; -use kube::{api::ListParams, Api, ResourceExt}; +use kube::{ + api::ListParams, + k8s::{apimachinery::pkg::api::resource::Quantity, corev1::Node}, + Api, ResourceExt, +}; use serde::Deserialize; #[tokio::main] diff --git a/examples/secret_reflector.rs b/examples/secret_reflector.rs index ac46998e9..e7fc85431 100644 --- a/examples/secret_reflector.rs +++ b/examples/secret_reflector.rs @@ -1,9 +1,8 @@ use futures::TryStreamExt; -use k8s_openapi::api::core::v1::Secret; use kube::{ api::{Api, ResourceExt}, + k8s::corev1::Secret, runtime::{reflector, reflector::Store, watcher, WatchStreamExt}, - Client, }; use std::collections::BTreeMap; use tracing::*; @@ -51,7 +50,7 @@ fn spawn_periodic_reader(reader: Store) { #[tokio::main] async fn main() -> anyhow::Result<()> { tracing_subscriber::fmt::init(); - let client = Client::try_default().await?; + let client = kube::Client::try_default().await?; let secrets: Api = Api::default_namespaced(client); let wc = watcher::Config::default().timeout(10); // short watch timeout in this example diff --git a/examples/secret_syncer.rs b/examples/secret_syncer.rs index 889a89680..39b8ff96a 100644 --- a/examples/secret_syncer.rs +++ b/examples/secret_syncer.rs @@ -4,10 +4,10 @@ // If you actually want to clean up other Kubernetes objects then you should use `ownerReferences` instead and let // k8s garbage collect the children. use futures::StreamExt; -use k8s_openapi::api::core::v1::{ConfigMap, Secret}; use kube::{ api::{Api, DeleteParams, ObjectMeta, Patch, PatchParams, Resource}, error::ErrorResponse, + k8s::corev1::{ConfigMap, Secret}, runtime::{ controller::{Action, Controller}, finalizer::{finalizer, Event}, diff --git a/examples/shared_stream_controllers.rs b/examples/shared_stream_controllers.rs index f8ff276d6..2f123b674 100644 --- a/examples/shared_stream_controllers.rs +++ b/examples/shared_stream_controllers.rs @@ -1,8 +1,8 @@ use std::{ops::Deref, sync::Arc, time::Duration}; use futures::{future, StreamExt}; -use k8s_openapi::api::{apps::v1::Deployment, core::v1::Pod}; use kube::{ + k8s::{appsv1::Deployment, corev1::Pod}, runtime::{ controller::Action, predicates, From 37d1f4e0074309219b14b401e4db6955687cea45 Mon Sep 17 00:00:00 2001 From: clux Date: Sat, 19 Oct 2024 17:02:07 +0100 Subject: [PATCH 3/5] account for msrv Signed-off-by: clux --- kube-core/src/k8s.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kube-core/src/k8s.rs b/kube-core/src/k8s.rs index 1138aca34..1b4b90aa7 100644 --- a/kube-core/src/k8s.rs +++ b/kube-core/src/k8s.rs @@ -19,7 +19,6 @@ pub use { api::core::v1 as corev1, api::discovery::v1 as discoveryv1, api::events::v1 as eventsv1, - api::flowcontrol::v1 as flowcontrolv1, api::networking::v1 as networkingv1, api::node::v1 as nodev1, api::policy::v1 as policyv1, @@ -29,3 +28,8 @@ pub use { apiextensions_apiserver::pkg::apis::apiextensions::v1 as apiextensionsv1, apimachinery::pkg::apis::meta::v1 as metav1, }; + +// Names with version gates +k8s_openapi::k8s_if_ge_1_26! { + pub use api::flowcontrol::v1 as flowcontrolv1; +} From 3cce769ad1ebc65585180a8c309d808ff6703601 Mon Sep 17 00:00:00 2001 From: clux Date: Sat, 19 Oct 2024 17:41:22 +0100 Subject: [PATCH 4/5] only re-export the sub modules to avoid double exports the double exports makes rustdoc not display it properly. this works. adding a png Signed-off-by: clux --- examples/request_raw.rs | 7 ++----- kube-core/src/crd.rs | 4 +--- kube-core/src/k8s.rs | 11 ++++++----- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/examples/request_raw.rs b/examples/request_raw.rs index 6c72c9b50..e2ff65147 100644 --- a/examples/request_raw.rs +++ b/examples/request_raw.rs @@ -6,11 +6,8 @@ //! By default, node summary metrics data is fetched by Kubernetes from the //! kubelet. The kubelet itself supports statistics access through CRI, or //! through cAdvisor. -use kube::{ - api::ListParams, - k8s::{apimachinery::pkg::api::resource::Quantity, corev1::Node}, - Api, ResourceExt, -}; +use k8s_openapi::apimachinery::pkg::api::resource::Quantity; +use kube::{api::ListParams, k8s::corev1::Node, Api, ResourceExt}; use serde::Deserialize; #[tokio::main] diff --git a/kube-core/src/crd.rs b/kube-core/src/crd.rs index f48ac476d..f4c67107b 100644 --- a/kube-core/src/crd.rs +++ b/kube-core/src/crd.rs @@ -1,10 +1,8 @@ //! Traits and tyes for CustomResources -use crate::k8s::apiextensions_apiserver::pkg::apis::apiextensions as apiexts; - /// Types for v1 CustomResourceDefinitions pub mod v1 { - use super::apiexts::v1::CustomResourceDefinition as Crd; + use crate::k8s::apiextensionsv1::CustomResourceDefinition as Crd; /// Extension trait that is implemented by kube-derive pub trait CustomResourceExt { /// Helper to generate the CRD including the JsonSchema diff --git a/kube-core/src/k8s.rs b/kube-core/src/k8s.rs index 1b4b90aa7..ef50e6af5 100644 --- a/kube-core/src/k8s.rs +++ b/kube-core/src/k8s.rs @@ -1,12 +1,13 @@ -//! Indirection layer for generated structs for easier imports +//! Flat indirection layer of stable apis for generated structs +//! +//! These are exclusively the generated **modules** found in [`k8s-openapi`](https://docs.rs/k8s_openapi). +#![allow(unused_imports)] -/// Re-export k8s-openapi root modules -pub use k8s_openapi::{api, apiextensions_apiserver, apimachinery}; /// Re-export versioned stable modules as the client-go like equivalent names /// /// Names should generally match https://pkg.go.dev/k8s.io/client-go/kubernetes/typed #[rustfmt::skip] -pub use { +pub use k8s_openapi::{ api::admissionregistration::v1 as admissionregistrationv1, api::apps::v1 as appsv1, api::authentication::v1 as authenticationv1, @@ -31,5 +32,5 @@ pub use { // Names with version gates k8s_openapi::k8s_if_ge_1_26! { - pub use api::flowcontrol::v1 as flowcontrolv1; + pub use k8s_openapi::api::flowcontrol::v1 as flowcontrolv1; } From 6e1dfb4e2519e6633821c393c64db57fda9ec742 Mon Sep 17 00:00:00 2001 From: clux Date: Sat, 19 Oct 2024 17:48:33 +0100 Subject: [PATCH 5/5] flowcontrol only became stable in 1_29 Signed-off-by: clux --- kube-core/src/k8s.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kube-core/src/k8s.rs b/kube-core/src/k8s.rs index ef50e6af5..d26b898ac 100644 --- a/kube-core/src/k8s.rs +++ b/kube-core/src/k8s.rs @@ -31,6 +31,6 @@ pub use k8s_openapi::{ }; // Names with version gates -k8s_openapi::k8s_if_ge_1_26! { +k8s_openapi::k8s_if_ge_1_29! { pub use k8s_openapi::api::flowcontrol::v1 as flowcontrolv1; }