Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a kube::k8s re-export module for stable apis #1613

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions examples/cert_check.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion examples/configmapgen_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion examples/crd_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
4 changes: 1 addition & 3 deletions examples/crd_apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
2 changes: 1 addition & 1 deletion examples/crd_derive.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion examples/crd_derive_multi.rs
Original file line number Diff line number Diff line change
@@ -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,
};
Expand Down
6 changes: 2 additions & 4 deletions examples/crd_derive_no_schema.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/crd_derive_schema.rs
Original file line number Diff line number Diff line change
@@ -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,
};
Expand Down
2 changes: 1 addition & 1 deletion examples/crd_reflector.rs
Original file line number Diff line number Diff line change
@@ -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,
};
Expand Down
3 changes: 1 addition & 2 deletions examples/custom_client.rs
Original file line number Diff line number Diff line change
@@ -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::*;

Expand All @@ -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<Pod> = Api::default_namespaced(client);
let pods: Api<kube::k8s::corev1::Pod> = Api::default_namespaced(client);
for p in pods.list(&Default::default()).await? {
info!("{}", p.name_any());
}
Expand Down
3 changes: 1 addition & 2 deletions examples/custom_client_tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand Down Expand Up @@ -32,7 +31,7 @@ async fn main() -> anyhow::Result<()> {
Client::new(service, config.default_namespace)
};

let pods: Api<Pod> = Api::default_namespaced(client);
let pods: Api<kube::k8s::corev1::Pod> = Api::default_namespaced(client);
for p in pods.list(&Default::default()).await? {
info!("{}", p.name_any());
}
Expand Down
3 changes: 1 addition & 2 deletions examples/custom_client_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -59,7 +58,7 @@ async fn main() -> anyhow::Result<()> {

let client = Client::new(service, config.default_namespace);

let pods: Api<Pod> = Api::default_namespaced(client);
let pods: Api<kube::k8s::corev1::Pod> = Api::default_namespaced(client);
for p in pods.list(&Default::default()).await? {
info!("{}", p.name_any());
}
Expand Down
2 changes: 1 addition & 1 deletion examples/dynamic_jsonpath.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand Down
10 changes: 5 additions & 5 deletions examples/dynamic_pod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use kube::{
api::{Api, ApiResource, NotUsed, Object, ResourceExt},
Client,
k8s::corev1::Pod,
};
use serde::Deserialize;
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<ContainerSimple>,
Expand All @@ -22,8 +22,8 @@ async fn main() -> anyhow::Result<()> {
}
type PodSimple = Object<PodSpecSimple, NotUsed>;

// Here we simply steal the type info from k8s_openapi, but we could create this from scratch.
let ar = ApiResource::erase::<k8s_openapi::api::core::v1::Pod>(&());
// Steal the type info, to avoid hand-typing / using discovery.
let ar = ApiResource::erase::<Pod>(&());

let pods: Api<PodSimple> = Api::default_namespaced_with(client, &ar);
for p in pods.list(&Default::default()).await? {
Expand Down
2 changes: 1 addition & 1 deletion examples/errorbounded_configmap_watcher.rs
Original file line number Diff line number Diff line change
@@ -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,
};
Expand Down
7 changes: 2 additions & 5 deletions examples/event_watcher.rs
Original file line number Diff line number Diff line change
@@ -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,
};
Expand Down
2 changes: 1 addition & 1 deletion examples/job_api.rs
Original file line number Diff line number Diff line change
@@ -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,
};
Expand Down
3 changes: 2 additions & 1 deletion examples/kubectl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 3 additions & 6 deletions examples/log_stream.rs
Original file line number Diff line number Diff line change
@@ -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::*;

Expand Down Expand Up @@ -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<Pod> = Api::default_namespaced(client);
Expand Down
11 changes: 5 additions & 6 deletions examples/multi_watcher.rs
Original file line number Diff line number Diff line change
@@ -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<Deployment> = Api::default_namespaced(client.clone());
let cms: Api<ConfigMap> = Api::default_namespaced(client.clone());
Expand Down
5 changes: 2 additions & 3 deletions examples/node_reflector.rs
Original file line number Diff line number Diff line change
@@ -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<Node> = Api::all(client.clone());
let wc = watcher::Config::default()
Expand Down
2 changes: 1 addition & 1 deletion examples/node_watcher.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand Down
5 changes: 2 additions & 3 deletions examples/pod_api.rs
Original file line number Diff line number Diff line change
@@ -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<Pod> = Api::default_namespaced(client);
Expand Down
10 changes: 4 additions & 6 deletions examples/pod_attach.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!({
Expand Down
2 changes: 1 addition & 1 deletion examples/pod_cp.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use futures::{StreamExt, TryStreamExt};
use k8s_openapi::api::core::v1::Pod;
use kube::k8s::corev1::Pod;
use tracing::*;

use kube::{
Expand Down
Loading
Loading