-
-
Notifications
You must be signed in to change notification settings - Fork 328
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
Pod logs operation #50
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0fdb60e
add pod log operation
f223599
Merge pull request #1 from liberwang1013/pod-logs
liberwang1013 46e8778
get pod name from arg
5a78ae2
Merge pull request #2 from liberwang1013/pod-arg
liberwang1013 259587e
move log function to a new impl RawApi block
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#[macro_use] | ||
extern crate log; | ||
|
||
use kube::{ | ||
api::{Api, Log, LogParams}, | ||
client::APIClient, | ||
config, | ||
}; | ||
use std::env; | ||
|
||
fn main() -> Result<(), failure::Error> { | ||
std::env::set_var("RUST_LOG", "info,kube=trace"); | ||
env_logger::init(); | ||
let config = config::load_kube_config().expect("failed to load kubeconfig"); | ||
let client = APIClient::new(config); | ||
|
||
let mypod = match env::args().nth(1) { | ||
Some(pod) => pod, | ||
None => { | ||
println!("Usage: log_openapi <pod>"); | ||
return Ok(()); | ||
} | ||
}; | ||
|
||
// Manage pods | ||
let pods = Api::v1Pod(client);; | ||
let lp = LogParams::default(); | ||
let plog = pods.within("default").log(&mypod, &lp)?; | ||
println!("Got pod {} log: {}", &mypod, &plog); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,8 @@ use crate::api::{ | |
PostParams, | ||
DeleteParams, | ||
ListParams, | ||
PatchParams | ||
PatchParams, | ||
LogParams | ||
}; | ||
use crate::api::resource::{ | ||
ObjectList, Object, WatchEvent, KubeObject, | ||
|
@@ -41,6 +42,16 @@ pub struct Api<K> { | |
pub(in crate::api) phantom: PhantomData<K>, | ||
} | ||
|
||
pub trait LogOperation { | ||
fn log_operation(&self, name: &str, lp: &LogParams) -> Result<String>; | ||
} | ||
|
||
pub trait Log: LogOperation { | ||
fn log(&self, name: &str, lp: &LogParams) -> Result<String> { | ||
Ok(self.log_operation(name, lp)?) | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a nice setup between private and public methods that looks like it allows you to very easily implement the Log trait. Cool pattern. Unfortunately, if you follow do my suggestion, this won't be needed. |
||
|
||
/// Expose same interface as Api for controlling scope/group/versions/ns | ||
impl<K> Api<K> { | ||
pub fn within(mut self, ns: &str) -> Self { | ||
|
@@ -107,6 +118,15 @@ impl<K> Api<K> where | |
} | ||
} | ||
|
||
impl<K> LogOperation for Api<K> where | ||
K: Clone + DeserializeOwned + KubeObject | ||
{ | ||
fn log_operation(&self, name: &str, lp: &LogParams) -> Result<String> { | ||
let req = self.api.log(name, lp)?; | ||
self.client.request_text(req) | ||
} | ||
} | ||
|
||
/// Scale spec from api::autoscaling::v1 | ||
#[derive(Deserialize, Serialize, Clone, Debug)] | ||
pub struct ScaleSpec { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Rather than having a one line impl for one resource object that every user would need to import the trait of, could we instead:
log
always public butunimplemented!()
or{}
by defaultimpl Api<Object<PodSpec, PodStatus>>
that overrideslog
Then you have one less import required for users.
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 implements log operation in this way, because I hope
trait Log
can be reused by other developers when they implement their crds.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, that makes sense. Either way is fine, it would just be easier for users of the Api to not have to import the extra trait.