-
-
Notifications
You must be signed in to change notification settings - Fork 325
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
Make Client configurable #540
Conversation
0a570c5
to
56735a0
Compare
96bf9b9
to
357938b
Compare
kube/src/client/mod.rs
Outdated
// Transform response body to `hyper::Body` and use type erased error to avoid type parameters. | ||
let service = MapResponseBodyLayer::new(|b| hyper::Body::wrap_stream(body::IntoStream::new(b))) | ||
.layer(service) | ||
.map_err(|e| e.into()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took me a few days to come up with this, but should be worth it. This change allows us to take advantage of the Tower ecosystem much more without introducing type parameters to Client
.
Shouldn't be a breaking change, but need to test more to make sure.
9505fcb
to
5d52d12
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great. just small philosophical comments. have not dug through the tls stuff much yet.
- Add `Config::native_tls_connector` and `Config::rustls_client_config` - Remove the requirement of having `native-tls` or `rustls-tls` enabled when `client` is enabled. Allow one, both or none. - When both, the default Service will use `native-tls` because of kube-rs#153. `rustls` can be still used with a custom client. Users will have an option to configure TLS at runtime. - When none, HTTP connector is used. - Note that `oauth` feature still requires tls feature. - Remove tls features from kube-runtime
Still a dependency of hyper-rustls, but we're not using tokio-rustls. Depend on rustls directly instead.
`config` + `native-tls`/`rustls-tls` can be used independently. For example, to create a simple HTTP client.
Allow using more from the Tower ecosystem.
Keeping this simple for now by default, but it's fully customizable.
- Move TLS methods to `ConfigExt` - Prepare to move `Auth` method to `ConfigExt` - `.option_layer(config.auth_layer()?)`
709d605
to
614c7c4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks amazing. Huge work 💯
Had another go over. TLS looks all great, good error handling everywhere, docs everywhere, things with TODOs are all pub(crate).
Left (another) philosiphical naming nit, but beyond this I am all good with this.
/// Extensions to [`Config`](crate::Config) for custom [`Client`](crate::Client). | ||
/// | ||
/// See [`Client::new`](crate::Client::new) for an example. | ||
/// | ||
/// This trait is sealed and cannot be implemented. | ||
pub trait ConfigExt: private::Sealed { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know about this pattern, but am a fan. Feels like a very smart way to avoid having all the public methods in a big namespace 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the downside is the extra import, but I think the explicit kube::client::ConfigExt
actually makes sense for this. I also wanted to keep client stuff out of the config module.
I'll leave it to you to make the final call on naming, and will make a release after you merge this :-) |
Release in 0.56.0! Thank you so much! |
Customize client with Layers:
Customize
HttpsConnector
:It's also possible to create
HttpsConnector
fromTlsConnector
:TLS Enhancements
kube::client::ConfigExt
extendingConfig
for customClient
. This includes methods to configure TLS connection when building a custom client (Make Client configurable with Layers #539)native-tls
:Config::native_tls_https_connector
andConfig::native_tls_connector
rustls-tls
:Config::rustls_https_connector
andConfig::rustls_client_config
native-tls
orrustls-tls
enabled whenclient
is enabled. Allow one, both or none.native-tls
because of rustls cannot reach a cluster through ip #153.rustls
can be still used with a custom client. Users will have an option to configure TLS at runtime.kube-runtime
client
feature fromnative-tls
andrust-tls
featuresconfig
+native-tls
/rustls-tls
can be used independently, e.g., to create a simple HTTP clientclient
feature must be added ifdefault-features = false
Layers
ConfigExt::base_uri_layer
(BaseUriLayer
) to set cluster URL (Make Client configurable with Layers #539)ConfigExt::auth_layer
that returns optional layer to manageAuthorization
header (Make Client configurable with Layers #539)gzip
: Replaced custom decompression module withDecompressionLayer
fromtower-http
(Make Client configurable with Layers #539)LogRequest
withTraceLayer
fromtower-http
(Make Client configurable with Layers #539)AddAuthorizationLayer
(borrowing from AddAddAuthorization
middleware tower-rs/tower-http#95 until released)Changes
headers
fromConfig
. It was originally added to allow injecting arbitrary headers, but now a custom client can be used to do that.Dependency Changes
static_assertions
since it's no longer usedtokio_rustls
withrustls
andwebpki
since we're not usingtokio_rustls
directlyrustls::internal::pemfile
withrustls-pemfile
url
and always usehttp::Uri
Config::cluster_url
is nowhttp::Uri
Error::InternalUrlError(url::ParseError)
andError::MalformedUrl(url::ParseError)
replaced byError::InvalidUri(http::uri::InvalidUri)
Closes #539