Skip to content

Commit

Permalink
Upgrade k8s-openapi to 0.16 (#1008)
Browse files Browse the repository at this point in the history
* cargo upgrade k8s-openapi --workspace

Signed-off-by: clux <sszynrae@gmail.com>

* just bump-k8s

Signed-off-by: clux <sszynrae@gmail.com>

* fix kube-core unit tests

Signed-off-by: clux <sszynrae@gmail.com>

* remove old k3s-arg that's not working anymore

Signed-off-by: clux <sszynrae@gmail.com>

* remove unsupported k3d-args (in more places)

Signed-off-by: clux <sszynrae@gmail.com>

* work around delete_collection bug in a bad way

Signed-off-by: clux <sszynrae@gmail.com>

* unpub

Signed-off-by: clux <sszynrae@gmail.com>

* less clone

Signed-off-by: clux <sszynrae@gmail.com>

* docs for the hidden kind

Signed-off-by: clux <sszynrae@gmail.com>

* awkward version check in the middle of delete_collection

Signed-off-by: clux <sszynrae@gmail.com>

* syntax for le_1_24..

Signed-off-by: clux <sszynrae@gmail.com>

* assert output for ci

Signed-off-by: clux <sszynrae@gmail.com>

* split unit tests and make an unstable feature for it

Signed-off-by: clux <sszynrae@gmail.com>

* need to actually add the unstable feature in kube-core as well

Signed-off-by: clux <sszynrae@gmail.com>

* ..also propagate the feature to examples

Signed-off-by: clux <sszynrae@gmail.com>

* double equals in ci syntax..

Signed-off-by: clux <sszynrae@gmail.com>

* use an evar rather than a feature

Signed-off-by: clux <sszynrae@gmail.com>

* review + be slightly more resilient without the opt-in

basically special-case the empty params case with an internal is_default
(cannot do Eq/PartialEq because upstream types do not have it).

which does mean delete_collection with default delete params keeps on
working on 1.25 (but then immediately breaks if they change from default
without the evar)

Signed-off-by: clux <sszynrae@gmail.com>

* update comment

Signed-off-by: clux <sszynrae@gmail.com>

* remove 1.25 workaround from main release

Signed-off-by: clux <sszynrae@gmail.com>

* remove evar set in ci

Signed-off-by: clux <sszynrae@gmail.com>

Signed-off-by: clux <sszynrae@gmail.com>
  • Loading branch information
clux committed Sep 21, 2022
1 parent cc2a2b9 commit a65c249
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 48 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/ci.yml
Expand Up @@ -122,7 +122,7 @@ jobs:
fail-fast: false
matrix:
# Run these tests against older clusters as well
k8s: [v1.19, latest]
k8s: [v1.20, latest]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand All @@ -144,7 +144,7 @@ jobs:
# Used to avoid rate limits when fetching the releases from k3s repo.
# Anonymous access is limited to 60 requests / hour / worker
# github-token: ${{ secrets.GITHUB_TOKEN }}
k3d-args: "--no-lb --k3s-arg --no-deploy=traefik,servicelb,metrics-server@server:*"
k3d-args: "--no-lb --no-rollback --k3s-arg --disable=traefik,servicelb,metrics-server@server:*"

# Real CI work starts here
- name: Build workspace
Expand All @@ -155,14 +155,15 @@ jobs:
run: cargo test --lib --all -- --ignored
- name: Run all facade integration library tests with extra features
run: cargo test -p kube --lib --features=derive,runtime -- --ignored --nocapture
- name: Run crd example tests
run: cargo run -p kube-examples --example crd_api
- name: Run all client integration library tests with rustls and ws
run: cargo test -p kube-client --lib --features=rustls-tls,ws -- --ignored
- name: Run derive example tests
run: cargo run -p kube-examples --example crd_derive
- name: Run crd example tests
run: cargo run -p kube-examples --example crd_api


mk8sv:
# comile check e2e tests against mk8sv
runs-on: ubuntu-latest
Expand Down Expand Up @@ -201,13 +202,13 @@ jobs:

- uses: nolar/setup-k3d-k3s@v1
with:
version: v1.19
version: v1.20
# k3d-kube
k3d-name: kube
# Used to avoid rate limits when fetching the releases from k3s repo.
# Anonymous access is limited to 60 requests / hour / worker
# github-token: ${{ secrets.GITHUB_TOKEN }}
k3d-args: "--no-lb --k3s-arg --no-deploy=traefik,servicelb,metrics-server@server:*"
k3d-args: "--no-lb --no-rollback --k3s-arg --disable=traefik,servicelb,metrics-server@server:*"

# Real CI work starts here
- name: Build workspace
Expand Down Expand Up @@ -254,7 +255,7 @@ jobs:
# Used to avoid rate limits when fetching the releases from k3s repo.
# Anonymous access is limited to 60 requests / hour / worker
# github-token: ${{ secrets.GITHUB_TOKEN }}
k3d-args: "--no-lb --k3s-arg --no-deploy=traefik,servicelb,metrics-server@server:*"
k3d-args: "--no-lb --no-rollback --k3s-arg --disable=traefik,servicelb,metrics-server@server:*"

- name: Compile e2e job against ${{matrix.tls}}
run: |
Expand Down
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -2,7 +2,7 @@

[![Crates.io](https://img.shields.io/crates/v/kube.svg)](https://crates.io/crates/kube)
[![Rust 1.60](https://img.shields.io/badge/MSRV-1.60-dea584.svg)](https://github.com/rust-lang/rust/releases/tag/1.60.0)
[![Tested against Kubernetes 1.19 and above](https://img.shields.io/badge/MK8SV-1.19-326ce5.svg)](https://kube.rs/kubernetes-version)
[![Tested against Kubernetes v1_20 and above](https://img.shields.io/badge/MK8SV-v1_20-326ce5.svg)](https://kube.rs/kubernetes-version)
[![Best Practices](https://bestpractices.coreinfrastructure.org/projects/5413/badge)](https://bestpractices.coreinfrastructure.org/projects/5413)
[![Discord chat](https://img.shields.io/discord/500028886025895936.svg?logo=discord&style=plastic)](https://discord.gg/tokio)

Expand All @@ -17,7 +17,7 @@ Select a version of `kube` along with the generated [k8s-openapi](https://github
```toml
[dependencies]
kube = { version = "0.74.0", features = ["runtime", "derive"] }
k8s-openapi = { version = "0.15.0", features = ["v1_24"] }
k8s-openapi = { version = "0.15.0", features = ["v1_25"] }
```

[Features are available](https://github.com/kube-rs/kube-rs/blob/master/kube/Cargo.toml#L18).
Expand Down Expand Up @@ -153,7 +153,7 @@ Kube has basic support ([with caveats](https://github.com/kube-rs/kube-rs/issues
```toml
[dependencies]
kube = { version = "0.74.0", default-features = false, features = ["client", "rustls-tls"] }
k8s-openapi = { version = "0.15.0", features = ["v1_24"] }
k8s-openapi = { version = "0.15.0", features = ["v1_25"] }
```

This will pull in `rustls` and `hyper-rustls`.
Expand Down
6 changes: 3 additions & 3 deletions e2e/Cargo.toml
Expand Up @@ -18,8 +18,8 @@ name = "boot"
path = "boot.rs"

[features]
latest = ["k8s-openapi/v1_24"]
mk8sv = ["k8s-openapi/v1_19"]
latest = ["k8s-openapi/v1_25"]
mk8sv = ["k8s-openapi/v1_20"]
rustls = ["kube/rustls-tls"]
openssl = ["kube/openssl-tls"]

Expand All @@ -29,6 +29,6 @@ tracing = "0.1.29"
tracing-subscriber = "0.3.3"
futures = "0.3.17"
kube = { path = "../kube", version = "^0.74.0", default-features = false, features = ["client", "runtime", "ws", "admission", "gzip"] }
k8s-openapi = { version = "0.15.0", default-features = false }
k8s-openapi = { version = "0.16.0", default-features = false }
serde_json = "1.0.68"
tokio = { version = "1.14.0", features = ["full"] }
4 changes: 2 additions & 2 deletions examples/Cargo.toml
Expand Up @@ -20,7 +20,7 @@ openssl-tls = ["kube/client", "kube/openssl-tls"]
rustls-tls = ["kube/client", "kube/rustls-tls"]
runtime = ["kube/runtime"]
ws = ["kube/ws"]
latest = ["k8s-openapi/v1_24"]
latest = ["k8s-openapi/v1_25"]

[dev-dependencies]
tokio-util = "0.7.0"
Expand All @@ -31,7 +31,7 @@ futures = "0.3.17"
jsonpath_lib = "0.3.0"
kube = { path = "../kube", version = "^0.74.0", default-features = false, features = ["admission"] }
kube-derive = { path = "../kube-derive", version = "^0.74.0", default-features = false } # only needed to opt out of schema
k8s-openapi = { version = "0.15.0", default-features = false }
k8s-openapi = { version = "0.16.0", default-features = false }
serde = { version = "1.0.130", features = ["derive"] }
serde_json = "1.0.68"
serde_yaml = "0.8.21"
Expand Down
5 changes: 3 additions & 2 deletions justfile
Expand Up @@ -13,7 +13,7 @@ fmt:
rustfmt +nightly --edition 2021 $(find . -type f -iname *.rs)

doc:
RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --lib --workspace --features=derive,ws,oauth,jsonpatch,client,derive,runtime,admission,k8s-openapi/v1_24 --open
RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --lib --workspace --features=derive,ws,oauth,jsonpatch,client,derive,runtime,admission,k8s-openapi/v1_25 --open

# Unit tests
test:
Expand Down Expand Up @@ -76,7 +76,8 @@ e2e-job-musl features:

k3d:
k3d cluster create main --servers 1 --registry-create main \
--k3s-arg "--no-deploy=traefik@server:*" \
--no-lb --no-rollback \
--k3s-arg "--disable=traefik,servicelb,metrics-server@server:*" \
--k3s-arg '--kubelet-arg=eviction-hard=imagefs.available<1%,nodefs.available<1%@agent:*' \
--k3s-arg '--kubelet-arg=eviction-minimum-reclaim=imagefs.available=1%,nodefs.available=1%@agent:*'

Expand Down
8 changes: 4 additions & 4 deletions kube-client/Cargo.toml
Expand Up @@ -32,7 +32,7 @@ config = ["__non_core", "pem", "dirs"]
__non_core = ["tracing", "serde_yaml", "base64"]

[package.metadata.docs.rs]
features = ["client", "native-tls", "rustls-tls", "openssl-tls", "ws", "oauth", "jsonpatch", "admission", "k8s-openapi/v1_24"]
features = ["client", "native-tls", "rustls-tls", "openssl-tls", "ws", "oauth", "jsonpatch", "admission", "k8s-openapi/v1_25"]
# Define the configuration attribute `docsrs`. Used to enable `doc_cfg` feature.
rustdoc-args = ["--cfg", "docsrs"]

Expand Down Expand Up @@ -73,7 +73,7 @@ tracing = { version = "0.1.29", features = ["log"], optional = true }
hyper-openssl = { version = "0.9.2", optional = true }

[dependencies.k8s-openapi]
version = "0.15.0"
version = "0.16.0"
default-features = false
features = []

Expand All @@ -86,6 +86,6 @@ tokio-test = "0.4.0"
tower-test = "0.4.0"

[dev-dependencies.k8s-openapi]
version = "0.15.0"
version = "0.16.0"
default-features = false
features = ["v1_24"]
features = ["v1_25"]
8 changes: 4 additions & 4 deletions kube-core/Cargo.toml
Expand Up @@ -13,7 +13,7 @@ repository = "https://github.com/kube-rs/kube-rs"
readme = "../README.md"

[package.metadata.docs.rs]
features = ["ws", "admission", "jsonpatch", "k8s-openapi/v1_24"]
features = ["ws", "admission", "jsonpatch", "k8s-openapi/v1_25"]
rustdoc-args = ["--cfg", "docsrs"]

[features]
Expand All @@ -34,14 +34,14 @@ chrono = { version = "0.4.19", default-features = false, features = ["clock"] }
schemars = { version = "0.8.6", optional = true }

[dependencies.k8s-openapi]
version = "0.15.0"
version = "0.16.0"
default-features = false
features = []

[dev-dependencies.k8s-openapi]
version = "0.15.0"
version = "0.16.0"
default-features = false
features = ["v1_24"]
features = ["v1_25"]

[dev-dependencies]
assert-json-diff = "2.0.1"
Expand Down
7 changes: 7 additions & 0 deletions kube-core/src/params.rs
Expand Up @@ -476,6 +476,13 @@ impl DeleteParams {
self.preconditions = Some(preconditions);
self
}

pub(crate) fn is_default(&self) -> bool {
!self.dry_run
&& self.grace_period_seconds.is_none()
&& self.propagation_policy.is_none()
&& self.preconditions.is_none()
}
}

// dryRun serialization differ when used as body parameters and query strings:
Expand Down
17 changes: 11 additions & 6 deletions kube-core/src/request.rs
Expand Up @@ -148,9 +148,15 @@ impl Request {
qp.append_pair("labelSelector", labels);
}
let urlstr = qp.finish();
let body = serde_json::to_vec(&dp).map_err(Error::SerializeBody)?;

let data = if dp.is_default() {
vec![] // default serialize needs to be empty body
} else {
serde_json::to_vec(&dp).map_err(Error::SerializeBody)?
};

let req = http::Request::delete(urlstr).header(http::header::CONTENT_TYPE, JSON_MIME);
req.body(body).map_err(Error::BuildRequest)
req.body(data).map_err(Error::BuildRequest)
}

/// Patch an instance of a resource
Expand Down Expand Up @@ -276,11 +282,10 @@ mod test {
use crate::{params::PostParams, request::Request, resource::Resource};
use k8s::{
admissionregistration::v1 as adregv1, apps::v1 as appsv1, authorization::v1 as authv1,
autoscaling::v1 as autoscalingv1, batch::v1beta1 as batchv1beta1, core::v1 as corev1,
autoscaling::v1 as autoscalingv1, batch::v1 as batchv1, core::v1 as corev1,
networking::v1 as networkingv1, rbac::v1 as rbacv1, storage::v1 as storagev1,
};
use k8s_openapi::api as k8s;
// use k8s::batch::v1 as batchv1;

// NB: stable requires >= 1.17
use k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1 as apiextsv1;
Expand Down Expand Up @@ -315,9 +320,9 @@ mod test {

#[test]
fn api_url_cj() {
let url = batchv1beta1::CronJob::url_path(&(), Some("ns"));
let url = batchv1::CronJob::url_path(&(), Some("ns"));
let req = Request::new(url).create(&PostParams::default(), vec![]).unwrap();
assert_eq!(req.uri(), "/apis/batch/v1beta1/namespaces/ns/cronjobs?");
assert_eq!(req.uri(), "/apis/batch/v1/namespaces/ns/cronjobs?");
}
#[test]
fn api_url_hpa() {
Expand Down
2 changes: 1 addition & 1 deletion kube-derive/Cargo.toml
Expand Up @@ -26,7 +26,7 @@ proc-macro = true
serde = { version = "1.0.130", features = ["derive"] }
serde_yaml = "0.8.21"
kube = { path = "../kube", default-features = false, version = "<1.0.0, >=0.61.0", features = ["derive"] }
k8s-openapi = { version = "0.15.0", default-features = false, features = ["v1_24"] }
k8s-openapi = { version = "0.16.0", default-features = false, features = ["v1_25"] }
schemars = { version = "0.8.6", features = ["chrono"] }
validator = { version = "0.16.0", features = ["derive"] }
chrono = { version = "0.4.19", default-features = false }
Expand Down
8 changes: 4 additions & 4 deletions kube-runtime/Cargo.toml
Expand Up @@ -15,7 +15,7 @@ rust-version = "1.60.0"
edition = "2021"

[package.metadata.docs.rs]
features = ["k8s-openapi/v1_24"]
features = ["k8s-openapi/v1_25"]
# Define the configuration attribute `docsrs`. Used to enable `doc_cfg` feature.
rustdoc-args = ["--cfg", "docsrs"]

Expand All @@ -37,7 +37,7 @@ thiserror = "1.0.29"
backoff = "0.4.0"

[dependencies.k8s-openapi]
version = "0.15.0"
version = "0.16.0"
default-features = false

[dev-dependencies]
Expand All @@ -48,6 +48,6 @@ rand = "0.8.0"
schemars = "0.8.6"

[dev-dependencies.k8s-openapi]
version = "0.15.0"
version = "0.16.0"
default-features = false
features = ["v1_24"]
features = ["v1_25"]
8 changes: 4 additions & 4 deletions kube/Cargo.toml
Expand Up @@ -31,7 +31,7 @@ config = ["kube-client/config"]
runtime = ["kube-runtime"]

[package.metadata.docs.rs]
features = ["client", "native-tls", "rustls-tls", "openssl-tls", "derive", "ws", "oauth", "jsonpatch", "admission", "runtime", "k8s-openapi/v1_24"]
features = ["client", "native-tls", "rustls-tls", "openssl-tls", "derive", "ws", "oauth", "jsonpatch", "admission", "runtime", "k8s-openapi/v1_25"]
# Define the configuration attribute `docsrs`. Used to enable `doc_cfg` feature.
rustdoc-args = ["--cfg", "docsrs"]

Expand All @@ -44,7 +44,7 @@ kube-runtime = { path = "../kube-runtime", version = "=0.74.0", optional = true}
# Not used directly, but required by resolver 2.0 to ensure that the k8s-openapi dependency
# is considered part of the "deps" graph rather than just the "dev-deps" graph
[dependencies.k8s-openapi]
version = "0.15.0"
version = "0.16.0"
default-features = false

[dev-dependencies]
Expand All @@ -56,6 +56,6 @@ serde = { version = "1.0.130", features = ["derive"] }
schemars = "0.8.6"

[dev-dependencies.k8s-openapi]
version = "0.15.0"
version = "0.16.0"
default-features = false
features = ["v1_24"]
features = ["v1_25"]
16 changes: 9 additions & 7 deletions kube/src/lib.rs
Expand Up @@ -243,7 +243,6 @@ mod test {
.await?;
let establish = await_condition(crds.clone(), "foos.clux.dev", conditions::is_crd_established());
let _ = tokio::time::timeout(std::time::Duration::from_secs(10), establish).await?;

// Use it
let foos: Api<Foo> = Api::default_namespaced(client.clone());
// Apply from generated struct
Expand All @@ -270,29 +269,32 @@ mod test {
}
});
let o = foos.patch("baz", &ssapply, &Patch::Apply(patch)).await?;
assert_eq!(o.spec.replicas, 2);
assert_eq!(o.spec.replicas, 2, "patching spec updated spec.replicas");
}
// check subresource
{
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
let scale = foos.get_scale("baz").await?;
assert_eq!(scale.spec.unwrap().replicas, Some(2));
let status = foos.get_status("baz").await?;
assert!(status.status.is_none(), "nothing has set status");
}
// set status subresource
{
let fs = serde_json::json!({"status": FooStatus { is_bad: false, replicas: 1 }});
let o = foos
.patch_status("baz", &Default::default(), &Patch::Merge(&fs))
.await?;
assert!(o.status.is_some());
assert!(o.status.is_some(), "status set after patch_status");
}
// set scale subresource
{
let fs = serde_json::json!({"spec": { "replicas": 3 }});
let o = foos
.patch_scale("baz", &Default::default(), &Patch::Merge(&fs))
.await?;
assert_eq!(o.status.unwrap().replicas, 1); // something needs to set the status for this
assert_eq!(o.spec.unwrap().replicas.unwrap(), 3); // what we asked for got updated
assert_eq!(o.status.unwrap().replicas, 1, "scale replicas got patched");
let linked_replicas = o.spec.unwrap().replicas.unwrap();
assert_eq!(linked_replicas, 3, "patch_scale updates linked spec.replicas");
}

// cleanup
Expand Down
4 changes: 2 additions & 2 deletions release.toml
Expand Up @@ -4,7 +4,7 @@
#
# 0. (optional) cargo release minor ; verify readme + changelog bumped; then git reset --hard
# 1. PUBLISH_GRACE_SLEEP=20 cargo release minor --execute
# 1X. - on failure: follow plan manually, cd into next dirs and publish insequence with cargo publish --features=k8s-openapi/v1_24
# 1X. - on failure: follow plan manually, cd into next dirs and publish insequence with cargo publish --features=k8s-openapi/v1_25
# 2. check consolidated commit
# 2X. - on failure: git commit --amend and insert version
# 3. ./scripts/release-post.sh
Expand All @@ -21,4 +21,4 @@ push = false
tag = false
# A Kubernetes version is normally supplied by the application consuming the library in the end.
# Since we don't have that when verifying, supply one ourselves.
enable-features = ["k8s-openapi/v1_24"]
enable-features = ["k8s-openapi/v1_25"]

0 comments on commit a65c249

Please sign in to comment.