From d1ce4eb5e1d88c88e1d5f1fd551563dbb2e94c35 Mon Sep 17 00:00:00 2001 From: clux Date: Sun, 5 Dec 2021 00:15:29 +0000 Subject: [PATCH 01/18] code coverage improvement testing Signed-off-by: clux --- .github/workflows/coverage.yml | 44 ++++++++++++++++++++++++++++++++++ .github/workflows/release.yml | 22 ----------------- 2 files changed, 44 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/coverage.yml diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 000000000..cef7c307d --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,44 @@ +name: Coverage + +on: + push: + #branches: + # - master + +jobs: + rust: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - uses: Swatinem/rust-cache@v1 + - uses: AbsaOSS/k3d-action@v1.4.0 + name: "Create Single Cluster" + with: + cluster-name: "test-cluster-1" + args: >- + -p "8083:80@agent[0]" + -p "8443:443@agent[0]" + -p "5053:53/udp@agent[0]" + --agents 1 + --no-lb + --image docker.io/rancher/k3s:v1.20.4-k3s1 + --k3s-server-arg "--disable=traefik,servicelb,metrics-server,local-storage" + --k3s-server-arg "--disable-cloud-controller" + - name: Run cargo-tarpaulin + uses: actions-rs/tarpaulin@v0.1 + with: + version: '0.18.5' + #out-type: Lcov + timeout: 600 + args: '--all -e tests -- --test-threads 1' + - name: Coveralls Finished + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + path-to-lcov: ./lcov.info diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b9749b327..f773c3e11 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,25 +19,3 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: body_path: release.txt - code-coverage: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Install stable toolchain - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - - name: Run cargo-tarpaulin - uses: actions-rs/tarpaulin@v0.1 - with: - version: '0.18.0' - out-type: Lcov - timeout: 600 - args: '--all -e tests -- --test-threads 1' - - name: Coveralls Finished - uses: coverallsapp/github-action@master - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - path-to-lcov: ./lcov.info From e34d8e4a536688b8846fdc2720088ab4cd3dfbef Mon Sep 17 00:00:00 2001 From: clux Date: Sun, 5 Dec 2021 00:17:31 +0000 Subject: [PATCH 02/18] codecov action Signed-off-by: clux --- .github/workflows/coverage.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index cef7c307d..1fc051b34 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -34,11 +34,14 @@ jobs: uses: actions-rs/tarpaulin@v0.1 with: version: '0.18.5' - #out-type: Lcov + out-type: Xml timeout: 600 args: '--all -e tests -- --test-threads 1' - - name: Coveralls Finished - uses: coverallsapp/github-action@master + #- name: Coveralls Finished + # uses: coverallsapp/github-action@master + # with: + # github-token: ${{ secrets.GITHUB_TOKEN }} + # path-to-lcov: ./lcov.info + - uses: codecov/codecov-action@v2 with: - github-token: ${{ secrets.GITHUB_TOKEN }} - path-to-lcov: ./lcov.info + flags: unittests,rust From c18e092233c47f56bd18782a3569c2696475de3f Mon Sep 17 00:00:00 2001 From: clux Date: Sun, 5 Dec 2021 00:28:01 +0000 Subject: [PATCH 03/18] try newer k3d action Signed-off-by: clux --- .github/workflows/coverage.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 1fc051b34..9f1e76c08 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -17,19 +17,18 @@ jobs: toolchain: stable override: true - uses: Swatinem/rust-cache@v1 - - uses: AbsaOSS/k3d-action@v1.4.0 + - uses: AbsaOSS/k3d-action@v2 name: "Create Single Cluster" with: cluster-name: "test-cluster-1" args: >- - -p "8083:80@agent[0]" - -p "8443:443@agent[0]" - -p "5053:53/udp@agent[0]" + -p "8083:80@agent:0:direct" + -p "8443:443@agent:0:direct" + -p "5053:53/udp@agent:0:direct" --agents 1 --no-lb --image docker.io/rancher/k3s:v1.20.4-k3s1 - --k3s-server-arg "--disable=traefik,servicelb,metrics-server,local-storage" - --k3s-server-arg "--disable-cloud-controller" + --k3s-arg "--no-deploy=traefik,servicelb,metrics-server@server:*" - name: Run cargo-tarpaulin uses: actions-rs/tarpaulin@v0.1 with: From db1964728b748de189a4d5706e830c9c5f326876 Mon Sep 17 00:00:00 2001 From: clux Date: Sun, 5 Dec 2021 00:36:07 +0000 Subject: [PATCH 04/18] wtf Signed-off-by: clux --- .github/workflows/coverage.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 9f1e76c08..da14788ff 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -22,13 +22,11 @@ jobs: with: cluster-name: "test-cluster-1" args: >- - -p "8083:80@agent:0:direct" - -p "8443:443@agent:0:direct" - -p "5053:53/udp@agent:0:direct" --agents 1 - --no-lb - --image docker.io/rancher/k3s:v1.20.4-k3s1 + --image docker.io/rancher/k3s:v1.22.4-k3s1 --k3s-arg "--no-deploy=traefik,servicelb,metrics-server@server:*" + + #--no-lb - name: Run cargo-tarpaulin uses: actions-rs/tarpaulin@v0.1 with: From f3270bc39a49532a3101bd3581b6c6ab8df3aff6 Mon Sep 17 00:00:00 2001 From: clux Date: Sun, 5 Dec 2021 11:22:07 +0000 Subject: [PATCH 05/18] get coverage running above 55 still not getting all the results i want because some ignored tests are not running Signed-off-by: clux --- .github/workflows/coverage.yml | 9 +--- Makefile | 2 +- kube-derive/src/lib.rs | 2 + kube/src/lib.rs | 83 ++++++++++++++++++++++++++++------ 4 files changed, 72 insertions(+), 24 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index da14788ff..2dcb75fc6 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -25,20 +25,13 @@ jobs: --agents 1 --image docker.io/rancher/k3s:v1.22.4-k3s1 --k3s-arg "--no-deploy=traefik,servicelb,metrics-server@server:*" - - #--no-lb - name: Run cargo-tarpaulin uses: actions-rs/tarpaulin@v0.1 with: version: '0.18.5' out-type: Xml timeout: 600 - args: '--all -e tests -- --test-threads 1' - #- name: Coveralls Finished - # uses: coverallsapp/github-action@master - # with: - # github-token: ${{ secrets.GITHUB_TOKEN }} - # path-to-lcov: ./lcov.info + args: '--workspace --ignored -e examples -e integration --features=runtime,derive,ws,oauth,jsonpatch,admission,k8s-openapi/v1_22 -o Stdout -t 600 -- --test-threads 1' - uses: codecov/codecov-action@v2 with: flags: unittests,rust diff --git a/Makefile b/Makefile index ba4394b20..a9975644f 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ test: test-kubernetes: cargo test --lib --all -- --ignored # also run tests that fail on github actions - cargo test -p kube --features=derive -- --ignored + cargo test -p kube --lib --features=derive,runtime -- --ignored cargo run -p kube-examples --example crd_derive cargo run -p kube-examples --example crd_api diff --git a/kube-derive/src/lib.rs b/kube-derive/src/lib.rs index 871012e12..9581ef44a 100644 --- a/kube-derive/src/lib.rs +++ b/kube-derive/src/lib.rs @@ -209,8 +209,10 @@ mod custom_resource; /// If you have to override a lot, [you can opt-out of schema-generation entirely](#kubeschema--mode) /// /// ## Advanced Features +/// /// - **embedding k8s-openapi types** can be done by enabling the `schemars` feature of `k8s-openapi` from [`0.13.0`](https://github.com/Arnavion/k8s-openapi/blob/master/CHANGELOG.md#v0130-2021-08-09) /// - **adding validation** via [validator crate](https://github.com/Keats/validator) is supported from `schemars` >= [`0.8.5`](https://github.com/GREsau/schemars/blob/master/CHANGELOG.md#085---2021-09-20) +/// - **generating rust code from schemas** can be done via [kopium](https://github.com/kube-rs/kopium) and is supported on stable crds (> 1.16 kubernetes) /// /// ### Validation Caveats /// The supported **`#[validate]` attrs also exist as `#[schemars]` attrs** so you can use those directly if you do not require the validation to run client-side (in your code). diff --git a/kube/src/lib.rs b/kube/src/lib.rs index 63cf6d04c..8c8359f56 100644 --- a/kube/src/lib.rs +++ b/kube/src/lib.rs @@ -180,25 +180,37 @@ pub use crate::core::{CustomResourceExt, Resource, ResourceExt}; pub use kube_core as core; +// Tests that require a cluster and the complete feature set +// Can be run with `cargo test -p kube --lib --features=runtime,derive -- --ignored` #[cfg(test)] +#[cfg(all(feature = "derive", feature = "runtime"))] mod test { - #[cfg(all(feature = "derive", feature = "client"))] + use schemars::JsonSchema; + use serde::{Deserialize, Serialize}; + use crate::{Api, Client, CustomResourceExt}; + use kube_derive::CustomResource; + + #[derive(CustomResource, Deserialize, Serialize, Clone, Debug, JsonSchema)] + #[kube(group = "clux.dev", version = "v1", kind = "Foo", namespaced)] + #[kube(status = "FooStatus")] + #[kube(scale = r#"{"specReplicasPath":".spec.replicas", "statusReplicasPath":".status.replicas"}"#)] + #[kube(crates(kube_core = "crate::core"))] // for dev-dep test structure + pub struct FooSpec { + name: String, + info: Option, + replicas: isize, + } + + #[derive(Deserialize, Serialize, Clone, Debug, Default, JsonSchema)] + pub struct FooStatus { + is_bad: bool, + replicas: isize, + } + #[tokio::test] #[ignore] // needs kubeconfig - async fn convenient_custom_resource() { - use crate::{ - core::{ApiResource, DynamicObject, GroupVersionKind}, - Api, Client, CustomResource, - }; - use schemars::JsonSchema; - use serde::{Deserialize, Serialize}; - - #[derive(Clone, Debug, CustomResource, Deserialize, Serialize, JsonSchema)] - #[kube(group = "clux.dev", version = "v1", kind = "Foo", namespaced)] - #[kube(crates(kube_core = "crate::core"))] - struct FooSpec { - foo: String, - } + async fn custom_resource_generates_correct_core_structs() { + use crate::core::{ApiResource, DynamicObject, GroupVersionKind}; let client = Client::try_default().await.unwrap(); let gvk = GroupVersionKind::gvk("clux.dev", "v1", "Foo"); @@ -209,4 +221,45 @@ mod test { // make sure they return the same url_path through their impls assert_eq!(a1.resource_url(), a2.resource_url()); } + + use k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceDefinition; + #[tokio::test] + #[ignore] // needs kubeconfig + async fn derived_resource_queriable() -> Result<(), Box> { + use crate::{ + core::params::{Patch, PatchParams}, + runtime::wait::{await_condition, conditions}, + }; + let client = Client::try_default().await?; + let ssapply = PatchParams::apply("kube").force(); + let crds: Api = Api::all(client.clone()); + // Server-side apply CRD + crds.patch("foos.clux.dev", &ssapply, &Patch::Apply(Foo::crd())) + .await?; + // Wait for it to be ready: + let establish = await_condition(crds, "foos.clux.dev", conditions::is_crd_established()); + let _ = tokio::time::timeout(std::time::Duration::from_secs(10), establish).await?; + // Use it + let foos: Api = Api::default_namespaced(client.clone()); + // Apply from generated struct + let foo = Foo::new("baz", FooSpec { + name: "baz".into(), + info: Some("old baz".into()), + replicas: 3, + }); + let o = foos.patch("baz", &ssapply, &Patch::Apply(&foo)).await?; + assert_eq!(o.spec.name, "baz"); + // Apply from partial json! + let patch = serde_json::json!({ + "apiVersion": "clux.dev/v1", + "kind": "Foo", + "spec": { + "name": "foo", + "replicas": 2 + } + }); + let o2 = foos.patch("baz", &ssapply, &Patch::Apply(patch)).await?; + assert_eq!(o2.spec.replicas, 2); + Ok(()) + } } From 85b515639dd492c7371483dceae62850ea801a7c Mon Sep 17 00:00:00 2001 From: clux Date: Sun, 5 Dec 2021 11:25:17 +0000 Subject: [PATCH 06/18] remove duplicate instructions and leftovers Signed-off-by: clux --- .github/workflows/coverage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 2dcb75fc6..354459622 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -31,7 +31,7 @@ jobs: version: '0.18.5' out-type: Xml timeout: 600 - args: '--workspace --ignored -e examples -e integration --features=runtime,derive,ws,oauth,jsonpatch,admission,k8s-openapi/v1_22 -o Stdout -t 600 -- --test-threads 1' + args: '--workspace --ignored -e examples -e integration --features=runtime,derive,ws,oauth,jsonpatch,admission,k8s-openapi/v1_22 -- --test-threads 1' - uses: codecov/codecov-action@v2 with: flags: unittests,rust From b71ddb055a8b4e9c048c30e62f967f44c0c371cd Mon Sep 17 00:00:00 2001 From: clux Date: Sun, 5 Dec 2021 11:39:46 +0000 Subject: [PATCH 07/18] fmt + comment Signed-off-by: clux --- kube/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kube/src/lib.rs b/kube/src/lib.rs index 8c8359f56..447b02f0a 100644 --- a/kube/src/lib.rs +++ b/kube/src/lib.rs @@ -185,10 +185,10 @@ pub use kube_core as core; #[cfg(test)] #[cfg(all(feature = "derive", feature = "runtime"))] mod test { - use schemars::JsonSchema; - use serde::{Deserialize, Serialize}; use crate::{Api, Client, CustomResourceExt}; use kube_derive::CustomResource; + use schemars::JsonSchema; + use serde::{Deserialize, Serialize}; #[derive(CustomResource, Deserialize, Serialize, Clone, Debug, JsonSchema)] #[kube(group = "clux.dev", version = "v1", kind = "Foo", namespaced)] @@ -224,7 +224,7 @@ mod test { use k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceDefinition; #[tokio::test] - #[ignore] // needs kubeconfig + #[ignore] // needs cluster (creates + patches foo crd) async fn derived_resource_queriable() -> Result<(), Box> { use crate::{ core::params::{Patch, PatchParams}, From 4d782944315586802d8386fae7a6aab6c0de6d8d Mon Sep 17 00:00:00 2001 From: clux Date: Sun, 5 Dec 2021 12:47:12 +0000 Subject: [PATCH 08/18] simplify (tarpaulin does not inject features in workspaces anyway) Signed-off-by: clux --- .github/workflows/coverage.yml | 2 +- kube/src/lib.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 354459622..51b2ce110 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -31,7 +31,7 @@ jobs: version: '0.18.5' out-type: Xml timeout: 600 - args: '--workspace --ignored -e examples -e integration --features=runtime,derive,ws,oauth,jsonpatch,admission,k8s-openapi/v1_22 -- --test-threads 1' + args: '--workspace --ignored -e examples -e integration -- --test-threads 1' - uses: codecov/codecov-action@v2 with: flags: unittests,rust diff --git a/kube/src/lib.rs b/kube/src/lib.rs index 447b02f0a..12a0cc35e 100644 --- a/kube/src/lib.rs +++ b/kube/src/lib.rs @@ -183,7 +183,6 @@ pub use kube_core as core; // Tests that require a cluster and the complete feature set // Can be run with `cargo test -p kube --lib --features=runtime,derive -- --ignored` #[cfg(test)] -#[cfg(all(feature = "derive", feature = "runtime"))] mod test { use crate::{Api, Client, CustomResourceExt}; use kube_derive::CustomResource; @@ -209,6 +208,7 @@ mod test { #[tokio::test] #[ignore] // needs kubeconfig + #[cfg(feature = "derive")] async fn custom_resource_generates_correct_core_structs() { use crate::core::{ApiResource, DynamicObject, GroupVersionKind}; let client = Client::try_default().await.unwrap(); @@ -225,6 +225,7 @@ mod test { use k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceDefinition; #[tokio::test] #[ignore] // needs cluster (creates + patches foo crd) + #[cfg(all(feature = "derive", feature = "runtime"))] async fn derived_resource_queriable() -> Result<(), Box> { use crate::{ core::params::{Patch, PatchParams}, From e85ddfa2065cd7480298a14ed06f6fed63d15a44 Mon Sep 17 00:00:00 2001 From: clux Date: Sun, 5 Dec 2021 12:53:39 +0000 Subject: [PATCH 09/18] fix test feature requirement Signed-off-by: clux --- kube/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kube/src/lib.rs b/kube/src/lib.rs index 12a0cc35e..05ceed882 100644 --- a/kube/src/lib.rs +++ b/kube/src/lib.rs @@ -208,7 +208,7 @@ mod test { #[tokio::test] #[ignore] // needs kubeconfig - #[cfg(feature = "derive")] + #[cfg(all(feature = "derive", feature = "client"))] async fn custom_resource_generates_correct_core_structs() { use crate::core::{ApiResource, DynamicObject, GroupVersionKind}; let client = Client::try_default().await.unwrap(); From 3218f12b36b99b8475feac6a2c64ba5f331777cb Mon Sep 17 00:00:00 2001 From: clux Date: Sun, 5 Dec 2021 12:58:05 +0000 Subject: [PATCH 10/18] need to move cfg limit before module Signed-off-by: clux --- kube/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kube/src/lib.rs b/kube/src/lib.rs index 05ceed882..bac57e513 100644 --- a/kube/src/lib.rs +++ b/kube/src/lib.rs @@ -183,6 +183,7 @@ pub use kube_core as core; // Tests that require a cluster and the complete feature set // Can be run with `cargo test -p kube --lib --features=runtime,derive -- --ignored` #[cfg(test)] +#[cfg(all(feature = "derive", feature = "client"))] mod test { use crate::{Api, Client, CustomResourceExt}; use kube_derive::CustomResource; @@ -208,7 +209,6 @@ mod test { #[tokio::test] #[ignore] // needs kubeconfig - #[cfg(all(feature = "derive", feature = "client"))] async fn custom_resource_generates_correct_core_structs() { use crate::core::{ApiResource, DynamicObject, GroupVersionKind}; let client = Client::try_default().await.unwrap(); From 3fa1dff6c65177ab0ca2c06d1373568059526206 Mon Sep 17 00:00:00 2001 From: clux Date: Sun, 5 Dec 2021 13:01:45 +0000 Subject: [PATCH 11/18] try running doc tests as well Signed-off-by: clux --- .github/workflows/coverage.yml | 2 +- kube-client/src/api/core_methods.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 51b2ce110..449678fc8 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -31,7 +31,7 @@ jobs: version: '0.18.5' out-type: Xml timeout: 600 - args: '--workspace --ignored -e examples -e integration -- --test-threads 1' + args: '--workspace --bins --lib --doc --ignored -e examples -e integration -- --test-threads 1' - uses: codecov/codecov-action@v2 with: flags: unittests,rust diff --git a/kube-client/src/api/core_methods.rs b/kube-client/src/api/core_methods.rs index 609059aaa..6469567e8 100644 --- a/kube-client/src/api/core_methods.rs +++ b/kube-client/src/api/core_methods.rs @@ -266,7 +266,7 @@ where /// let jobs: Api = Api::namespaced(client, "apps"); /// let lp = ListParams::default() /// .fields("metadata.name=my_job") - /// .timeout(20); // upper bound of how long we watch for + /// .timeout(5); // upper bound of how long we watch for /// let mut stream = jobs.watch(&lp, "0").await?.boxed(); /// while let Some(status) = stream.try_next().await? { /// match status { From 0660b22fde0a5c516352708a189c89d8d40a8830 Mon Sep 17 00:00:00 2001 From: clux Date: Sun, 5 Dec 2021 13:31:48 +0000 Subject: [PATCH 12/18] try using nightly for tarpaulin doc test runner Signed-off-by: clux --- .github/workflows/coverage.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 449678fc8..bccb9838f 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -11,10 +11,10 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 - - name: Install stable toolchain + - name: Install nightly toolchain uses: actions-rs/toolchain@v1 with: - toolchain: stable + toolchain: nightly override: true - uses: Swatinem/rust-cache@v1 - uses: AbsaOSS/k3d-action@v2 @@ -31,7 +31,8 @@ jobs: version: '0.18.5' out-type: Xml timeout: 600 - args: '--workspace --bins --lib --doc --ignored -e examples -e integration -- --test-threads 1' + # NB: feature selection do not work yet + args: '--workspace --lib --ignored --doc -e integration -- --test-threads 1' - uses: codecov/codecov-action@v2 with: flags: unittests,rust From 8add4850fb8efedfa1e3f83a61c3aa24c93f72a8 Mon Sep 17 00:00:00 2001 From: clux Date: Sun, 5 Dec 2021 14:00:09 +0000 Subject: [PATCH 13/18] try with two runs of tarpaulin Signed-off-by: clux --- .github/workflows/coverage.yml | 3 +-- tarpaulin.toml | 12 ++++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 tarpaulin.toml diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index bccb9838f..4483cd80d 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -31,8 +31,7 @@ jobs: version: '0.18.5' out-type: Xml timeout: 600 - # NB: feature selection do not work yet - args: '--workspace --lib --ignored --doc -e integration -- --test-threads 1' + args: '--config=tarpaulin.toml -- --test-threads 1' - uses: codecov/codecov-action@v2 with: flags: unittests,rust diff --git a/tarpaulin.toml b/tarpaulin.toml new file mode 100644 index 000000000..4c22341b6 --- /dev/null +++ b/tarpaulin.toml @@ -0,0 +1,12 @@ +[lib_coverage] +workspace = true +exclude = ["integration"] +#exclude_files = ["integration/"] +run-types = ["Doctests", "Tests"] + +[kube_lib_ignored_coverage] +features = "kube/derive kube/runtime" +color = "Always" +packages = ["kube"] +workspace = false +ignored = true From ac6a4723854e464541212dc154d31919d6343ce2 Mon Sep 17 00:00:00 2001 From: clux Date: Sun, 5 Dec 2021 14:44:48 +0000 Subject: [PATCH 14/18] simplified with one-pass on stable Signed-off-by: clux --- .github/workflows/coverage.yml | 7 +++---- tarpaulin.toml | 16 ++++++++-------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 4483cd80d..d1361b0c4 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -11,10 +11,10 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 - - name: Install nightly toolchain + - name: Install stable toolchain uses: actions-rs/toolchain@v1 with: - toolchain: nightly + toolchain: stable override: true - uses: Swatinem/rust-cache@v1 - uses: AbsaOSS/k3d-action@v2 @@ -30,8 +30,7 @@ jobs: with: version: '0.18.5' out-type: Xml - timeout: 600 - args: '--config=tarpaulin.toml -- --test-threads 1' + args: ' -- --test-threads 1' - uses: codecov/codecov-action@v2 with: flags: unittests,rust diff --git a/tarpaulin.toml b/tarpaulin.toml index 4c22341b6..cc3b002f8 100644 --- a/tarpaulin.toml +++ b/tarpaulin.toml @@ -1,12 +1,12 @@ -[lib_coverage] -workspace = true -exclude = ["integration"] -#exclude_files = ["integration/"] -run-types = ["Doctests", "Tests"] +# Usage cargo tarpaulin -- --test-threads 1 -[kube_lib_ignored_coverage] +[one_pass_coverage] +workspace = true features = "kube/derive kube/runtime" color = "Always" -packages = ["kube"] -workspace = false ignored = true +timeout = "600s" +exclude = ["integration"] +# NB: skipping Doctests because they are slow to build and generally marked no_run +run-types = ["Tests"] +generate = ["Json"] From 04074eb8974aca745b7654deb30ffade0186bc7f Mon Sep 17 00:00:00 2001 From: clux Date: Sun, 5 Dec 2021 15:11:15 +0000 Subject: [PATCH 15/18] test 3 core methods Signed-off-by: clux --- kube-core/src/admission.rs | 1 - kube/src/lib.rs | 6 ++++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/kube-core/src/admission.rs b/kube-core/src/admission.rs index 0a39c5ebc..5230fb248 100644 --- a/kube-core/src/admission.rs +++ b/kube-core/src/admission.rs @@ -31,7 +31,6 @@ pub struct SerializePatchError(#[source] serde_json::Error); /// Failed to convert `AdmissionReview` into `AdmissionRequest`. pub struct ConvertAdmissionReviewError; - /// The `kind` field in [`TypeMeta`]. pub const META_KIND: &str = "AdmissionReview"; /// The `api_version` field in [`TypeMeta`] on the v1 version. diff --git a/kube/src/lib.rs b/kube/src/lib.rs index bac57e513..b47353d5b 100644 --- a/kube/src/lib.rs +++ b/kube/src/lib.rs @@ -179,7 +179,6 @@ pub use crate::core::{CustomResourceExt, Resource, ResourceExt}; #[doc(inline)] pub use kube_core as core; - // Tests that require a cluster and the complete feature set // Can be run with `cargo test -p kube --lib --features=runtime,derive -- --ignored` #[cfg(test)] @@ -228,7 +227,7 @@ mod test { #[cfg(all(feature = "derive", feature = "runtime"))] async fn derived_resource_queriable() -> Result<(), Box> { use crate::{ - core::params::{Patch, PatchParams}, + core::params::{DeleteParams, Patch, PatchParams}, runtime::wait::{await_condition, conditions}, }; let client = Client::try_default().await?; @@ -261,6 +260,9 @@ mod test { }); let o2 = foos.patch("baz", &ssapply, &Patch::Apply(patch)).await?; assert_eq!(o2.spec.replicas, 2); + assert_eq!(foos.get_scale("baz").await?.spec.unwrap().replicas, Some(2)); + assert!(foos.get_status("baz").await?.status.is_none()); // nothing has set this + foos.delete("baz", &DeleteParams::default()).await?; Ok(()) } } From c4c3a2490f07b23a1424204e5556b384744f1f72 Mon Sep 17 00:00:00 2001 From: clux Date: Sun, 5 Dec 2021 15:26:53 +0000 Subject: [PATCH 16/18] import parts of dynamic api example as discovery tests Signed-off-by: clux --- kube/src/lib.rs | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/kube/src/lib.rs b/kube/src/lib.rs index b47353d5b..c042b1e93 100644 --- a/kube/src/lib.rs +++ b/kube/src/lib.rs @@ -184,7 +184,7 @@ pub use kube_core as core; #[cfg(test)] #[cfg(all(feature = "derive", feature = "client"))] mod test { - use crate::{Api, Client, CustomResourceExt}; + use crate::{Api, Client, CustomResourceExt, ResourceExt}; use kube_derive::CustomResource; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; @@ -265,4 +265,37 @@ mod test { foos.delete("baz", &DeleteParams::default()).await?; Ok(()) } + + #[tokio::test] + #[ignore] // needs cluster (fetches api resources, and lists all) + #[cfg(all(feature = "derive", feature = "runtime"))] + async fn dynamic_resources_discoverable() -> Result<(), Box> { + use crate::{ + core::DynamicObject, + discovery::{verbs, Discovery, Scope}, + }; + let client = Client::try_default().await?; + + let discovery = Discovery::new(client.clone()).run().await?; + for group in discovery.groups() { + for (ar, caps) in group.recommended_resources() { + if !caps.supports_operation(verbs::LIST) { + continue; + } + let api: Api = if caps.scope == Scope::Namespaced { + Api::default_namespaced_with(client.clone(), &ar) + } else { + Api::all_with(client.clone(), &ar) + }; + println!("{}/{} : {}", group.name(), ar.version, ar.kind); + let list = api.list(&Default::default()).await?; + for item in list.items { + let name = item.name(); + let ns = item.metadata.namespace.map(|s| s + "/").unwrap_or_default(); + println!("\t\t{}{}", ns, name); + } + } + } + Ok(()) + } } From 049405056b10ae0a21a0d6878045c3fd4436b317 Mon Sep 17 00:00:00 2001 From: clux Date: Sun, 5 Dec 2021 15:51:46 +0000 Subject: [PATCH 17/18] remove accidentally left-in flags Signed-off-by: clux --- .github/workflows/coverage.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index d1361b0c4..0d6b03761 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -32,5 +32,3 @@ jobs: out-type: Xml args: ' -- --test-threads 1' - uses: codecov/codecov-action@v2 - with: - flags: unittests,rust From 03de8abf0dd235dcf356078140aa01d76ecfec0f Mon Sep 17 00:00:00 2001 From: clux Date: Sun, 5 Dec 2021 15:52:24 +0000 Subject: [PATCH 18/18] revert pointless change in core_methods Signed-off-by: clux --- kube-client/src/api/core_methods.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kube-client/src/api/core_methods.rs b/kube-client/src/api/core_methods.rs index 6469567e8..609059aaa 100644 --- a/kube-client/src/api/core_methods.rs +++ b/kube-client/src/api/core_methods.rs @@ -266,7 +266,7 @@ where /// let jobs: Api = Api::namespaced(client, "apps"); /// let lp = ListParams::default() /// .fields("metadata.name=my_job") - /// .timeout(5); // upper bound of how long we watch for + /// .timeout(20); // upper bound of how long we watch for /// let mut stream = jobs.watch(&lp, "0").await?.boxed(); /// while let Some(status) = stream.try_next().await? { /// match status {