Skip to content
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

Change Client::new to take Service #400

Merged
merged 1 commit into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions examples/pod_reflector.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use color_eyre::Result;
use futures::prelude::*;
use k8s_openapi::api::core::v1::Pod;
use kube::{api::ListParams, Api, Client, Config};
use kube::{api::ListParams, Api, Client};
use kube_runtime::{reflector, watcher};

#[tokio::main]
async fn main() -> Result<()> {
let config = Config::infer().await?;
let client = Client::new(config);
let client = Client::try_default().await?;
let namespace = std::env::var("NAMESPACE").unwrap_or("default".into());

let api: Api<Pod> = Api::namespaced(client, &namespace);
Expand Down
19 changes: 5 additions & 14 deletions kube/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,16 @@ use std::convert::{TryFrom, TryInto};
/// The best way to instantiate the client is either by
/// inferring the configuration from the environment using
/// [`Client::try_default`] or with an existing [`Config`]
/// using [`Client::new`]
/// using [`Client::try_from`].
#[derive(Clone)]
pub struct Client {
inner: Service,
}

impl Client {
// TODO Change this to take `Service` instead after figuring out `auth_header`.
/// Create and initialize a [`Client`] using the given
/// configuration.
///
/// # Panics
///
/// Panics if the configuration supplied leads to an invalid TlsConnector.
/// If you want to handle this error case use [`Config::try_from`](Self::try_from)
/// (note that this requires [`std::convert::TryFrom`] to be in scope.)
pub fn new(config: Config) -> Self {
Self::try_from(config).expect("Could not create a client from the supplied config")
/// Create and initialize a [`Client`] using the given `Service`.
pub fn new(service: Service) -> Self {
Self { inner: service }
}

/// Create and initialize a [`Client`] using the inferred
Expand Down Expand Up @@ -359,8 +351,7 @@ impl TryFrom<Config> for Client {

/// Convert [`Config`] into a [`Client`]
fn try_from(config: Config) -> Result<Self> {
let inner = config.try_into()?;
Ok(Self { inner })
Ok(Self::new(config.try_into()?))
}
}

Expand Down