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

create a client feature in kube #525 #528

Merged
merged 21 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from 18 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: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ jobs:
- run: cargo test --doc --all -j4
- run: cargo test -j4 -p examples
- run: cd examples && cargo build --examples
- run: cd examples && cargo test --example crd_derive_no_schema --no-default-features --features=native-tls
- run: cd kube && cargo test --lib --no-default-features --features=rustls-tls,ws,oauth
- run: cd kube && cargo test --lib --no-default-features --features=native-tls,ws,oauth
- run: cd examples && cargo test --example crd_derive_no_schema --no-default-features --features=native-tls,client
- run: cd kube && cargo test --lib --no-default-features --features=rustls-tls,ws,oauth,client
- run: cd kube && cargo test --lib --no-default-features --features=native-tls,ws,oauth,client
- save_cache:
paths:
- /usr/local/cargo/registry
Expand Down Expand Up @@ -139,7 +139,7 @@ jobs:
- run: cargo test --lib --all -j4
- run: cargo test --doc --all -j4
- run: cargo test -j4 -p examples
- run: cd kube && cargo test --lib --no-default-features --features=rustls-tls
- run: cd kube && cargo test --lib --no-default-features --features=rustls-tls,client
- save_cache:
paths:
- "$HOME/.cargo/registry"
Expand Down
7 changes: 3 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
UNRELEASED
===================
* see /~https://github.com/clux/kube-rs/compare/0.54.0...master

