Skip to content

Commit

Permalink
Merge branch 'master' into ver/await-condition-value
Browse files Browse the repository at this point in the history
  • Loading branch information
olix0r committed May 15, 2022
2 parents 298c53b + 0f19c8b commit 92c7744
Show file tree
Hide file tree
Showing 79 changed files with 1,402 additions and 696 deletions.
8 changes: 6 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,18 @@ RUN scurl https://raw.githubusercontent.com/rancher/k3d/main/install.sh \
RUN rustup component add clippy rls rust-src rustfmt

# Install cargo-deny
ARG CARGO_DENY_VERSION=0.11.0
ARG CARGO_DENY_VERSION=0.11.4
RUN scurl "https://github.com/EmbarkStudios/cargo-deny/releases/download/${CARGO_DENY_VERSION}/cargo-deny-${CARGO_DENY_VERSION}-x86_64-unknown-linux-musl.tar.gz" \
| tar zvxf - --strip-components=1 -C $HOME/bin "cargo-deny-${CARGO_DENY_VERSION}-x86_64-unknown-linux-musl/cargo-deny"

# Install cargo-tarpaulin
ARG CARGO_TARPAULIN_VERSION=0.18.5
ARG CARGO_TARPAULIN_VERSION=0.20.0
RUN scurl "https://github.com/xd009642/tarpaulin/releases/download/${CARGO_TARPAULIN_VERSION}/cargo-tarpaulin-${CARGO_TARPAULIN_VERSION}-travis.tar.gz" \
| tar xzvf - -C $HOME/bin

ARG JUST_VERSION=1.1.3
RUN scurl https://github.com/casey/just/releases/download/${JUST_VERSION}/just-${JUST_VERSION}-x86_64-unknown-linux-musl.tar.gz \
| tar xzvf - -C $HOME/bin

ENTRYPOINT ["/usr/local/share/docker-init.sh"]
CMD ["sleep", "infinity"]
1 change: 0 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

