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

Api::namespaced should work with default namespace #209

Closed
clux opened this issue Apr 1, 2020 · 4 comments · Fixed by #534
Closed

Api::namespaced should work with default namespace #209

clux opened this issue Apr 1, 2020 · 4 comments · Fixed by #534
Labels
api Api abstraction related client kube Client related

Comments

@clux
Copy link
Member

clux commented Apr 1, 2020

Currently the kube::Config picks up on the default namespace in two ways:

  • in cluster: SERVICE_DEFAULT_NS evar provided
  • local dev: context.namespace.unwrap_or("default")

Which can be passed onto the kube::Client so that Api::namsepaced and Resource::namespaced can omit this if they want a controller to run in the namespace they were deployed to.

@clux clux added api Api abstraction related client kube Client related labels Apr 1, 2020
@clux
Copy link
Member Author

clux commented Apr 1, 2020

This interplays with the planned api changes in #194.
But we could as a tempoary measure add:

  • Api::default_namespaced()

Slightly harder to do Resource::default_namespaced because the that information is on the kube::Client, but that's fine. Resource is a lower level API.

@clux
Copy link
Member Author

clux commented Apr 1, 2020

Actually, only doing one of them is awkward for the Informer init..

    let namespace = env::var("NAMESPACE").unwrap_or("default".into());
    let resource = Resource::namespaced::<Pod>(&namespace);
    let inf = Informer::new(client, ListParams::default(), resource);

We should probably move Informers and Reflectors to use Api rather than Resource, and not give it a Client. They don't need the lower-level API anyway.

@clux
Copy link
Member Author

clux commented Apr 1, 2020

Stashed diff:

diff --git kube/src/api/typed.rs kube/src/api/typed.rs
index 16d985e5..996479ea 100644
--- kube/src/api/typed.rs
+++ kube/src/api/typed.rs
@@ -53,6 +53,16 @@ where
             phantom: PhantomData,
         }
     }
+
+    /// Namespaced resource within the configured default namespace
+    pub fn default_namespaced(client: Client) -> Self {
+        let api = Resource::namespaced::<K>(&client.default_ns);
+        Self {
+            api,
+            client,
+            phantom: PhantomData,
+        }
+    }
 }
 
 /// PUSH/PUT/POST/GET abstractions
diff --git kube/src/client/mod.rs kube/src/client/mod.rs
index 8738c0f5..280a535f 100644
--- kube/src/client/mod.rs
+++ kube/src/client/mod.rs
@@ -65,7 +65,7 @@ pub struct Status {
 #[derive(Clone)]
 pub struct Client {
     cluster_url: reqwest::Url,
-    default_ns: String,
+    pub(crate) default_ns: String,
     inner: reqwest::Client,
 }
 

clux added a commit that referenced this issue Feb 11, 2021
@clux clux linked a pull request Feb 11, 2021 that will close this issue
@clux clux linked a pull request May 21, 2021 that will close this issue
@clux clux closed this as completed in #534 May 21, 2021
@clux
Copy link
Member Author

clux commented Jun 5, 2021

released in 0.56

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Api abstraction related client kube Client related
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant