Skip to content

Commit fbf6bd7

Browse files
authored
Show only pods which are created by plugin on plugin status report page (#5) (#16)
1 parent 0fe2ec7 commit fbf6bd7

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/main/java/cd/go/contrib/elasticagent/model/KubernetesCluster.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ public KubernetesCluster(KubernetesClient client) throws ParseException {
3939

4040
private void fetchPods(KubernetesClient dockerClient) throws ParseException {
4141
final Map<String, KubernetesNode> dockerNodeMap = nodes.stream().distinct().collect(toMap(KubernetesNode::getName, node -> node));
42-
final List<Pod> pods = dockerClient.pods().inNamespace(Constants.KUBERNETES_NAMESPACE_KEY).list().getItems();
42+
43+
final List<Pod> pods = dockerClient.pods().inNamespace(Constants.KUBERNETES_NAMESPACE_KEY)
44+
.withLabel(Constants.CREATED_BY_LABEL_KEY, Constants.PLUGIN_ID)
45+
.list().getItems();
46+
4347
LOG.info("Running pods " + pods.size());
4448

4549
for (Pod pod : pods) {

src/test/java/cd/go/contrib/elasticagent/executors/StatusReportExecutorTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public void shouldBuildStatusReportView() throws Exception {
6565
when(kubernetesClient.nodes()).thenReturn(nodes);
6666

6767
when(pods.inNamespace(Constants.KUBERNETES_NAMESPACE_KEY)).thenReturn(pods);
68+
when(pods.withLabel(Constants.CREATED_BY_LABEL_KEY, Constants.PLUGIN_ID)).thenReturn(pods);
6869
when(pods.list()).thenReturn(new PodList());
6970
when(kubernetesClient.pods()).thenReturn(pods);
7071

@@ -79,4 +80,4 @@ public void shouldBuildStatusReportView() throws Exception {
7980
assertThat(response.responseCode(), is(200));
8081
assertThat(response.responseBody(), is("{\"view\":\"status-report\"}"));
8182
}
82-
}
83+
}

src/test/java/cd/go/contrib/elasticagent/model/KubernetesClusterTest.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,13 @@
1717
package cd.go.contrib.elasticagent.model;
1818

1919
import cd.go.contrib.elasticagent.Constants;
20-
import io.fabric8.kubernetes.api.model.Node;
2120
import io.fabric8.kubernetes.api.model.NodeList;
2221
import io.fabric8.kubernetes.api.model.PodList;
2322
import io.fabric8.kubernetes.client.KubernetesClient;
2423
import io.fabric8.kubernetes.client.dsl.internal.NodeOperationsImpl;
2524
import io.fabric8.kubernetes.client.dsl.internal.PodOperationsImpl;
2625
import org.junit.Test;
2726

28-
import java.util.Arrays;
29-
import java.util.List;
30-
31-
import static org.hamcrest.Matchers.hasSize;
32-
import static org.junit.Assert.assertThat;
3327
import static org.mockito.Mockito.*;
3428

3529
public class KubernetesClusterTest {
@@ -44,6 +38,7 @@ public void shouldCreateKubernetesClusterObject() throws Exception {
4438
when(kubernetesClient.nodes()).thenReturn(nodes);
4539

4640
when(pods.inNamespace(Constants.KUBERNETES_NAMESPACE_KEY)).thenReturn(pods);
41+
when(pods.withLabel(Constants.CREATED_BY_LABEL_KEY, Constants.PLUGIN_ID)).thenReturn(pods);
4742
when(pods.list()).thenReturn(new PodList());
4843
when(kubernetesClient.pods()).thenReturn(pods);
4944

@@ -52,4 +47,4 @@ public void shouldCreateKubernetesClusterObject() throws Exception {
5247
verify(kubernetesClient, times(1)).nodes();
5348
verify(kubernetesClient, times(1)).pods();
5449
}
55-
}
50+
}

0 commit comments

Comments
 (0)