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

kdash-rs / kdash / 24024608060

06 Apr 2026 08:20AM UTC coverage: 62.628% (+0.5%) from 62.154%
24024608060

push

github

deepu105
feat: Add inline filter to Context page

54 of 95 new or added lines in 3 files covered. (56.84%)

651 existing lines in 31 files now uncovered.

6363 of 10160 relevant lines covered (62.63%)

212.77 hits per line

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

55.83
/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
  draw_resource_tab,
19
  network::Network,
20
  ui::utils::{
21
    draw_describe_block, draw_resource_block, draw_yaml_block, get_describe_active,
22
    get_resource_title, style_primary, title_with_dual_style, ResourceTableProps, COPY_HINT,
23
    DESCRIBE_YAML_LOGS_AND_ESC_HINT,
24
  },
25
};
26

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

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

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

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

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

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

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

121
pub struct ReplicationControllerResource {}
122

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

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

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

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

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

206
#[cfg(test)]
207
mod tests {
208
  use super::*;
209
  use crate::app::models::HasPodSelector;
210
  use crate::app::test_utils::*;
211

212
  #[test]
213
  fn test_replica_sets_from_api() {
1✔
214
    let (rplc, rplc_list): (Vec<KubeReplicationController>, Vec<_>) =
1✔
215
      convert_resource_from_file("replication_controllers");
1✔
216

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

250
  #[test]
251
  fn test_replication_controller_pod_label_selector() {
1✔
252
    let (rplc, _): (Vec<KubeReplicationController>, Vec<_>) =
1✔
253
      convert_resource_from_file("replication_controllers");
1✔
254

255
    // nginx RC has selector: {app: nginx}
256
    let selector = rplc[0].pod_label_selector();
1✔
257
    assert!(selector.is_some());
1✔
258
    assert_eq!(selector.unwrap(), "app=nginx");
1✔
259
  }
1✔
260
}
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