// These extensions are loaded for all users by default.
"extensions": [
"DavidAnson.vscode-markdownlint",
"matklad.rust-analyzer",
"NathanRidley.autotrim",
"samverschueren.final-newline",
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ jobs:
- name: Test crd_derive_no_schema example
run: cargo test -p kube-examples --example crd_derive_no_schema --no-default-features --features=openssl-tls,latest
if: matrix.os == 'ubuntu-latest'
- name: Test crd_api example with deprecated crd
run: cargo test -p kube-examples --example crd_api --no-default-features --features=deprecated,kubederive,openssl-tls
if: matrix.os == 'ubuntu-latest'

check-msrv:
# Run `cargo check` on our minimum supported Rust version
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jobs:
with:
version: '0.18.5'
out-type: Xml
- uses: codecov/codecov-action@v2
- uses: codecov/codecov-action@v3
54 changes: 52 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,57 @@
<!-- next-header -->
UNRELEASED
===================
* see https://github.com/kube-rs/kube-rs/compare/0.71.0...master
* see https://github.com/kube-rs/kube-rs/compare/0.72.0...master

[0.72.0](https://github.com/kube-rs/kube-rs/releases/tag/0.72.0) / 2022-05-13
===================

## Highlights
### Ergonomics improvements
A new [`runtime::WatchSteamExt`](https://docs.rs/kube/latest/kube/runtime/trait.WatchStreamExt.html) ([#899](https://github.com/kube-rs/kube-rs/pull/899) + [#906](https://github.com/kube-rs/kube-rs/pull/906)) allows for simpler setups for streams from [`watcher`](https://docs.rs/kube/latest/kube/runtime/fn.watcher.html) or [`reflector`](https://docs.rs/kube/latest/kube/runtime/fn.reflector.html).

```diff
- let stream = utils::try_flatten_applied(StreamBackoff::new(watcher(api, lp), b));
+ let stream = watcher(api, lp).backoff(b).applied_objects();
```

The `util::try_flatten_*` helpers have been marked as deprecated since they are not used by the stream impls.

A new [`reflector:store()`](https://docs.rs/kube/latest/kube/runtime/reflector/fn.store.html) fn allows simpler reflector setups [#907](https://github.com/kube-rs/kube-rs/pull/907):

```diff
- let store = reflector::store::Writer::<Node>::default();
- let reader = store.as_reader();
+ let (reader, writer) = reflector::store();
```

Additional conveniences getters/settes to [`ResourceExt`](https://docs.rs/kube/latest/kube/trait.ResourceExt.html) for manged_fields and creation_timestamp [#888](https://github.com/kube-rs/kube-rs/pull/888) + [#898](https://github.com/kube-rs/kube-rs/pull/898), plus a [`GroupVersion::with_kind`](https://docs.rs/kube/latest/kube/core/struct.GroupVersion.html#method.with_kind) path to a GVK, and a [`TryFrom<TypeMeta> for GroupVersionKind`](https://docs.rs/kube/latest/kube/core/struct.GroupVersionKind.html#impl-TryFrom%3CTypeMeta%3E) in [#896](https://github.com/kube-rs/kube-rs/pull/896).

### CRD Version Selection
Managing multiple [version in CustomResourceDefinitions](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definition-versioning/) can be pretty complicated, but we now have helpers and docs on how to tackle it.

A new function [`kube::core::crd::merge_crds`](https://docs.rs/kube/latest/kube/core/crd/fn.merge_crds.html) have been added (in [#889](https://github.com/kube-rs/kube-rs/pull/889)) to help push crd schemas generated by kube-derived crds with different `#[kube(version)]` properties. See the [kube-derive#version](https://docs.rs/kube/latest/kube/derive.CustomResource.html#versioning) documentation for details.

A new example showcases [how one can manage two or more versions of a crd](https://github.com/kube-rs/kube-rs/blob/7715cabd4d1976493e6b8949471f283df927a79e/examples/crd_derive_multi.rs#L12-L31) and what the expected truncation outcomes are when moving between versions.

### Examples
Examples now have moved to `tracing` for its logging, respects `RUST_LOG`, and namespace selection via the kubeconfig context. There is also a [larger kubectl example](https://github.com/kube-rs/kube-rs/blob/master/examples/kubectl.rs) showcasing [`kubectl apply -f yaml`](https://github.com/kube-rs/kube-rs/blob/7715cabd4d1976493e6b8949471f283df927a79e/examples/kubectl.rs#L149-L170) as well as `kubectl {edit,delete,get,watch}` via [#885](https://github.com/kube-rs/kube-rs/pull/885) + [#897](https://github.com/kube-rs/kube-rs/pull/897).

## What's Changed
### Added
* Allow merging multi-version CRDs into a single schema by @clux in https://github.com/kube-rs/kube-rs/pull/889
* Add GroupVersion::with_kind and TypeMeta -> GroupVersionKind converters by @clux in https://github.com/kube-rs/kube-rs/pull/896
* Add managed_fields accessors to ResourceExt by @clux in https://github.com/kube-rs/kube-rs/pull/898
* Add ResourceExt::creation_timestamp by @clux in https://github.com/kube-rs/kube-rs/pull/888
* Support lowercase http_proxy & https_proxy evars by @DevineLiu in https://github.com/kube-rs/kube-rs/pull/892
* Add a WatchStreamExt trait for stream chaining by @clux in https://github.com/kube-rs/kube-rs/pull/899
* Add Event::modify + reflector::store helpers by @clux in https://github.com/kube-rs/kube-rs/pull/907
### Changed
* Switch to kubernetes cluster dns for incluster url everywhere by @clux in https://github.com/kube-rs/kube-rs/pull/876
* Update tower-http requirement from 0.2.0 to 0.3.2 by @dependabot in https://github.com/kube-rs/kube-rs/pull/893
### Removed
* Remove deprecated legacy crd v1beta1 by @clux in https://github.com/kube-rs/kube-rs/pull/890


[0.71.0](https://github.com/kube-rs/kube-rs/releases/tag/0.71.0) / 2022-04-12
===================
Expand All @@ -19,7 +69,7 @@ We highlight some **changes** here that you should be especially aware of.
Publishing events via [Recorder](https://docs.rs/kube/latest/kube/runtime/events/struct.Recorder.html) for cluster scoped resources (supported since `0.70.0`) now publish to `kube-system` rather than `default`, as all but the newest clusters struggle with publishing events in the `default` namespace.

### [Default TLS stack set to OpenSSL](https://github.com/kube-rs/kube-rs/pull/863)
The previous `native-tls` default was there because we used to depend on `reqwest`, but because we depended on openssl anyway the feature does not make much sense. Changing to `openssl-tls` also improves the situation on macOS where the Security Framework struggles with PKCS#12 certs from OpenSSL v3. The `native-tls` feature will still be available in this release in case of issues, but the plan is to decommission it shortly. Of course, we all ideally want to move to rustls, but we are still blocked by #153.
The previous `native-tls` default was there because we used to depend on `reqwest`, but because we depended on openssl anyway the feature does not make much sense. Changing to `openssl-tls` also improves the situation on macOS where the Security Framework struggles with PKCS#12 certs from OpenSSL v3. The `native-tls` feature will still be available in this release in case of issues, but the plan is to decommission it shortly. Of course, we all ideally want to move to rustls, but we are still blocked by [#153](https://github.com/kube-rs/kube-rs/issues/153).

## What's Changed
### Added
Expand Down
14 changes: 7 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md).
## Rust Guidelines

- **Channel**: Code is built and tested using the **stable** channel of Rust, but documented and formatted with **nightly** <sup>[*](https://github.com/kube-rs/kube-rs/issues/707)</sup>
- **Formatting**: To format the codebase, run `make fmt`
- **Documentation** To check documentation, run `make doc`
- **Testing**: To run tests, run `make test` and see below.
- **Formatting**: To format the codebase, run `just fmt`
- **Documentation** To check documentation, run `just doc`
- **Testing**: To run tests, run `just test` and see below.

For a list of tooling that we glue together everything see [TOOLS.md](https://kube.rs/tools/).

Expand All @@ -41,13 +41,13 @@ We have 3 classes of tests.

The last two will try to access the Kubernetes cluster that is your `current-context`; i.e. via your local `KUBECONFIG` evar or `~/.kube/config` file.

The easiest way set up a minimal Kubernetes cluster for these is with [`k3d`](https://k3d.io/) (`make k3d`).
The easiest way set up a minimal Kubernetes cluster for these is with [`k3d`](https://k3d.io/) (`just k3d`).

### Unit Tests & Documentation Tests

**Most** unit/doc tests are run from `cargo test --lib --doc --all`, but because of feature-sets, and examples, you will need a couple of extra invocations to replicate our CI.

For the complete variations, run the `make test` target in the `Makefile`.
For the complete variations, run the `just test` target in the `justfile`.

All public interfaces must be documented, and most should have minor documentation examples to show usage.

Expand All @@ -57,15 +57,15 @@ Slower set of tests within the crates marked with an **`#[ignore]`** attribute.

:warning: These **WILL** try to modify resources in your current cluster :warning:

Most integration tests are run with `cargo test --all --lib -- --ignored`, but because of feature-sets, you will need a few invocations of these to replicate our CI. See `make test-integration`
Most integration tests are run with `cargo test --all --lib -- --ignored`, but because of feature-sets, you will need a few invocations of these to replicate our CI. See `just test-integration`

### End to End Tests

We have a small set of [e2e tests](https://github.com/kube-rs/kube-rs/tree/master/e2e) that tests difference between in-cluster and local configuration.

These tests are the heaviest tests we have because they require a full `docker build`, image import (or push/pull flow), yaml construction, and `kubectl` usage to verify that the outcome was sufficient.

To run E2E tests, use (or follow) `make e2e` as appropriate.
To run E2E tests, use (or follow) `just e2e` as appropriate.

### Test Guidelines

Expand Down
71 changes: 0 additions & 71 deletions Makefile

This file was deleted.

49 changes: 23 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Select a version of `kube` along with the generated [k8s-openapi](https://github

```toml
[dependencies]
kube = { version = "0.71.0", features = ["runtime", "derive"] }
k8s-openapi = { version = "0.14.0", features = ["v1_22"] }
kube = { version = "0.72.0", features = ["runtime", "derive"] }
k8s-openapi = { version = "0.14.0", features = ["v1_23"] }
```

[Features are available](https://github.com/kube-rs/kube-rs/blob/master/kube/Cargo.toml#L18).
Expand Down Expand Up @@ -47,15 +47,15 @@ The [`Api`](https://docs.rs/kube/*/kube/struct.Api.html) is what interacts with

```rust
use k8s_openapi::api::core::v1::Pod;
let pods: Api<Pod> = Api::namespaced(client, "apps");
let pods: Api<Pod> = Api::default_namespaced(client);

let p = pods.get("blog").await?;
println!("Got blog pod with containers: {:?}", p.spec.unwrap().containers);

let patch = json!({"spec": {
"activeDeadlineSeconds": 5
}});
let pp = PatchParams::apply("my_controller");
let pp = PatchParams::apply("kube");
let patched = pods.patch("blog", &pp, &Patch::Apply(patch)).await?;
assert_eq!(patched.spec.active_deadline_seconds, Some(5));

Expand All @@ -72,20 +72,20 @@ You need to `#[derive(CustomResource)]` and some `#[kube(attrs..)]` on a spec st

```rust
#[derive(CustomResource, Debug, Serialize, Deserialize, Default, Clone, JsonSchema)]
#[kube(group = "clux.dev", version = "v1", kind = "Foo", namespaced)]
pub struct FooSpec {
name: String,
info: String,
#[kube(group = "kube.rs", version = "v1", kind = "Document", namespaced)]
pub struct DocumentSpec {
title: String,
content: String,
}
```

Then you can use the generated wrapper struct `Foo` as a [`kube::Resource`](https://docs.rs/kube/*/kube/trait.Resource.html):
Then you can use the generated wrapper struct `Document` as a [`kube::Resource`](https://docs.rs/kube/*/kube/trait.Resource.html):

```rust
let foos: Api<Foo> = Api::namespaced(client, "default");
let f = Foo::new("my-foo", FooSpec::default());
println!("foo: {:?}", f);
println!("crd: {:?}", serde_yaml::to_string(&Foo::crd()));
let docs: Api<Document> = Api::default_namespaced(client);
let d = Document::new("guide", DocumentSpec::default());
println!("doc: {:?}", d);
println!("crd: {:?}", serde_yaml::to_string(&Document::crd()));
```

There are a ton of kubebuilder-like instructions that you can annotate with here. See the [documentation](https://docs.rs/kube/latest/kube/derive.CustomResource.html) or the `crd_` prefixed [examples](https://github.com/kube-rs/kube-rs/blob/master/examples) for more.
Expand All @@ -101,32 +101,29 @@ The `runtime` module exports the `kube_runtime` crate and contains higher level
A low level streaming interface (similar to informers) that presents `Applied`, `Deleted` or `Restarted` events.

```rust
let api = Api::<Pod>::namespaced(client, "default");
let watcher = watcher(api, ListParams::default());
let api = Api::<Pod>::default_namespaced(client);
let stream = watcher(api, ListParams::default()).applied_objects();
```

This now gives a continual stream of events and you do not need to care about the watch having to restart, or connections dropping.

```rust
let mut apply_events = try_flatten_applied(watcher).boxed_local();
while let Some(event) = apply_events.try_next().await? {
while let Some(event) = stream.try_next().await? {
println!("Applied: {}", event.name());
}
```

NB: the plain stream items a `watcher` returns are different from `WatchEvent`. If you are following along to "see what changed", you should flatten it with one of the utilities like `try_flatten_applied` or `try_flatten_touched`.
NB: the plain items in a `watcher` stream are different from `WatchEvent`. If you are following along to "see what changed", you should flatten it with one of the utilities from `WatchStreamExt`, such as `applied_objects`.

## Reflectors

A `reflector` is a `watcher` with `Store` on `K`. It acts on all the `Event<K>` exposed by `watcher` to ensure that the state in the `Store` is as accurate as possible.

```rust
let nodes: Api<Node> = Api::namespaced(client, &namespace);
let lp = ListParams::default()
.labels("beta.kubernetes.io/instance-type=m4.2xlarge");
let store = reflector::store::Writer::<Node>::default();
let reader = store.as_reader();
let rf = reflector(store, watcher(nodes, lp));
let nodes: Api<Node> = Api::all(client);
let lp = ListParams::default().labels("kubernetes.io/arch=amd64");
let (reader, writer) = reflector::store();
let rf = reflector(writer, watcher(nodes, lp));
```

At this point you can listen to the `reflector` as if it was a `watcher`, but you can also query the `reader` at any point.
Expand Down Expand Up @@ -156,8 +153,8 @@ Kube has basic support ([with caveats](https://github.com/kube-rs/kube-rs/issues

```toml
[dependencies]
kube = { version = "0.71.0", default-features = false, features = ["client", "rustls-tls"] }
k8s-openapi = { version = "0.14.0", features = ["v1_22"] }
kube = { version = "0.72.0", default-features = false, features = ["client", "rustls-tls"] }
k8s-openapi = { version = "0.14.0", features = ["v1_23"] }
```

This will pull in `rustls` and `hyper-rustls`.
Expand Down
4 changes: 2 additions & 2 deletions e2e/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ path = "dapp.rs"
anyhow = "1.0.44"
env_logger = "0.9.0"
futures = "0.3.17"
kube = { path = "../kube", version = "^0.71.0", default-features = false, features = ["client", "rustls-tls"] }
k8s-openapi = { version = "0.14.0", features = ["v1_22"], default-features = false }
kube = { path = "../kube", version = "^0.72.0", default-features = false, features = ["client", "rustls-tls"] }
k8s-openapi = { version = "0.14.0", features = ["v1_23"], default-features = false }
log = "0.4.11"
serde_json = "1.0.68"
tokio = { version = "1.14.0", features = ["full"] }
4 changes: 2 additions & 2 deletions e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ General process, optimized for time.
It's successful if the app exits successfully, without encountering errors.

### Running
Start a cluster first, e.g. `make k3d`.
Start a cluster first, e.g. `just k3d`.

Run `make integration` to cross compile `dapp` with `muslrust` locally using the same docker image, and then deploy it to the current active cluster.
Run `just integration` to cross compile `dapp` with `muslrust` locally using the same docker image, and then deploy it to the current active cluster.
Loading

0 comments on commit 92c7744

Please sign in to comment.