0.54.0 / 2021-05-18
===================
* `kube`: `client` feature added (default-enabled) - #528
* `kube`: `PatchParams` force now only works with `Patch::Apply` #528
* `kube`: `api` `discovery` module now uses a new `ApiResource` struct [#495](/~https://github.com/clux/kube-rs/issues/495)
* `kube`: `api` BREAKING: `DynamicObject` now takes an `ApiResource` rather than a `GroupVersionKind`
* `kube`: `api` BREAKING: `discovery` module's `Group` renamed to `ApiGroup`
* `kube-core` crate factored out of `kube` to reduce dependencies - [#516](/~https://github.com/clux/kube-rs/issues/516) via [#517](/~https://github.com/clux/kube-rs/issues/517) + [#519](/~https://github.com/clux/kube-rs/issues/519) + [#522](/~https://github.com/clux/kube-rs/issues/522)
* `kube-core` crate factored out of `kube` to reduce dependencies - [#516](/~https://github.com/clux/kube-rs/issues/516) via [#517](/~https://github.com/clux/kube-rs/issues/517) + [#519](/~https://github.com/clux/kube-rs/issues/519) + [#522](/~https://github.com/clux/kube-rs/issues/522) and #528

0.53.0 / 2021-05-15
===================
Expand Down
13 changes: 2 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,13 @@ doc:
test:
cargo test --all
cargo test --lib --all -- --ignored # also run tests that fail on circleci
cd kube && cargo test --lib --features=rustls-tls --no-default-features
cd kube && cargo test --lib --features=rustls-tls,client --no-default-features
cd kube && cargo test --lib --no-default-features
cd kube && cargo test --lib --features=derive

readme:
rustdoc README.md --test --edition=2018

minikube-create:
sudo rm -rf /tmp/juju-mk* /tmp/minikube*
minikube start --driver=docker \
--kubernetes-version v1.20.2 \
--extra-config kubeadm.ignore-preflight-errors=SystemVerification

minikube:
kubectl config set-context --cluster=minikube --user=minikube --namespace=apps minikube
kubectl create namespace apps

kind-create:
kind create cluster

Expand Down
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 @@ publish = false
edition = "2018"

[features]
default = ["native-tls", "schema", "kubederive", "ws"]
default = ["native-tls", "schema", "kubederive", "ws", "client"]
kubederive = ["kube/derive"] # by default import kube-derive with its default features
schema = ["kube-derive/schema"] # crd_derive_no_schema shows how to opt out
native-tls = ["kube/native-tls", "kube-runtime/native-tls"]
rustls-tls = ["kube/rustls-tls", "kube-runtime/rustls-tls"]
ws = ["kube/ws"]
client = ["kube/client"]

[dev-dependencies]
anyhow = "1.0.37"
Expand Down
2 changes: 1 addition & 1 deletion examples/admission_controller.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use kube_core::{
use kube::core::{
admission::{AdmissionRequest, AdmissionResponse, AdmissionReview},
DynamicObject, ResourceExt,
};
Expand Down
2 changes: 1 addition & 1 deletion kube-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ readme = "../README.md"
[features]
ws = []
admission = ["json-patch"]
jsonpatch = ["json-patch"]

[dependencies]
serde = { version = "1.0.118", features = ["derive"] }
serde_json = "1.0.61"
thiserror = "1.0.23"
once_cell = "1.7.2"
url = "2.2.0"
log = "0.4.11"
http = "0.2.2"
json-patch = { version = "0.2.6", optional = true }

Expand Down
5 changes: 2 additions & 3 deletions kube-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ pub use request::Request;
mod resource;
pub use resource::{Resource, ResourceExt};

pub mod subresource;

#[macro_use] extern crate log;
pub mod response;

pub mod subresource;

mod error;
pub use error::{Error, ErrorResponse};
Expand Down
4 changes: 3 additions & 1 deletion kube-core/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@ impl PatchParams {
}
}
if self.force && !patch.is_apply() {
warn!("PatchParams::force only works with Patch::Apply");
return Err(Error::RequestValidation(
"PatchParams::force only works with Patch::Apply".into(),
));
}
Ok(())
}
Expand Down
69 changes: 69 additions & 0 deletions kube-core/src/response.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
use serde::Deserialize;
// TODO: replace with Status in k8s openapi?

/// A Kubernetes status object
#[allow(missing_docs)]
#[derive(Deserialize, Debug)]
pub struct Status {
// TODO: typemeta
// TODO: metadata that can be completely empty (listmeta...)
#[serde(default, skip_serializing_if = "String::is_empty")]
pub status: String,
#[serde(default, skip_serializing_if = "String::is_empty")]
pub message: String,
#[serde(default, skip_serializing_if = "String::is_empty")]
pub reason: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub details: Option<StatusDetails>,
#[serde(default, skip_serializing_if = "num::Zero::is_zero")]
pub code: u16,
}

/// Status details object on the [`Status`] object
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
#[allow(missing_docs)]
pub struct StatusDetails {
#[serde(default, skip_serializing_if = "String::is_empty")]
pub name: String,
#[serde(default, skip_serializing_if = "String::is_empty")]
pub group: String,
#[serde(default, skip_serializing_if = "String::is_empty")]
pub kind: String,
#[serde(default, skip_serializing_if = "String::is_empty")]
pub uid: String,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub causes: Vec<StatusCause>,
#[serde(default, skip_serializing_if = "num::Zero::is_zero")]
pub retry_after_seconds: u32,
}

/// Status cause object on the [`StatusDetails`] object
#[derive(Deserialize, Debug)]
#[allow(missing_docs)]
pub struct StatusCause {
#[serde(default, skip_serializing_if = "String::is_empty")]
pub reason: String,
#[serde(default, skip_serializing_if = "String::is_empty")]
pub message: String,
#[serde(default, skip_serializing_if = "String::is_empty")]
pub field: String,
}


#[cfg(test)]
mod test {
use super::Status;

// ensure our status schema is sensible
#[test]
fn delete_deserialize_test() {
let statusresp = r#"{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Success","details":{"name":"some-app","group":"clux.dev","kind":"foos","uid":"1234-some-uid"}}"#;
let s: Status = serde_json::from_str::<Status>(statusresp).unwrap();
assert_eq!(s.details.unwrap().name, "some-app");

let statusnoname = r#"{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Success","details":{"group":"clux.dev","kind":"foos","uid":"1234-some-uid"}}"#;
let s2: Status = serde_json::from_str::<Status>(statusnoname).unwrap();
assert_eq!(s2.details.unwrap().name, ""); // optional probably better..
}
}
2 changes: 1 addition & 1 deletion kube-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ schema = []
[dev-dependencies]
serde = { version = "1.0.118", features = ["derive"] }
serde_yaml = "0.8.17"
kube-core = { path = "../kube-core" }
kube = { path = "../kube", default-features = false }
k8s-openapi = { version = "0.11.0", default-features = false, features = ["v1_20"] }
schemars = { version = "0.8.0", features = ["chrono"] }
chrono = "0.4.19"
Expand Down
14 changes: 7 additions & 7 deletions kube-derive/src/custom_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea
impl #rootident {
pub fn new(name: &str, spec: #ident) -> Self {
Self {
api_version: <#rootident as kube_core::Resource>::api_version(&()).to_string(),
kind: <#rootident as kube_core::Resource>::kind(&()).to_string(),
api_version: <#rootident as kube::Resource>::api_version(&()).to_string(),
kind: <#rootident as kube::Resource>::kind(&()).to_string(),
metadata: k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta {
name: Some(name.to_string()),
..Default::default()
Expand All @@ -184,7 +184,7 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea

let api_ver = format!("{}/{}", group, version);
let impl_resource = quote! {
impl kube_core::Resource for #rootident {
impl kube::Resource for #rootident {
type DynamicType = ();

fn group(_: &()) -> std::borrow::Cow<'_, str> {
Expand Down Expand Up @@ -223,8 +223,8 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea
impl Default for #rootident {
fn default() -> Self {
Self {
api_version: <#rootident as kube_core::Resource>::api_version(&()).to_string(),
kind: <#rootident as kube_core::Resource>::kind(&()).to_string(),
api_version: <#rootident as kube::Resource>::api_version(&()).to_string(),
kind: <#rootident as kube::Resource>::kind(&()).to_string(),
metadata: k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta::default(),
spec: Default::default(),
#statusdef
Expand Down Expand Up @@ -358,8 +358,8 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea
.expect("valid custom resource from #[kube(attrs..)]")
}

pub fn api_resource() -> kube_core::api_resource::ApiResource {
kube_core::api_resource::ApiResource::erase::<Self>(&())
pub fn api_resource() -> kube::core::ApiResource {
kube::core::ApiResource::erase::<Self>(&())
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion kube-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mod custom_resource;
///
/// ```rust
/// use serde::{Serialize, Deserialize};
/// use kube_core::Resource;
/// use kube::Resource;
/// use kube_derive::CustomResource;
/// use schemars::JsonSchema;
///
Expand Down
2 changes: 1 addition & 1 deletion kube-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ edition = "2018"

[dependencies]
futures = "0.3.8"
kube = { path = "../kube", version = "^0.54.0", default-features = false }
kube = { path = "../kube", version = "^0.54.0", default-features = false, features = ["client"] }
derivative = "2.1.1"
serde = "1.0.118"
smallvec = "1.6.0"
Expand Down
55 changes: 29 additions & 26 deletions kube/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,56 +17,59 @@ edition = "2018"

[features]
default = ["native-tls"]
native-tls = ["openssl", "hyper-tls", "tokio-native-tls"]
rustls-tls = ["hyper-rustls", "tokio-rustls"]
native-tls = ["client", "openssl", "hyper-tls", "tokio-native-tls"]
rustls-tls = ["client", "hyper-rustls", "tokio-rustls"]
ws = ["client", "tokio-tungstenite", "rand", "kube-core/ws"]
oauth = ["client", "tame-oauth"]
gzip = ["client", "async-compression"]
client = ["__config", "__non_core", "hyper", "tower", "hyper-timeout", "pin-project", "chrono", "jsonpath_lib", "bytes", "futures", "tokio", "tokio-util", "either"]
jsonpatch = ["kube-core/jsonpatch"]
admission = ["kube-core/admission"]
derive = ["kube-derive"]
jsonpatch = ["json-patch"]
ws = ["tokio-tungstenite", "rand", "kube-core/ws"]
oauth = ["tame-oauth"]
gzip = ["async-compression"]
admission = ["json-patch", "kube-core/admission"]

# private feature sets; do not use
__config = ["pem", "dirs"]
__non_core = ["tracing", "serde_yaml", "base64"]

[package.metadata.docs.rs]
features = ["derive", "ws", "oauth", "jsonpatch"]
features = ["derive", "client", "ws", "oauth", "jsonpatch", "admission"]
# Define the configuration attribute `docsrs`. Used to enable `doc_cfg` feature.
rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
base64 = "0.13.0"
chrono = "0.4.19"
dirs = { package = "dirs-next", version = "2.0.0" }
base64 = { version = "0.13.0", optional = true }
chrono = { version = "0.4.19", optional = true }
dirs = { package = "dirs-next", optional = true, version = "2.0.0" }
serde = { version = "1.0.118", features = ["derive"] }
serde_json = "1.0.61"
serde_yaml = "0.8.17"
serde_yaml = { version = "0.8.17", optional = true }
http = "0.2.2"
url = "2.2.0"
log = "0.4.11"
either = "1.6.1"
either = { version = "1.6.1", optional = true }
thiserror = "1.0.23"
futures = "0.3.8"
pem = "0.8.2"
futures = { version = "0.3.8", optional = true }
pem = { version = "0.8.2", optional = true }
openssl = { version = "0.10.32", optional = true }
tokio-native-tls = { version = "0.3.0", optional = true }
tokio-rustls = { version = "0.22.0", features = ["dangerous_configuration"], optional = true }
bytes = "1.0.0"
tokio = { version = "1.0.1", features = ["time", "signal", "sync"] }
bytes = { version = "1.0.0", optional = true }
tokio = { version = "1.0.1", features = ["time", "signal", "sync"], optional = true }
static_assertions = "1.1.0"
kube-derive = { path = "../kube-derive", version = "^0.54.0", optional = true }
kube-core = { path = "../kube-core", version = "^0.54.0"}
jsonpath_lib = "0.2.6"
tokio-util = { version = "0.6.0", features = ["io", "codec"] }
json-patch = { version = "0.2.6", optional = true }
hyper = { version = "0.14.2", features = ["client", "http1", "stream", "tcp"] }
jsonpath_lib = { version = "0.2.6", optional = true }
tokio-util = { version = "0.6.0", optional = true, features = ["io", "codec"] }
hyper = { version = "0.14.2", optional = true, features = ["client", "http1", "stream", "tcp"] }
hyper-tls = { version = "0.5.0", optional = true }
hyper-rustls = { version = "0.22.1", optional = true }
tokio-tungstenite = { version = "0.14.0", optional = true }
tower = { version = "0.4.6", features = ["buffer", "util"] }
tower = { version = "0.4.6", optional = true, features = ["buffer", "util"] }
async-compression = { version = "0.3.7", features = ["gzip", "tokio"], optional = true }
hyper-timeout = "0.4.1"
hyper-timeout = {version = "0.4.1", optional = true }
tame-oauth = { version = "0.4.7", features = ["gcp"], optional = true }
pin-project = "1.0.4"
pin-project = { version = "1.0.4", optional = true }
rand = { version = "0.8.3", optional = true }
tracing = "0.1.25"
tracing = { version = "0.1.25", features = ["log"], optional = true }

[dependencies.k8s-openapi]
version = "0.11.0"
Expand Down
4 changes: 2 additions & 2 deletions kube/src/api/core_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use serde::{de::DeserializeOwned, Serialize};
use std::fmt::Debug;
use tracing::instrument;

use crate::{api::Api, client::Status, Result};
use kube_core::{object::ObjectList, params::*, WatchEvent};
use crate::{api::Api, Result};
use kube_core::{object::ObjectList, params::*, response::Status, WatchEvent};

/// PUSH/PUT/POST/GET abstractions
impl<K> Api<K>
Expand Down
2 changes: 1 addition & 1 deletion kube/src/api/subresource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use tracing::instrument;

use crate::{
api::{Api, Patch, PatchParams, PostParams},
client::Status,
Result,
};

use kube_core::response::Status;
pub use kube_core::subresource::{EvictParams, LogParams};

#[cfg(feature = "ws")] pub use kube_core::subresource::AttachParams;
Expand Down
Loading