• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kdash-rs / kdash / 24207749698

09 Apr 2026 06:53PM UTC coverage: 71.732% (+0.6%) from 71.177%
24207749698

push

github

deepu105
refactor: update filter hints for consistency and clarity

250 of 268 new or added lines in 18 files covered. (93.28%)

1 existing line in 1 file now uncovered.

9965 of 13892 relevant lines covered (71.73%)

258.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

53.53
/src/app/replication_controllers.rs
1
use std::collections::BTreeMap;
2

3
use async_trait::async_trait;
4
use chrono::Utc;
5
use k8s_openapi::api::core::v1::ReplicationController;
6
use ratatui::{
7
  layout::{Constraint, Rect},
8
  widgets::{Cell, Row},
9
  Frame,
10
};
11

12
use super::{
13
  models::{self, AppResource, KubeResource},
14
  utils::{self},
15
  ActiveBlock, App,
16
};
17
use crate::{
18
  app::key_binding::DEFAULT_KEYBINDING,
19
  draw_resource_tab,
20
  network::Network,
21
  ui::utils::{
22
    action_hint, describe_yaml_logs_and_esc_hint, draw_describe_block, draw_resource_block,
23
    draw_yaml_block, get_describe_active, get_resource_title, help_bold_line, style_primary,
24
    title_with_dual_style, ResourceTableProps,
25
  },
26
};
27

28
#[derive(Clone, Debug, PartialEq)]
29
pub struct KubeReplicationController {
30
  pub name: String,
31
  pub namespace: String,
32
  pub desired: i32,
33
  pub current: i32,
34
  pub ready: i32,
35
  pub containers: String,
36
  pub images: String,
37
  pub selector: String,
38
  pub age: String,
39
  k8s_obj: ReplicationController,
40
}
41

42
impl From<ReplicationController> for KubeReplicationController {
43
  fn from(rplc: ReplicationController) -> Self {
4✔
44
    let (current, ready) = match rplc.status.as_ref() {
4✔
45
      Some(s) => (s.replicas, s.ready_replicas.unwrap_or_default()),
4✔
46
      _ => (0, 0),
×
47
    };
48

49
    let (desired, selector, (containers, images)) = match rplc.spec.as_ref() {
4✔
50
      Some(spec) => (
4✔
51
        spec.replicas.unwrap_or_default(),
4✔
52
        spec
4✔
53
          .selector
4✔
54
          .as_ref()
4✔
55
          .unwrap_or(&BTreeMap::new())
4✔
56
          .iter()
4✔
57
          .map(|(key, val)| format!("{}={}", key, val))
4✔
58
          .collect::<Vec<String>>()
4✔
59
          .join(","),
4✔
60
        match spec.template.as_ref() {
4✔
61
          Some(tmpl) => match tmpl.spec.as_ref() {
4✔
62
            Some(pspec) => (
4✔
63
              pspec
4✔
64
                .containers
4✔
65
                .iter()
4✔
66
                .map(|c| c.name.to_owned())
6✔
67
                .collect::<Vec<String>>()
4✔
68
                .join(","),
4✔
69
              pspec
4✔
70
                .containers
4✔
71
                .iter()
4✔
72
                .filter_map(|c| c.image.to_owned())
6✔
73
                .collect::<Vec<String>>()
4✔
74
                .join(","),
4✔
75
            ),
76
            None => ("".into(), "".into()),
×
77
          },
78
          None => ("".into(), "".into()),
×
79
        },
80
      ),
81
      None => (0, "".into(), ("".into(), "".into())),
×
82
    };
83

84
    KubeReplicationController {
4✔
85
      name: rplc.metadata.name.clone().unwrap_or_default(),
4✔
86
      namespace: rplc.metadata.namespace.clone().unwrap_or_default(),
4✔
87
      age: utils::to_age(rplc.metadata.creation_timestamp.as_ref(), Utc::now()),
4✔
88
      desired,
4✔
89
      current,
4✔
90
      ready,
4✔
91
      containers,
4✔
92
      images,
4✔
93
      selector,
4✔
94
      k8s_obj: utils::sanitize_obj(rplc),
4✔
95
    }
4✔
96
  }
4✔
97
}
98

99
impl KubeResource<ReplicationController> for KubeReplicationController {
100
  fn get_name(&self) -> &String {
×
101
    &self.name
×
102
  }
×
103
  fn get_k8s_obj(&self) -> &ReplicationController {
×
104
    &self.k8s_obj
×
105
  }
×
106
}
107

108
impl models::HasPodSelector for KubeReplicationController {
109
  fn pod_label_selector(&self) -> Option<String> {
1✔
110
    self
1✔
111
      .k8s_obj
1✔
112
      .spec
1✔
113
      .as_ref()
1✔
114
      .and_then(|s| s.selector.as_ref())
1✔
115
      .filter(|labels| !labels.is_empty())
1✔
116
      .map(models::labels_to_selector)
1✔
117
  }
1✔
118
}
119

120
static RPL_CTRL_TITLE: &str = "ReplicationControllers";
121

122
pub struct ReplicationControllerResource {}
123

