Skip to content

Commit

Permalink
Merge pull request #413 from sarub0b0/retry-resume-logs
Browse files Browse the repository at this point in the history
Support retry and resume for log streaming
  • Loading branch information
sarub0b0 authored Oct 22, 2023
2 parents 6657544 + ec933a2 commit cb9e002
Show file tree
Hide file tree
Showing 12 changed files with 699 additions and 862 deletions.
63 changes: 1 addition & 62 deletions cspell.json
Original file line number Diff line number Diff line change
@@ -1,62 +1 @@
{
"words": [
"ratatui",
"crossterm",
"kubetui",
"Atext",
"multispace",
"nums",
"arboard",
"kohashimoto",
"kubeconfig",
"hoge",
"rstest",
"thiserror",
"openapi",
"Kubeconfig",
"indoc",
"apimachinery",
"horizontalpodautoscalers",
"mockall",
"configmap",
"chrono",
"networkpolicies",
"networkpolicy",
"serviceaccount",
"jdfbz",
"tolerations",
"pullable",
"fuga",
"coldef",
"Appender",
"logfile",
"appender",
"Fullscreen",
"activatable",
"rustfmt",
"tesat",
"tesatb",
"fullwidth",
"mabb",
"peekable",
"taskbox",
"ptimized",
"mhoge",
"oneline",
"maaaaaaaaaaaaaaa",
"impls",
"showable",
"mabc",
"HOGE",
"hogehoge",
"subwin",
"erde",
"rustls",
"taplo",
"kosay",
"serde"
],
"language": "en",
"version": "0.2",
"flagWords": []
}
{"language":"en","version":"0.2","words":["ratatui","crossterm","kubetui","Atext","multispace","nums","arboard","kohashimoto","kubeconfig","hoge","rstest","thiserror","openapi","Kubeconfig","indoc","apimachinery","horizontalpodautoscalers","mockall","configmap","chrono","networkpolicies","networkpolicy","serviceaccount","jdfbz","tolerations","pullable","fuga","coldef","Appender","logfile","appender","Fullscreen","activatable","rustfmt","tesat","tesatb","fullwidth","mabb","peekable","taskbox","ptimized","mhoge","oneline","maaaaaaaaaaaaaaa","impls","showable","mabc","HOGE","hogehoge","subwin","erde","rustls","taplo","kosay","serde","itertools"],"flagWords":[]}
2 changes: 2 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
force_multiline_blocks = true
imports_layout = "HorizontalVertical"
13 changes: 6 additions & 7 deletions src/event/kubernetes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use self::{
config::{ConfigMessage, ConfigsDataWorker},
context_message::{ContextMessage, ContextRequest, ContextResponse},
inner::Inner,
log::{LogHandlers, LogStreamMessage, LogWorkerBuilder},
log::{LogHandlers, LogStreamMessage, LogWorker},
namespace_message::{NamespaceMessage, NamespaceRequest, NamespaceResponse},
network::{NetworkDescriptionWorker, NetworkMessage},
worker::{PollWorker, Worker},
Expand Down Expand Up @@ -393,11 +393,8 @@ impl Worker for MainWorker {
handler.abort();
}

log_stream_handler = Some(
LogWorkerBuilder::new(tx, kube_client.clone(), namespace, name)
.build()
.spawn(),
);
log_stream_handler =
Some(LogWorker::new(tx, kube_client.clone(), namespace, name).spawn());

task::yield_now().await;
}
Expand Down Expand Up @@ -1016,7 +1013,9 @@ mod kube_store {
});

let user = auth_infos.iter().find_map(|auth_info| {
let Some(kube::config::Context{ref user, ..}) = context.context else {return None};
let Some(kube::config::Context { ref user, .. }) = context.context else {
return None;
};

if &auth_info.name == user {
Some(auth_info.name.to_string())
Expand Down
2 changes: 1 addition & 1 deletion src/event/kubernetes/api_resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl Ord for ApiResource {

impl PartialOrd for ApiResource {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.to_string().partial_cmp(&other.to_string())
Some(self.cmp(other))
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/event/kubernetes/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ impl KubeClient {
&self.client
}

pub fn to_client(&self) -> Client {
self.client.clone()
}

#[allow(dead_code)]
pub fn as_server_url(&self) -> &String {
&self.server_url
Expand Down
41 changes: 40 additions & 1 deletion src/event/kubernetes/color.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,43 @@
const COLOR: [u8; 6] = [32, 33, 34, 35, 36, 37];
pub mod fg {

#[allow(dead_code)]
#[derive(Clone, Copy)]
pub enum Color {
Reset = 39,

Red = 31,
Green = 32,
Yellow = 33,
Blue = 34,
Magenta = 35,
Cyan = 36,
Gray = 37,

DarkGray = 90,
LightRed = 91,
LightGreen = 92,
LightYellow = 93,
LightBlue = 94,
LightMagenta = 95,
LightCyan = 96,
White = 97,
}

impl Color {
pub fn wrap(&self, s: impl Into<String>) -> String {
format!("\x1b[{}m{}\x1b[39m", *self as u8, s.into())
}
}
}

const COLOR: [u8; 6] = [
fg::Color::Green as u8,
fg::Color::Yellow as u8,
fg::Color::Blue as u8,
fg::Color::Magenta as u8,
fg::Color::Cyan as u8,
fg::Color::Gray as u8,
];

pub struct Color {
index: usize,
Expand Down
Loading

0 comments on commit cb9e002

Please sign in to comment.