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

Try to integrate k8s-pb #1602

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
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
18 changes: 5 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ jobs:
run: cargo build

- name: Build no-features
run: cargo build -p kube --no-default-features
run: cargo build -p kube --no-default-features --features=openapi
if: matrix.os == 'ubuntu-latest' # only linux tests all feature combinations
- name: Build no-tls
run: cargo build -p kube --no-default-features --features=client
run: cargo build -p kube --no-default-features --features=client,openapi
if: matrix.os == 'ubuntu-latest' # only linux tests all feature combinations

# Workspace unit tests with various feature sets
Expand Down Expand Up @@ -96,7 +96,7 @@ jobs:
# Run `cargo check` on our minimum supported Rust version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- uses: actions/checkout@v4
- name: Find MSRV
id: msrv
run: |
Expand Down Expand Up @@ -143,11 +143,7 @@ jobs:
k8s: [v1.26, v1.30]
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
override: true
toolchain: stable
profile: minimal
- uses: dtolnay/rust-toolchain@stable
# Smart caching for Rust projects.
# Includes workaround for macos cache corruption.
# - https://github.com/rust-lang/cargo/issues/8603
Expand Down Expand Up @@ -201,11 +197,7 @@ jobs:
exit 1
fi

- uses: actions-rs/toolchain@v1
with:
override: true
toolchain: stable
profile: minimal
- uses: dtolnay/rust-toolchain@stable
# Smart caching for Rust projects.
# Includes workaround for macos cache corruption.
# - https://github.com/rust-lang/cargo/issues/8603
Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ json-patch = "3"
jsonptr = "0.6"
jsonpath-rust = "0.5.0"
k8s-openapi = { version = "0.23.0", default-features = false }
k8s-pb = "0.6.1"
#k8s-pb = { path = "../k8s-pb/k8s-pb" }
openssl = "0.10.36"
parking_lot = "0.12.0"
pem = "3.0.1"
Expand Down
4 changes: 4 additions & 0 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ name = "base64"
# newer via tower-http (we have latest)
name = "bitflags"

[[bans.skip]]
# different versions deep done in prost vs aws-lc
name = "itertools"

[[bans.skip-tree]]
name = "windows-sys"

Expand Down
2 changes: 1 addition & 1 deletion e2e/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ openssl = ["kube/openssl-tls"]
anyhow.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
kube = { path = "../kube", version = "^0.96.0", default-features = false, features = ["client", "runtime", "ws", "admission", "gzip"] }
kube = { path = "../kube", version = "^0.96.0", default-features = false, features = ["client", "runtime", "ws", "admission", "gzip", "openapi"] }
k8s-openapi.workspace = true
serde_json.workspace = true
tokio = { workspace = true, features = ["full"] }
3 changes: 2 additions & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ license.workspace = true
release = false

