-
-
Notifications
You must be signed in to change notification settings - Fork 85
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
Adding support for storageclass #222
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,11 @@ pub(crate) mod replicasets; | |
pub(crate) mod replication_controllers; | ||
pub(crate) mod secrets; | ||
pub(crate) mod statefulsets; | ||
pub(crate) mod storageclass; | ||
pub(crate) mod svcs; | ||
mod utils; | ||
|
||
use crate::app::storageclass::KubeStorageClass; | ||
use anyhow::anyhow; | ||
use kube::config::Kubeconfig; | ||
use kubectl_view_allocations::{GroupBy, QtyByQualifier}; | ||
|
@@ -69,6 +71,7 @@ pub enum ActiveBlock { | |
CronJobs, | ||
Secrets, | ||
RplCtrl, | ||
StorageClasses, | ||
More, | ||
} | ||
|
||
|
@@ -123,6 +126,7 @@ pub struct Data { | |
pub logs: LogsState, | ||
pub describe_out: ScrollableTxt, | ||
pub metrics: StatefulTable<(Vec<String>, Option<QtyByQualifier>)>, | ||
pub storageclasses: StatefulTable<KubeStorageClass>, | ||
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. move to line 125 for consistency plz |
||
} | ||
|
||
/// selected data items | ||
|
@@ -195,6 +199,7 @@ impl Default for Data { | |
logs: LogsState::new(String::default()), | ||
describe_out: ScrollableTxt::new(), | ||
metrics: StatefulTable::new(), | ||
storageclasses: StatefulTable::new(), | ||
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. move to line 192 plz |
||
} | ||
} | ||
} | ||
|
@@ -318,7 +323,7 @@ impl Default for App { | |
("Replication Controllers".into(), ActiveBlock::RplCtrl), | ||
// ("Persistent Volume Claims".into(), ActiveBlock::RplCtrl), | ||
// ("Persistent Volumes".into(), ActiveBlock::RplCtrl), | ||
// ("Storage Classes".into(), ActiveBlock::RplCtrl), | ||
("Storage Classes".into(), ActiveBlock::StorageClasses), | ||
// ("Roles".into(), ActiveBlock::RplCtrl), | ||
// ("Role Bindings".into(), ActiveBlock::RplCtrl), | ||
// ("Cluster Roles".into(), ActiveBlock::RplCtrl), | ||
|
@@ -515,6 +520,7 @@ impl App { | |
self.dispatch(IoEvent::GetCronJobs).await; | ||
self.dispatch(IoEvent::GetSecrets).await; | ||
self.dispatch(IoEvent::GetReplicationControllers).await; | ||
self.dispatch(IoEvent::GetStorageClasses).await; | ||
self.dispatch(IoEvent::GetMetrics).await; | ||
} | ||
|
||
|
@@ -553,6 +559,9 @@ impl App { | |
ActiveBlock::RplCtrl => { | ||
self.dispatch(IoEvent::GetReplicationControllers).await; | ||
} | ||
ActiveBlock::StorageClasses => { | ||
self.dispatch(IoEvent::GetStorageClasses).await; | ||
} | ||
ActiveBlock::Logs => { | ||
if !self.is_streaming { | ||
// do not tail to avoid duplicates | ||
|
@@ -709,6 +718,7 @@ mod tests { | |
sync_io_rx.recv().await.unwrap(), | ||
IoEvent::GetReplicationControllers | ||
); | ||
assert_eq!(sync_io_rx.recv().await.unwrap(), IoEvent::GetStorageClasses); | ||
assert_eq!(sync_io_rx.recv().await.unwrap(), IoEvent::GetMetrics); | ||
assert_eq!(sync_io_rx.recv().await.unwrap(), IoEvent::GetNamespaces); | ||
assert_eq!(sync_io_rx.recv().await.unwrap(), IoEvent::GetNodes); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use crate::app::models::KubeResource; | ||
use crate::app::utils; | ||
use k8s_openapi::api::storage::v1::StorageClass; | ||
use k8s_openapi::chrono::Utc; | ||
|
||
#[derive(Clone, Debug, PartialEq)] | ||
pub struct KubeStorageClass { | ||
pub name: String, | ||
pub provisioner: String, | ||
pub reclaim_policy: String, | ||
pub volume_binding_mode: String, | ||
pub allow_volume_expansion: bool, | ||
pub age: String, | ||
k8s_obj: StorageClass, | ||
} | ||
|
||
impl KubeResource<StorageClass> for KubeStorageClass { | ||
fn from_api(storage_class: &StorageClass) -> Self { | ||
KubeStorageClass { | ||
name: storage_class.metadata.name.clone().unwrap_or_default(), | ||
provisioner: storage_class.provisioner.clone(), | ||
reclaim_policy: storage_class.reclaim_policy.clone().unwrap_or_default(), | ||
volume_binding_mode: storage_class | ||
.volume_binding_mode | ||
.clone() | ||
.unwrap_or_default(), | ||
allow_volume_expansion: storage_class.allow_volume_expansion.unwrap_or_default(), | ||
age: utils::to_age( | ||
storage_class.metadata.creation_timestamp.as_ref(), | ||
Utc::now(), | ||
), | ||
k8s_obj: storage_class.to_owned(), | ||
} | ||
} | ||
|
||
fn get_k8s_obj(&self) -> &StorageClass { | ||
&self.k8s_obj | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::app::storageclass::KubeStorageClass; | ||
use crate::app::test_utils::{convert_resource_from_file, get_time}; | ||
use crate::app::utils; | ||
use k8s_openapi::chrono::Utc; | ||
|
||
#[tokio::test] | ||
async fn test_storageclass_from_api() { | ||
let (storage_classes, storage_classes_list): (Vec<KubeStorageClass>, Vec<_>) = | ||
convert_resource_from_file("storageclass"); | ||
assert_eq!(storage_classes_list.len(), 4); | ||
assert_eq!( | ||
storage_classes[0], | ||
KubeStorageClass { | ||
name: "ebs-performance".into(), | ||
provisioner: "kubernetes.io/aws-ebs".into(), | ||
reclaim_policy: "Delete".into(), | ||
volume_binding_mode: "Immediate".into(), | ||
allow_volume_expansion: false, | ||
age: utils::to_age(Some(&get_time("2021-12-14T11:08:59Z")), Utc::now()), | ||
k8s_obj: storage_classes_list[0].clone(), | ||
} | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -416,6 +416,21 @@ async fn handle_route_events(key: Key, app: &mut App) { | |
.await; | ||
} | ||
} | ||
ActiveBlock::StorageClasses => { | ||
if let Some(res) = handle_block_action(key, &mut app.data.storageclasses) { | ||
let _ok = handle_describe_or_yaml_action( | ||
key, | ||
app, | ||
&res, | ||
IoCmdEvent::GetDescribe { | ||
kind: "storageclass".to_owned(), | ||
value: res.name.to_owned(), | ||
ns: None, | ||
}, | ||
) | ||
.await; | ||
} | ||
} | ||
ActiveBlock::Contexts | ActiveBlock::Utilization | ActiveBlock::Help => { /* Do nothing */ } | ||
} | ||
} | ||
|
@@ -479,6 +494,7 @@ async fn handle_block_scroll(app: &mut App, up: bool, is_mouse: bool, page: bool | |
ActiveBlock::RplCtrl => app.data.rpl_ctrls.handle_scroll(up, page), | ||
ActiveBlock::Contexts => app.data.contexts.handle_scroll(up, page), | ||
ActiveBlock::Utilization => app.data.metrics.handle_scroll(up, page), | ||
ActiveBlock::StorageClasses => app.data.storageclasses.handle_scroll(up, page), | ||
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. move to line 494 |
||
ActiveBlock::Help => app.help_docs.handle_scroll(up, page), | ||
ActiveBlock::More => app.more_resources_menu.handle_scroll(up, page), | ||
ActiveBlock::Logs => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ use crate::app::{ | |
replication_controllers::KubeReplicationController, | ||
secrets::KubeSecret, | ||
statefulsets::KubeStatefulSet, | ||
storageclass::KubeStorageClass, | ||
svcs::KubeSvc, | ||
}; | ||
|
||
|
@@ -332,4 +333,13 @@ impl<'a> Network<'a> { | |
None => Api::all(self.client.clone()), | ||
} | ||
} | ||
|
||
pub async fn get_storage_classes(&self) { | ||
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. move to line 301 to seperate pub and private functions visually |
||
let items: Vec<KubeStorageClass> = self | ||
.get_namespaced_resources(|it| KubeStorageClass::from_api(it)) | ||
.await; | ||
|
||
let mut app = self.app.lock().await; | ||
app.data.storageclasses.set_items(items); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -34,6 +34,7 @@ static SECRETS_TITLE: &str = "Secrets"; | |||||
static RPL_CTRL_TITLE: &str = "ReplicationControllers"; | ||||||
static DESCRIBE_ACTIVE: &str = "-> Describe "; | ||||||
static YAML_ACTIVE: &str = "-> YAML "; | ||||||
static STORAGE_CLASSES_LABEL: &str = "Storage Classes"; | ||||||
deepu105 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
pub fn draw_resource_tabs_block<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, area: Rect) { | ||||||
let chunks = | ||||||
|
@@ -80,6 +81,7 @@ fn draw_more<B: Backend>(block: ActiveBlock, f: &mut Frame<'_, B>, app: &mut App | |||||
ActiveBlock::CronJobs => draw_cronjobs_tab(block, f, app, area), | ||||||
ActiveBlock::Secrets => draw_secrets_tab(block, f, app, area), | ||||||
ActiveBlock::RplCtrl => draw_replication_controllers_tab(block, f, app, area), | ||||||
ActiveBlock::StorageClasses => draw_storage_classes_tab(block, f, app, area), | ||||||
ActiveBlock::Describe | ActiveBlock::Yaml => { | ||||||
let mut prev_route = app.get_prev_route(); | ||||||
if prev_route.active_block == block { | ||||||
|
@@ -89,6 +91,7 @@ fn draw_more<B: Backend>(block: ActiveBlock, f: &mut Frame<'_, B>, app: &mut App | |||||
ActiveBlock::CronJobs => draw_cronjobs_tab(block, f, app, area), | ||||||
ActiveBlock::Secrets => draw_secrets_tab(block, f, app, area), | ||||||
ActiveBlock::RplCtrl => draw_replication_controllers_tab(block, f, app, area), | ||||||
ActiveBlock::StorageClasses => draw_storage_classes_tab(block, f, app, area), | ||||||
_ => { /* do nothing */ } | ||||||
} | ||||||
} | ||||||
|
@@ -939,6 +942,68 @@ fn draw_replication_controllers_block<B: Backend>(f: &mut Frame<'_, B>, app: &mu | |||||
); | ||||||
} | ||||||
|
||||||
fn draw_storage_classes_tab<B: Backend>( | ||||||
block: ActiveBlock, | ||||||
f: &mut Frame<'_, B>, | ||||||
app: &mut App, | ||||||
area: Rect, | ||||||
) { | ||||||
draw_resource_tab!( | ||||||
STORAGE_CLASSES_LABEL, | ||||||
block, | ||||||
f, | ||||||
app, | ||||||
area, | ||||||
draw_storage_classes_tab, | ||||||
draw_storage_classes_block, | ||||||
app.data.secrets | ||||||
); | ||||||
} | ||||||
|
||||||
fn draw_storage_classes_block<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, area: Rect) { | ||||||
let title = | ||||||
get_cluster_wide_resource_title(STORAGE_CLASSES_LABEL, app.data.storageclasses.items.len()); | ||||||
|
||||||
draw_resource_block( | ||||||
f, | ||||||
area, | ||||||
ResourceTableProps { | ||||||
title, | ||||||
inline_help: DESCRIBE_YAML_AND_ESC_HINT.into(), | ||||||
resource: &mut app.data.storageclasses, | ||||||
table_headers: vec![ | ||||||
"Name", | ||||||
"Provisioner", | ||||||
"Reclaim Policy", | ||||||
"Volume binding mode", | ||||||
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.
Suggested change
|
||||||
"Allow volume expansion", | ||||||
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.
Suggested change
|
||||||
"Age", | ||||||
], | ||||||
column_widths: vec![ | ||||||
Constraint::Percentage(10), | ||||||
Constraint::Percentage(20), | ||||||
Constraint::Percentage(10), | ||||||
Constraint::Percentage(20), | ||||||
Constraint::Percentage(20), | ||||||
Constraint::Percentage(10), | ||||||
], | ||||||
}, | ||||||
|c| { | ||||||
Row::new(vec![ | ||||||
Cell::from(c.name.to_owned()), | ||||||
Cell::from(c.provisioner.to_owned()), | ||||||
Cell::from(c.reclaim_policy.to_owned()), | ||||||
Cell::from(c.volume_binding_mode.to_owned()), | ||||||
Cell::from(c.allow_volume_expansion.to_string()), | ||||||
Cell::from(c.age.to_owned()), | ||||||
]) | ||||||
.style(style_primary(app.light_theme)) | ||||||
}, | ||||||
app.light_theme, | ||||||
app.is_loading, | ||||||
); | ||||||
} | ||||||
|
||||||
/// common for all resources | ||||||
fn draw_describe_block<B: Backend>( | ||||||
f: &mut Frame<'_, B>, | ||||||
|
@@ -1037,6 +1102,10 @@ fn get_node_title<S: AsRef<str>>(app: &App, suffix: S) -> String { | |||||
) | ||||||
} | ||||||
|
||||||
fn get_cluster_wide_resource_title<S: AsRef<str>>(title: S, items_len: usize) -> String { | ||||||
format!("{} [{}]", title.as_ref(), items_len,) | ||||||
} | ||||||
|
||||||
fn get_resource_title<S: AsRef<str>>(app: &App, title: S, suffix: S, items_len: usize) -> String { | ||||||
format!( | ||||||
" {} {}", | ||||||
|
@@ -1370,4 +1439,12 @@ mod tests { | |||||
fn test_title_with_ns() { | ||||||
assert_eq!(title_with_ns("Title", "hello", 3), "Title (ns: hello) [3]"); | ||||||
} | ||||||
|
||||||
#[test] | ||||||
fn test_get_cluster_wide_resource_title() { | ||||||
assert_eq!( | ||||||
get_cluster_wide_resource_title("Cluster Resource", 3), | ||||||
"Cluster Resource [3]" | ||||||
); | ||||||
} | ||||||
} |
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.
move it to existing import grouping below in line 40. If you are using VSCode it should do that when you format