124
#[async_trait]
125
impl AppResource for ReplicationControllerResource {
126
  fn render(block: ActiveBlock, f: &mut Frame<'_>, app: &mut App, area: Rect) {
×
127
    draw_resource_tab!(
×
128
      RPL_CTRL_TITLE,
×
129
      block,
×
130
      f,
×
131
      app,
×
132
      area,
×
133
      Self::render,
134
      draw_block,
135
      app.data.replication_controllers
136
    );
137
  }
×
138

139
  async fn get_resource(nw: &Network<'_>) {
140
    let items: Vec<KubeReplicationController> = nw
141
      .get_namespaced_resources(ReplicationController::into)
142
      .await;
143

144
    let mut app = nw.app.lock().await;
145
    app.data.replication_controllers.set_items(items);
146
  }
×
147
}
148

149
fn draw_block(f: &mut Frame<'_>, app: &mut App, area: Rect) {
×
150
  let is_loading = app.is_loading();
×
151
  let title = get_resource_title(
×
152
    app,
×
153
    RPL_CTRL_TITLE,
×
154
    "",
×
155
    app.data.replication_controllers.items.len(),
×
156
  );
157

158
  draw_resource_block(
×
159
    f,
×
160
    area,
×
161
    ResourceTableProps {
×
162
      title,
×
163
      inline_help: help_bold_line(
×
164
        format!(
×
165
          "{} | {}",
×
NEW
166
          action_hint("pods", DEFAULT_KEYBINDING.submit.key),
×
167
          describe_yaml_logs_and_esc_hint()
×
168
        ),
×
169
        app.light_theme,
×
170
      ),
×
171
      resource: &mut app.data.replication_controllers,
×
172
      table_headers: vec![
×
173
        "Namespace",
×
174
        "Name",
×
175
        "Desired",
×
176
        "Current",
×
177
        "Ready",
×
178
        "Containers",
×
179
        "Images",
×
180
        "Selector",
×
181
        "Age",
×
182
      ],
×
183
      column_widths: vec![
×
184
        Constraint::Percentage(15),
×
185
        Constraint::Percentage(15),
×
186
        Constraint::Percentage(10),
×
187
        Constraint::Percentage(10),
×
188
        Constraint::Percentage(10),
×
189
        Constraint::Percentage(10),
×
190
        Constraint::Percentage(10),
×
191
        Constraint::Percentage(10),
×
192
        Constraint::Percentage(10),
×
193
      ],
×
194
    },
×
195
    |c| {
×
196
      Row::new(vec![
×
197
        Cell::from(c.namespace.to_owned()),
×
198
        Cell::from(c.name.to_owned()),
×
199
        Cell::from(c.desired.to_string()),
×
200
        Cell::from(c.current.to_string()),
×
201
        Cell::from(c.ready.to_string()),
×
202
        Cell::from(c.containers.to_owned()),
×
203
        Cell::from(c.images.to_owned()),
×
204
        Cell::from(c.selector.to_owned()),
×
205
        Cell::from(c.age.to_owned()),
×
206
      ])
207
      .style(style_primary(app.light_theme))
×
208
    },
×
209
    app.light_theme,
×
210
    is_loading,
×
211
  );
212
}
×
213

214
#[cfg(test)]
215
mod tests {
216
  use super::*;
217
  use crate::app::models::HasPodSelector;
218
  use crate::app::test_utils::*;
219

220
  #[test]
221
  fn test_replica_sets_from_api() {
1✔
222
    let (rplc, rplc_list): (Vec<KubeReplicationController>, Vec<_>) =
1✔
223
      convert_resource_from_file("replication_controllers");
1✔
224

225
    assert_eq!(rplc.len(), 2);
1✔
226
    assert_eq!(
1✔
227
      rplc[0],
1✔
228
      KubeReplicationController {
1✔
229
        name: "nginx".into(),
1✔
230
        namespace: "default".into(),
1✔
231
        age: utils::to_age(Some(&get_time("2021-07-27T14:37:49Z")), Utc::now()),
1✔
232
        k8s_obj: rplc_list[0].clone(),
1✔
233
        desired: 3,
1✔
234
        current: 3,
1✔
235
        ready: 3,
1✔
236
        containers: "nginx".into(),
1✔
237
        images: "nginx".into(),
1✔
238
        selector: "app=nginx".into(),
1✔
239
      }
1✔
240
    );
241
    assert_eq!(
1✔
242
      rplc[1],
1✔
243
      KubeReplicationController {
1✔
244
        name: "nginx-new".into(),
1✔
245
        namespace: "default".into(),
1✔
246
        age: utils::to_age(Some(&get_time("2021-07-27T14:45:24Z")), Utc::now()),
1✔
247
        k8s_obj: rplc_list[1].clone(),
1✔
248
        desired: 3,
1✔
249
        current: 3,
1✔
250
        ready: 0,
1✔
251
        containers: "nginx,nginx2".into(),
1✔
252
        images: "nginx,nginx".into(),
1✔
253
        selector: "app=nginx".into(),
1✔
254
      }
1✔
255
    );
256
  }
1✔
257

258
  #[test]
259
  fn test_replication_controller_pod_label_selector() {
1✔
260
    let (rplc, _): (Vec<KubeReplicationController>, Vec<_>) =
1✔
261
      convert_resource_from_file("replication_controllers");
1✔
262

263
    // nginx RC has selector: {app: nginx}
264
    let selector = rplc[0].pod_label_selector();
1✔
265
    assert!(selector.is_some());
1✔
266
    assert_eq!(selector.unwrap(), "app=nginx");
1✔
267
  }
1✔
268
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc