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

起動に失敗しているpodのログを取得しようとしたとき関連するイベント情報を出力する #90

Merged
merged 15 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
282dd87
feat(event) Resultをanyhowクレートのものに変更
sarub0b0 Jul 19, 2021
c5aac80
feat(event::kube::log) colorからIteraterを削除し、next_color関数に置き換えた
sarub0b0 Jul 19, 2021
66e944a
feat(example): コンテナ起動中のログ出力に関するサンプルマニフェストを作成
sarub0b0 Aug 17, 2021
cda786c
feat: ログ取得時にコンテナ起動するまで待機し、エラー時はイベント情報を取得・表示する機能などを実装
sarub0b0 Sep 20, 2021
b9b9566
clippy
sarub0b0 Sep 20, 2021
ecf2318
feat(event/k8s): Handlers構造体にderive(Default, Debug)を設定
sarub0b0 Sep 21, 2021
36b0eec
feat(event/k8s/log): LogWorker構造体ベースで処理を行う下地を実装
sarub0b0 Sep 21, 2021
7645e8f
feat(event/k8s/log): クラス化。エラーや出力を調整
sarub0b0 Sep 22, 2021
3bbc116
fix(event/k8s/log): ログの行頭に空白が入る不具合を修正
sarub0b0 Sep 22, 2021
6d0c54d
feat(event/k8s/log): initContainersが1つならログのプレフィックスに数字をつけないように変更
sarub0b0 Sep 22, 2021
94a76f9
feat(event/k8s/log): initContainersが1つでもあるならcontainersのログにプレフィックスをつける…
sarub0b0 Sep 22, 2021
1541533
feat(make): re-deployでエラーを許容するように変更。e2e-testの前にre-deployが走るように変更
sarub0b0 Sep 22, 2021
375c9af
refactor(event/k8s/log): new-log-streamフューチャーを削除。不要なコードを削除
sarub0b0 Sep 22, 2021
7ace720
refactor(event/k8s/log): terminated_description内の分岐を削除。引数でselectorをとる…
sarub0b0 Sep 22, 2021
d9c4130
feat(event/k8s/log): terminated_descriptionの出力をkubectl describeに近い形に変更
sarub0b0 Sep 22, 2021
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
291 changes: 175 additions & 116 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ edition = "2018"
members = [ "tui-wrapper", "event", "ansi", "clipboard-wrapper" ]

[features]
default = [ "logging" ]
logging = [ "log", "log4rs", "event/logging", "tui-wrapper/logging" ]
mock = [ "event/mock" ]
mock-failed = [ "event/mock-failed" ]
new-log-stream = [ "event/new-log-stream" ]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@


build:
cargo build ${FLAGS}

run:
cargo run ${FLAGS}

debug:
RUST_LOG=debug cargo run

e2e-test: build re-deploy
RUST_LOG=debug target/debug/kubetui
.PHONY: e2e-test

re-deploy:
-kubectl delete -f example/
-kubectl apply -f example/
4 changes: 4 additions & 0 deletions event/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ edition = "2018"
logging = [ "log" ]
mock = []
mock-failed = [ "hyper" ]
new-log-stream = []

[dependencies]
crossterm = "0.19"
Expand All @@ -28,6 +29,9 @@ serde = { version = "1.0", features = ["derive"] }
log = { version = "0.4", optional = true }
hyper = { version = "0.14", optional = true }
thiserror = "1"
anyhow = "1"

async-trait = "0.1"

[dev-dependencies]
pretty_assertions = "0.7"
32 changes: 8 additions & 24 deletions event/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub type Result<R, E = Error> = std::result::Result<R, E>;
// pub type Result<R> = std::result::Result<R, Box<dyn std::error::Error>>;

use crossbeam::channel::{RecvError, SendError};
use std::fmt::{Debug, Display, Formatter};
pub use anyhow::anyhow;
pub use anyhow::Result;
use thiserror::Error as TError;