[features]
default = ["rustls-tls", "kubederive", "ws", "latest", "socks5", "runtime", "refresh"]
default = ["rustls-tls", "kubederive", "ws", "latest", "socks5", "runtime", "refresh", "openapi"]
kubederive = ["kube/derive"]
openssl-tls = ["kube/client", "kube/openssl-tls", "kube/unstable-client"]
rustls-tls = ["kube/client", "kube/rustls-tls", "kube/unstable-client"]
runtime = ["kube/runtime", "kube/unstable-runtime"]
socks5 = ["kube/socks5"]
openapi = ["kube/openapi"]
refresh = ["kube/oauth", "kube/oidc"]
kubelet-debug = ["kube/kubelet-debug"]
ws = ["kube/ws"]
Expand Down
4 changes: 2 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ How deriving `CustomResource` works in practice, and how it interacts with the [
cargo run --example crd_api
cargo run --example crd_derive
cargo run --example crd_derive_schema
cargo run --example crd_derive_no_schema --no-default-features --features=openssl-tls,latest
cargo run --example crd_derive_no_schema --no-default-features --features=openssl-tls,openapi,latest
cargo run --example cert_check # showcases partial typing with Resource derive
```

Expand Down Expand Up @@ -143,5 +143,5 @@ The `crd_reflector` will just await changes. You can run `kubectl apply -f crd-b
Disable default features and enable `openssl-tls`:

```sh
cargo run --example pod_watcher --no-default-features --features=openssl-tls,latest,runtime
cargo run --example pod_watcher --no-default-features --features=openssl-tls,openapi,latest,runtime
```
5 changes: 4 additions & 1 deletion kube-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ oauth = ["client", "tame-oauth"]
oidc = ["client", "form_urlencoded"]
gzip = ["client", "tower-http/decompression-gzip"]
client = ["config", "__non_core", "hyper", "hyper-util", "http-body", "http-body-util", "tower", "tower-http", "hyper-timeout", "chrono", "jsonpath-rust", "bytes", "futures", "tokio", "tokio-util", "either"]
openapi = ["k8s-openapi", "kube-core/openapi"]
pb = ["k8s-pb", "kube-core/pb"]
jsonpatch = ["kube-core/jsonpatch"]
admission = ["kube-core/admission"]
config = ["__non_core", "pem", "home"]
Expand Down Expand Up @@ -78,7 +80,8 @@ secrecy = { workspace = true }
tracing = { workspace = true, features = ["log"], optional = true }
hyper-openssl = { workspace = true, features = ["client-legacy"], optional = true }
form_urlencoded = { workspace = true, optional = true }
k8s-openapi= { workspace = true, features = [] }
k8s-openapi = { workspace = true, optional = true, features = [] }
k8s-pb = { workspace = true, optional = true }

[dev-dependencies]
kube = { path = "../kube", features = ["derive", "client", "ws"], version = "<1.0.0, >=0.61.0" }
Expand Down
13 changes: 6 additions & 7 deletions kube-client/src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
//! API helpers for structured interaction with the Kubernetes API

mod core_methods;
#[cfg(feature = "openapi")] mod core_methods;
#[cfg(feature = "ws")] mod remote_command;
use std::fmt::Debug;

#[cfg(feature = "ws")] pub use remote_command::{AttachedProcess, TerminalSize};
#[cfg(feature = "ws")] mod portforward;
#[cfg(feature = "ws")] pub use portforward::Portforwarder;

mod subresource;
#[cfg(feature = "ws")]
#[cfg(feature = "openapi")] mod subresource;
#[cfg(all(feature = "ws", feature = "openapi"))]
#[cfg_attr(docsrs, doc(cfg(feature = "ws")))]
pub use subresource::{Attach, AttachParams, Ephemeral, Execute, Portforward};
#[cfg(feature = "openapi")]
pub use subresource::{Evict, EvictParams, Log, LogParams, ScaleSpec, ScaleStatus};

mod util;
#[cfg(feature = "openapi")] mod util;

pub mod entry;

Expand Down Expand Up @@ -247,8 +247,7 @@ impl<K> Debug for Api<K> {
/// Sanity test on scope restrictions
#[cfg(test)]
mod test {
use crate::{client::Body, Api, Client};
use k8s_openapi::api::core::v1 as corev1;
use crate::{client::Body, core::k8s::api::core::v1 as corev1, Api, Client};

use http::{Request, Response};
use tower_test::mock;
Expand Down
34 changes: 17 additions & 17 deletions kube-client/src/api/subresource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub use kube_core::subresource::{EvictParams, LogParams};
#[cfg_attr(docsrs, doc(cfg(feature = "ws")))]
pub use kube_core::subresource::AttachParams;

pub use k8s_openapi::api::autoscaling::v1::{Scale, ScaleSpec, ScaleStatus};
pub use kube_core::k8s::api::autoscaling::v1::{Scale, ScaleSpec, ScaleStatus};

#[cfg(feature = "ws")] use crate::api::portforward::Portforwarder;
#[cfg(feature = "ws")] use crate::api::remote_command::AttachedProcess;
Expand Down Expand Up @@ -136,7 +136,7 @@ where
/// See [`Api::get_ephemeral_containers`] et al.
pub trait Ephemeral {}

impl Ephemeral for k8s_openapi::api::core::v1::Pod {}
impl Ephemeral for kube_core::k8s::api::core::v1::Pod {}

impl<K> Api<K>
where
Expand All @@ -160,7 +160,7 @@ where
/// Example of using `replace_ephemeral_containers`:
///
/// ```no_run
/// use k8s_openapi::api::core::v1::Pod;
/// use kube_core::k8s::api::core::v1::Pod;
/// use kube::{Api, api::PostParams};
/// # async fn wrapper() -> Result<(), Box<dyn std::error::Error>> {
/// # let client = kube::Client::try_default().await?;
Expand Down Expand Up @@ -229,7 +229,7 @@ where
///
/// ```no_run
/// use kube::api::{Api, PatchParams, Patch};
/// use k8s_openapi::api::core::v1::Pod;
/// use kube_core::k8s::api::core::v1::Pod;
/// # async fn wrapper() -> Result<(), Box<dyn std::error::Error>> {
/// # let client = kube::Client::try_default().await?;
/// let pods: Api<Pod> = Api::namespaced(client, "apps");
Expand Down Expand Up @@ -310,7 +310,7 @@ where
///
/// ```no_run
/// use kube::api::{Api, PatchParams, Patch};
/// use k8s_openapi::api::batch::v1::Job;
/// use kube_core::k8s::api::batch::v1::Job;
/// # async fn wrapper() -> Result<(), Box<dyn std::error::Error>> {
/// # let client = kube::Client::try_default().await?;
/// let jobs: Api<Job> = Api::namespaced(client, "apps");
Expand Down Expand Up @@ -347,7 +347,7 @@ where
///
/// ```no_run
/// use kube::api::{Api, PostParams};
/// use k8s_openapi::api::batch::v1::{Job, JobStatus};
/// use kube_core::k8s::api::batch::v1::{Job, JobStatus};
/// # async fn wrapper() -> Result<(), Box<dyn std::error::Error>> {
/// # let client = kube::Client::try_default().await?;
/// let jobs: Api<Job> = Api::namespaced(client, "apps");
Expand Down Expand Up @@ -375,7 +375,7 @@ where
#[test]
fn log_path() {
use crate::api::{Request, Resource};
use k8s_openapi::api::core::v1 as corev1;
use kube_core::k8s::api::core::v1 as corev1;
let lp = LogParams {
container: Some("blah".into()),
..LogParams::default()
Expand All @@ -390,7 +390,7 @@ fn log_path() {
/// See [`Api::logs`] and [`Api::log_stream`] for usage.
pub trait Log {}

impl Log for k8s_openapi::api::core::v1::Pod {}
impl Log for kube_core::k8s::api::core::v1::Pod {}

impl<K> Api<K>
where
Expand All @@ -412,7 +412,7 @@ where
///
/// ```no_run
/// # async fn wrapper() -> Result<(), Box<dyn std::error::Error>> {
/// # use k8s_openapi::api::core::v1::Pod;
/// # use kube_core::k8s::api::core::v1::Pod;
/// # use kube::{api::{Api, LogParams}, Client};
/// # let client: Client = todo!();
/// use futures::{AsyncBufReadExt, TryStreamExt};
Expand Down Expand Up @@ -442,7 +442,7 @@ where
#[test]
fn evict_path() {
use crate::api::{Request, Resource};
use k8s_openapi::api::core::v1 as corev1;
use kube_core::k8s::api::core::v1 as corev1;
let ep = EvictParams::default();
let url = corev1::Pod::url_path(&(), Some("ns"));
let req = Request::new(url).evict("foo", &ep).unwrap();
Expand All @@ -454,7 +454,7 @@ fn evict_path() {
/// See [`Api::evic`] for usage
pub trait Evict {}

impl Evict for k8s_openapi::api::core::v1::Pod {}
impl Evict for kube_core::k8s::api::core::v1::Pod {}

impl<K> Api<K>
where
Expand All @@ -476,7 +476,7 @@ where
#[test]
fn attach_path() {
use crate::api::{Request, Resource};
use k8s_openapi::api::core::v1 as corev1;
use kube_core::k8s::api::core::v1 as corev1;
let ap = AttachParams {
container: Some("blah".into()),
..AttachParams::default()
Expand All @@ -498,7 +498,7 @@ pub trait Attach {}

#[cfg(feature = "ws")]
#[cfg_attr(docsrs, doc(cfg(feature = "ws")))]
impl Attach for k8s_openapi::api::core::v1::Pod {}
impl Attach for kube_core::k8s::api::core::v1::Pod {}

#[cfg(feature = "ws")]
#[cfg_attr(docsrs, doc(cfg(feature = "ws")))]
Expand All @@ -522,7 +522,7 @@ where
#[test]
fn exec_path() {
use crate::api::{Request, Resource};
use k8s_openapi::api::core::v1 as corev1;
use kube_core::k8s::api::core::v1 as corev1;
let ap = AttachParams {
container: Some("blah".into()),
..AttachParams::default()
Expand All @@ -546,7 +546,7 @@ pub trait Execute {}

#[cfg(feature = "ws")]
#[cfg_attr(docsrs, doc(cfg(feature = "ws")))]
impl Execute for k8s_openapi::api::core::v1::Pod {}
impl Execute for kube_core::k8s::api::core::v1::Pod {}

#[cfg(feature = "ws")]
#[cfg_attr(docsrs, doc(cfg(feature = "ws")))]
Expand Down Expand Up @@ -577,7 +577,7 @@ where
#[test]
fn portforward_path() {
use crate::api::{Request, Resource};
use k8s_openapi::api::core::v1 as corev1;
use kube_core::k8s::api::core::v1 as corev1;
let url = corev1::Pod::url_path(&(), Some("ns"));
let req = Request::new(url).portforward("foo", &[80, 1234]).unwrap();
assert_eq!(
Expand All @@ -593,7 +593,7 @@ fn portforward_path() {
pub trait Portforward {}

#[cfg(feature = "ws")]
impl Portforward for k8s_openapi::api::core::v1::Pod {}
impl Portforward for kube_core::k8s::api::core::v1::Pod {}

#[cfg(feature = "ws")]
impl<K> Api<K>
Expand Down
7 changes: 4 additions & 3 deletions kube-client/src/api/util/csr.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::{api::Api, Error, Result};
use k8s_openapi::api::certificates::v1::CertificateSigningRequest;
use kube_core::params::{Patch, PatchParams};

use kube_core::{
k8s::api::certificates::v1::CertificateSigningRequest,
params::{Patch, PatchParams},
};

impl Api<CertificateSigningRequest> {
/// Partially update approval of the specified CertificateSigningRequest.
Expand Down
13 changes: 8 additions & 5 deletions kube-client/src/api/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ use crate::{
api::{Api, Resource},
Error, Result,
};
use k8s_openapi::api::{
authentication::v1::TokenRequest,
core::v1::{Node, ServiceAccount},
use kube_core::{
k8s::api::{
authentication::v1::TokenRequest,
core::v1::{Node, ServiceAccount},
},
params::PostParams,
util::Restart,
};
use kube_core::{params::PostParams, util::Restart};
use serde::de::DeserializeOwned;

mod csr;
Expand Down Expand Up @@ -66,7 +69,7 @@ mod test {
api::{Api, DeleteParams, ListParams, PostParams},
Client,
};
use k8s_openapi::api::{
use kube_core::k8s::api::{
authentication::v1::{TokenRequest, TokenRequestSpec, TokenReview, TokenReviewSpec},
core::v1::{Node, ServiceAccount},
};
Expand Down
8 changes: 5 additions & 3 deletions kube-client/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
//!
//! The [`Client`] can also be used with [`Discovery`](crate::Discovery) to dynamically
//! retrieve the resources served by the kubernetes API.
use apimachinery::pkg::apis::meta::v1 as k8s_meta_v1;
use either::{Either, Left, Right};
use futures::{future::BoxFuture, AsyncBufRead, StreamExt, TryStream, TryStreamExt};
use http::{self, Request, Response};
use http_body_util::BodyExt;
#[cfg(feature = "ws")] use hyper_util::rt::TokioIo;
use k8s_openapi::apimachinery::pkg::apis::meta::v1 as k8s_meta_v1;
use kube_core::k8s::apimachinery;
pub use kube_core::response::Status;
use serde::de::DeserializeOwned;
use serde_json::{self, Value};
Expand Down Expand Up @@ -372,7 +373,8 @@ impl Client {
/// The following methods might be deprecated to avoid confusion between similarly named types within `discovery`.
impl Client {
/// Returns apiserver version.
pub async fn apiserver_version(&self) -> Result<k8s_openapi::apimachinery::pkg::version::Info> {
#[cfg(feature = "openapi")] // Info struct does not exist for pbs
pub async fn apiserver_version(&self) -> Result<apimachinery::pkg::version::Info> {
self.request(
Request::builder()
.uri("/version")
Expand Down Expand Up @@ -497,8 +499,8 @@ mod tests {

use crate::{client::Body, Api, Client};

use crate::core::k8s::api::core::v1::Pod;
use http::{Request, Response};
use k8s_openapi::api::core::v1::Pod;
use tower_test::mock;

#[tokio::test]
Expand Down
Loading
Loading