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

kdash-rs / kdash / 24896163116

24 Apr 2026 02:55PM UTC coverage: 73.15% (+1.5%) from 71.659%
24896163116

push

github

deepu105
polish

33 of 33 new or added lines in 4 files covered. (100.0%)

857 existing lines in 27 files now uncovered.

10192 of 13933 relevant lines covered (73.15%)

139.7 hits per line

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

60.26
/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::Rect,
8
  widgets::{Cell, Row},
9
  Frame,
10
};
11

12
use super::{
13
  models::{self, AppResource, KubeResource, Named},
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, responsive_columns,
24
    style_primary, title_with_dual_style, ColumnDef, ResourceTableProps, ViewTier,
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 Named for KubeReplicationController {
100
  fn get_name(&self) -> &String {
×
101
    &self.name
×
102
  }
×
103
}
104

105
impl KubeResource<ReplicationController> for KubeReplicationController {
106
  fn get_k8s_obj(&self) -> &ReplicationController {
×
107
    &self.k8s_obj
×
108
  }
×
109
}
110

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

123
static RPL_CTRL_TITLE: &str = "ReplicationControllers";
124

125
pub struct ReplicationControllerResource {}
126

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

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

147
    let mut app = nw.app.lock().await;
148
    app.data.replication_controllers.set_items(items);
149
  }
×
150
}
151

152
const RC_COLUMNS: [ColumnDef; 9] = [
153
  ColumnDef::all("Namespace", 15, 15, 15),
154
  ColumnDef::all("Name", 15, 15, 15),
155
  ColumnDef::all("Desired", 10, 10, 10),
156
  ColumnDef::all("Current", 10, 10, 10),
157
  ColumnDef::all("Ready", 10, 10, 10),
158
  ColumnDef::all("Containers", 10, 10, 10),
159
  ColumnDef::all("Images", 10, 10, 10),
160
  ColumnDef::all("Selector", 10, 10, 10),
161
  ColumnDef::all("Age", 10, 10, 10),
162
];
163

164
fn draw_block(f: &mut Frame<'_>, app: &mut App, area: Rect) {
×
165
  let is_loading = app.is_loading();
×
166
  let title = get_resource_title(
×
167
    app,
×
168
    RPL_CTRL_TITLE,
×
169
    "",
×
170
    app.data.replication_controllers.items.len(),
×
171
  );
172

173
  let (headers, widths) = responsive_columns(&RC_COLUMNS, ViewTier::Compact);
×
174

175
  draw_resource_block(
×
176
    f,
×
177
    area,
×
178
    ResourceTableProps {
×
179
      title,
×
180
      inline_help: help_bold_line(
×
181
        format!(
×
182
          "{} | {}",
×
183
          action_hint("pods", DEFAULT_KEYBINDING.submit.key),
×
184
          describe_yaml_logs_and_esc_hint()
×
185
        ),
×
186
        app.light_theme,
×
187
      ),
×
188
      resource: &mut app.data.replication_controllers,
×
189
      table_headers: headers,
×
190
      column_widths: widths,
×
191
    },
×
192
    |c| {
×
193
      Row::new(vec![
×
194
        Cell::from(c.namespace.to_owned()),
×
195
        Cell::from(c.name.to_owned()),
×
196
        Cell::from(c.desired.to_string()),
×
197
        Cell::from(c.current.to_string()),
×
198
        Cell::from(c.ready.to_string()),
×
199
        Cell::from(c.containers.to_owned()),
×
200
        Cell::from(c.images.to_owned()),
×
201
        Cell::from(c.selector.to_owned()),
×
202
        Cell::from(c.age.to_owned()),
×
203
      ])
204
      .style(style_primary(app.light_theme))
×
205
    },
×
206
    app.light_theme,
×
207
    is_loading,
×
208
  );
UNCOV
209
}
×
210

211
#[cfg(test)]
212
mod tests {
213
  use super::*;
214
  use crate::app::models::HasPodSelector;
215
  use crate::app::test_utils::*;
216

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

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

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

260
    // nginx RC has selector: {app: nginx}
261
    let selector = rplc[0].pod_label_selector();
1✔
262
    assert!(selector.is_some());
1✔
263
    assert_eq!(selector.unwrap(), "app=nginx");
1✔
264
  }
1✔
265
}
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