#[cfg(any(feature = "mock", feature = "mock-failed"))]
Expand All @@ -26,28 +26,12 @@ pub enum Error {
Raw(String),
#[error(transparent)]
IO(#[from] std::io::Error),
#[error(transparent)]
Pod(#[from] PodError),
}

#[derive(Debug, TError)]
pub enum CrossbeamError<T: Debug> {
Recv(RecvError),
Send(SendError<T>),
}

impl<T: Debug> Display for CrossbeamError<T> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self)
}
}

impl<T: Debug> From<SendError<T>> for CrossbeamError<T> {
fn from(e: SendError<T>) -> Self {
Self::Send(e)
}
}

impl<T: Debug> From<RecvError> for CrossbeamError<T> {
fn from(e: RecvError) -> Self {
Self::Recv(e)
}
pub enum PodError {
#[error("ContainerExitCodeNotZero: {0}")]
ContainerExitCodeNotZero(String, Vec<String>),
}
4 changes: 2 additions & 2 deletions event/src/kubernetes/api_resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ async fn get_all_api_info(client: &Client, server_url: &str) -> Result<Vec<APIIn
let job = try_join_all(
group_versions
.iter()
.map(|gv| api_resource_list_to_api_info_list(&client, server_url, gv)),
.map(|gv| api_resource_list_to_api_info_list(client, server_url, gv)),
)
.await?;

Expand Down Expand Up @@ -347,7 +347,7 @@ async fn get_api_resources(
continue;
}

ret.push(header_by_api_info(&info) + &table.to_print());
ret.push(header_by_api_info(info) + &table.to_print());
ret.push("".to_string());
}
}
Expand Down
14 changes: 7 additions & 7 deletions event/src/kubernetes/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use k8s_openapi::api::core::v1::{ConfigMap, Secret};

use kube::{Api, Client};

use crate::error::{Error, Result};
use crate::error::{anyhow, Error, Result};

#[derive(Clone, Copy)]
enum Configs {
Expand Down Expand Up @@ -39,9 +39,9 @@ async fn fetch_configs_per_namespace(
namespaces: &[String],
ty: Configs,
) -> Result<Vec<Vec<String>>> {
let insert_ns = insert_ns(&namespaces);
let insert_ns = insert_ns(namespaces);
let jobs = try_join_all(namespaces.iter().map(|ns| {
get_resourse_per_namespace(
get_resource_per_namespace(
client,
server_url,
format!("api/v1/namespaces/{}/{}", ns, ty.kind()),
Expand Down Expand Up @@ -123,7 +123,7 @@ pub async fn configs_loop(
pub async fn get_config(client: Client, ns: &str, kind: &str, name: &str) -> Result<Vec<String>> {
match kind {
"ConfigMap" => {
let cms: Api<ConfigMap> = Api::namespaced(client, &ns);
let cms: Api<ConfigMap> = Api::namespaced(client, ns);
let cm = cms.get(name).await?;
Ok(cm
.data
Expand All @@ -132,7 +132,7 @@ pub async fn get_config(client: Client, ns: &str, kind: &str, name: &str) -> Res
.collect())
}
"Secret" => {
let secs: Api<Secret> = Api::namespaced(client, &ns);
let secs: Api<Secret> = Api::namespaced(client, ns);
let sec = secs.get(name).await?;

Ok(sec
Expand All @@ -149,9 +149,9 @@ pub async fn get_config(client: Client, ns: &str, kind: &str, name: &str) -> Res
})
.collect())
}
_ => Err(Error::Raw(format!(
_ => Err(anyhow!(Error::Raw(format!(
"Invalid kind [{}]. Set kind ConfigMap or Secret",
kind
))),
)))),
}
}
6 changes: 3 additions & 3 deletions event/src/kubernetes/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ async fn get_event_table(
let insert_ns = insert_ns(namespaces);

let jobs = try_join_all(namespaces.iter().map(|ns| {
get_resourse_per_namespace(
&client,
&server_url,
get_resource_per_namespace(
client,
server_url,
format!("api/v1/namespaces/{}/{}", ns, "events"),
&TARGET,
move |row: &TableRow, indexes: &[usize]| {
Expand Down
Loading