Skip to content

Commit

Permalink
Avoid special Config::incluster behavior for rustls (#1184)
Browse files Browse the repository at this point in the history
* Revert special `Config::incluster` behavior for `rustls`

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

* minor doc updates

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

* typo fix - closes #1175

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

---------

Signed-off-by: clux <sszynrae@gmail.com>
  • Loading branch information
clux committed Apr 5, 2023
1 parent 5914164 commit 36dcdaa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 21 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ A low level streaming interface (similar to informers) that presents `Applied`,

```rust
let api = Api::<Pod>::default_namespaced(client);
let stream = watcher(api, ListParams::default()).applied_objects();
let stream = watcher(api, Config::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.
Expand All @@ -112,15 +112,15 @@ while let Some(event) = stream.try_next().await? {
}
```

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`.
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`](https://docs.rs/kube/latest/kube/runtime/trait.WatchStreamExt.html), 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::all(client);
let lp = ListParams::default().labels("kubernetes.io/arch=amd64");
let lp = Config::default().labels("kubernetes.io/arch=amd64");
let (reader, writer) = reflector::store();
let rf = reflector(writer, watcher(nodes, lp));
```
Expand All @@ -132,8 +132,8 @@ At this point you can listen to the `reflector` as if it was a `watcher`, but yo
A `Controller` is a `reflector` along with an arbitrary number of watchers that schedule events internally to send events through a reconciler:

```rust
Controller::new(root_kind_api, ListParams::default())
.owns(child_kind_api, ListParams::default())
Controller::new(root_kind_api, Config::default())
.owns(child_kind_api, Config::default())
.run(reconcile, error_policy, context)
.for_each(|res| async move {
match res {
Expand All @@ -148,15 +148,15 @@ Here `reconcile` and `error_policy` refer to functions you define. The first wil

## Rustls

Kube has basic support ([with caveats](https://github.com/kube-rs/kube/issues?q=is%3Aopen+is%3Aissue+label%3Arustls)) for [rustls](https://github.com/ctz/rustls) as a replacement for the `openssl` dependency. To use this, turn off default features, and enable `rustls-tls`:
By default `openssl` is used for TLS, but [rustls](https://github.com/ctz/rustls) is supported. To switch, turn off `default-features`, and enable the `rustls-tls` feature:

```toml
[dependencies]
kube = { version = "0.80.0", default-features = false, features = ["client", "rustls-tls"] }
k8s-openapi = { version = "0.17.0", features = ["v1_26"] }
```

This will pull in `rustls` and `hyper-rustls`.
This will pull in `rustls` and `hyper-rustls`. If `default-features` is left enabled, you will pull in two TLS stacks, and the default will remain as `openssl`.

## musl-libc

Expand Down
14 changes: 1 addition & 13 deletions kube-client/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,20 +208,8 @@ impl Config {

/// Load an in-cluster Kubernetes client configuration using
/// [`Config::incluster_env`].
///
/// # Rustls-specific behavior
/// Rustls does not support validating IP addresses (see
/// <https://github.com/kube-rs/kube/issues/1003>).
/// To work around this, when rustls is configured, this function automatically appends
/// `tls-server-name = "kubernetes.default.svc"` to the resulting configuration.
/// Overriding or unsetting `Config::tls_server_name` will avoid this behaviour.
pub fn incluster() -> Result<Self, InClusterError> {
let mut cfg = Self::incluster_env()?;
if cfg!(all(not(feature = "openssl-tls"), feature = "rustls-tls")) {
// openssl takes precedence when both features present, so only do it when only rustls is there
cfg.tls_server_name = Some("kubernetes.default.svc".to_string());
}
Ok(cfg)
Self::incluster_env()
}

/// Load an in-cluster config using the `KUBERNETES_SERVICE_HOST` and
Expand Down
2 changes: 1 addition & 1 deletion kube-runtime/src/controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub struct Action {
}

impl Action {
/// Action to to the reconciliation at this time even if no external watch triggers hit
/// Action to the reconciliation at this time even if no external watch triggers hit
///
/// This is the best-practice action that ensures eventual consistency of your controller
/// even in the case of missed changes (which can happen).
Expand Down

0 comments on commit 36dcdaa

Please sign in to comment.