Skip to content

Commit 6181bd7

Browse files
authored
Merge pull request #8 from GaneshSPatil/add-job-identifier-field-in-pod-row
Add job identifier field in pod row
2 parents 474af8d + 4e50381 commit 6181bd7

File tree

6 files changed

+78
-51
lines changed

6 files changed

+78
-51
lines changed

src/main/java/cd/go/contrib/elasticagent/Constants.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ public interface Constants {
4545
// internal use only
4646
String CREATED_BY_LABEL_KEY = "Elastic-Agent-Created-By";
4747
String ENVIRONMENT_LABEL_KEY = "Elastic-Agent-Environment-Name";
48-
String JOB_ID_LABEL_KEY = "Elastic-Agent-Job-Identifier";
48+
String JOB_ID_LABEL_KEY = "Elastic-Agent-Job-Id";
49+
String JOB_IDENTIFIER_LABEL_KEY = "Elastic-Agent-Job-Identifier";
4950

5051
String KUBERNETES_NAMESPACE_KEY = "default";
5152
String KUBERNETES_POD_KIND_LABEL_KEY = "kind";

src/main/java/cd/go/contrib/elasticagent/KubernetesInstanceFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
import static cd.go.contrib.elasticagent.KubernetesPlugin.LOG;
3939
import static cd.go.contrib.elasticagent.executors.GetProfileMetadataExecutor.POD_CONFIGURATION;
40+
import static cd.go.contrib.elasticagent.utils.Util.GSON;
4041
import static cd.go.contrib.elasticagent.utils.Util.getSimpleDateFormat;
4142
import static org.apache.commons.lang3.StringUtils.isBlank;
4243

@@ -99,6 +100,7 @@ private static void setLabels(Pod pod, CreateAgentRequest request) {
99100
private static void setAnnotations(Pod pod, CreateAgentRequest request) {
100101
Map<String, String> existingAnnotations = (pod.getMetadata().getAnnotations() != null) ? pod.getMetadata().getAnnotations() : new HashMap<>();
101102
existingAnnotations.putAll(request.properties());
103+
existingAnnotations.put(Constants.JOB_IDENTIFIER_LABEL_KEY, GSON.toJson(request.jobIdentifier()));
102104
pod.getMetadata().setAnnotations(existingAnnotations);
103105
}
104106

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,8 @@ public Long getJobId() {
120120
public String getJobName() {
121121
return jobName;
122122
}
123+
124+
public String representation() {
125+
return pipelineName + "/" + pipelineCounter + "/" + staqeName + "/" + stageCounter + "/" + jobName;
126+
}
123127
}

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package cd.go.contrib.elasticagent.model;
1818

19+
import cd.go.contrib.elasticagent.Constants;
1920
import cd.go.contrib.elasticagent.utils.Util;
2021
import io.fabric8.kubernetes.api.model.Pod;
2122

@@ -29,8 +30,10 @@ public class KubernetesPod {
2930
private final Date creationTimestamp;
3031
private final String podIP;
3132
private final String status;
33+
private JobIdentifier jobIdentifier;
3234

3335
public KubernetesPod(Pod pod) throws ParseException {
36+
jobIdentifier = Util.GSON.fromJson(pod.getMetadata().getAnnotations().get(Constants.JOB_IDENTIFIER_LABEL_KEY), JobIdentifier.class);
3437
podName = pod.getMetadata().getName();
3538
image = pod.getSpec().getContainers().get(0).getImage();
3639
podIP = pod.getStatus().getPodIP();
@@ -64,6 +67,13 @@ public String getStatus() {
6467
return status;
6568
}
6669

70+
public String getJobInformation() {
71+
if(jobIdentifier != null) {
72+
return jobIdentifier.representation();
73+
}
74+
return "No Job Information Available!";
75+
}
76+
6777
@Override
6878
public boolean equals(Object o) {
6979
if (this == o) return true;
@@ -77,7 +87,8 @@ public boolean equals(Object o) {
7787
if (creationTimestamp != null ? !creationTimestamp.equals(that.creationTimestamp) : that.creationTimestamp != null)
7888
return false;
7989
if (podIP != null ? !podIP.equals(that.podIP) : that.podIP != null) return false;
80-
return status != null ? status.equals(that.status) : that.status == null;
90+
if (status != null ? !status.equals(that.status) : that.status != null) return false;
91+
return jobIdentifier != null ? jobIdentifier.equals(that.jobIdentifier) : that.jobIdentifier == null;
8192
}
8293

8394
@Override
@@ -88,6 +99,7 @@ public int hashCode() {
8899
result = 31 * result + (creationTimestamp != null ? creationTimestamp.hashCode() : 0);
89100
result = 31 * result + (podIP != null ? podIP.hashCode() : 0);
90101
result = 31 * result + (status != null ? status.hashCode() : 0);
102+
result = 31 * result + (jobIdentifier != null ? jobIdentifier.hashCode() : 0);
91103
return result;
92104
}
93105
}

src/main/resources/status-report.template.ftlh

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@
44
}
55

66
[data-plugin-style-id="kubernetes-plugin"] .node {
7-
border: 1px solid #d1c4e9;
8-
width: 100%;
9-
background: #fff;
7+
border: 1px solid #d1c4e9;
8+
width: 100%;
9+
background: #fff;
1010
border-radius: 2px;
1111
margin-bottom: 20px;
1212
}
1313

1414
[data-plugin-style-id="kubernetes-plugin"] .node-header {
15-
background: #d1c4e9;
16-
padding: 10px;
17-
font-size: 14px;
15+
background: #d1c4e9;
16+
padding: 10px;
17+
font-size: 14px;
1818
font-weight: 600;
19-
cursor: pointer;
19+
cursor: pointer;
2020
}
2121

2222
[data-plugin-style-id="kubernetes-plugin"] .node-header .left {
23-
float: left;
23+
float: left;
2424
padding: 0px;
2525
}
2626

@@ -33,8 +33,8 @@
3333
}
3434

3535
[data-plugin-style-id="kubernetes-plugin"] .node-header span {
36-
display: inline-block;
37-
width: 15%;
36+
display: inline-block;
37+
width: 15%;
3838
font-size: 17px;
3939
}
4040

@@ -43,84 +43,84 @@
4343
}
4444

4545
[data-plugin-style-id="kubernetes-plugin"] .node table {
46-
width: calc(100% - 40px);
46+
width: calc(100% - 40px);
4747
min-width: 95%;
48-
border: 1px solid #D8D8D8;
48+
border: 1px solid #D8D8D8;
4949
font-size: 13px;
50-
margin: 10px 20px 20px 20px;
50+
margin: 10px 20px 20px 20px;
5151
}
5252

5353
[data-plugin-style-id="kubernetes-plugin"] .node table thead {
5454
background: #D8D8D8;
5555
}
5656

5757
[data-plugin-style-id="kubernetes-plugin"] .node table thead th {
58-
padding: 10px 20px;
58+
padding: 10px 20px;
5959
font-weight: bold;
6060
}
6161

6262
[data-plugin-style-id="kubernetes-plugin"] .node table tbody tr {
63-
border-top: 1px solid #D8D8D8;
64-
border-bottom: 1px solid #D8D8D8;
63+
border-top: 1px solid #D8D8D8;
64+
border-bottom: 1px solid #D8D8D8;
6565
border-collapse: collapse;
6666
}
6767

6868
[data-plugin-style-id="kubernetes-plugin"] .node table tbody td {
69-
padding: 10px 20px;
70-
max-width: 190px;
69+
padding: 10px 20px;
70+
max-width: 190px;
7171
text-overflow: ellipsis;
72-
overflow: hidden;
72+
overflow: hidden;
7373
}
7474

7575
[data-plugin-style-id="kubernetes-plugin"] dl.properties {
76-
overflow: hidden;
77-
margin: 0;
78-
font-size: 13px;
79-
display: inline-block;
76+
overflow: hidden;
77+
margin: 0;
78+
font-size: 13px;
79+
display: inline-block;
8080
vertical-align: top;
8181
}
8282

8383
[data-plugin-style-id="kubernetes-plugin"] dt {
84-
float: left;
85-
clear: both;
86-
min-width: 230px;
87-
text-align: right;
84+
float: left;
85+
clear: both;
86+
min-width: 230px;
87+
text-align: right;
8888
font-weight: normal;
89-
padding: 5px 0px;
90-
margin: 0;
89+
padding: 5px 0px;
90+
margin: 0;
9191
}
9292

9393
[data-plugin-style-id="kubernetes-plugin"] dl.properties.inline dt {
94-
clear: none;
95-
min-width: auto;
94+
clear: none;
95+
min-width: auto;
9696
vertical-align: bottom;
9797
}
9898

9999
[data-plugin-style-id="kubernetes-plugin"] dl.properties.inline dd, [data-plugin-style-id="kubernetes-plugin"] dl.properties.inline dt {
100100
padding: 0px;
101-
height: 15px;
101+
height: 15px;
102102
}
103103

104104
[data-plugin-style-id="kubernetes-plugin"] dl.properties.inline dd {
105105
margin-right: 15px;
106106
}
107107

108108
[data-plugin-style-id="kubernetes-plugin"] .node-header .hostname, [data-plugin-style-id="kubernetes-plugin"] .node-header .node-id {
109-
min-width: 150px;
110-
max-width: 150px;
111-
overflow: hidden;
109+
min-width: 150px;
110+
max-width: 150px;
111+
overflow: hidden;
112112
text-overflow: ellipsis;
113113
}
114114

115115
[data-plugin-style-id="kubernetes-plugin"] .name {
116-
min-width: 300px;
117-
max-width: 300px;
118-
overflow: hidden;
116+
min-width: 300px;
117+
max-width: 300px;
118+
overflow: hidden;
119119
text-overflow: ellipsis;
120120
}
121121

122122
[data-plugin-style-id="kubernetes-plugin"] dl.properties.inline dt:first-child {
123-
min-width: auto;
123+
min-width: auto;
124124
margin-left: 10px;
125125
}
126126

@@ -130,23 +130,23 @@
130130
}
131131

132132
[data-plugin-style-id="kubernetes-plugin"] dd {
133-
float: left;
134-
padding: 5px 0px;
133+
float: left;
134+
padding: 5px 0px;
135135
font-weight: 600;
136-
margin: 0;
136+
margin: 0;
137137
}
138138

139139
[data-plugin-style-id="kubernetes-plugin"] .node .header {
140140
margin: 20px 0px 0px 20px;
141141
}
142142

143143
[data-plugin-style-id="kubernetes-plugin"] .warning {
144-
font-size: 13px;
145-
font-weight: 600;
144+
font-size: 13px;
145+
font-weight: 600;
146146
margin-bottom: 10px;
147-
border-left: 2px solid #f7bc08;
148-
padding: 10px;
149-
background: #fff;
147+
border-left: 2px solid #f7bc08;
148+
padding: 10px;
149+
background: #fff;
150150
border-radius: 2px;
151151
}
152152
</style>
@@ -208,7 +208,7 @@
208208
<dt>Architecture</dt>
209209
<dd>${node.architecture!}</dd>
210210
</dl>
211-
211+
212212
<dl class="properties">
213213
<dt>Container Runtime Version</dt>
214214
<dd>${node.containerRuntimeVersion!}</dd>
@@ -223,6 +223,7 @@
223223
<thead>
224224
<tr>
225225
<th>Pod Name</th>
226+
<th>Job Information</th>
226227
<th>Image</th>
227228
<th>IP Address</th>
228229
<th>Created At</th>
@@ -234,6 +235,7 @@
234235
<#list node.pods as pod>
235236
<tr>
236237
<td>${pod.podName!}</td>
238+
<td>${pod.jobInformation!}</td>
237239
<td>${pod.image!}</td>
238240
<td>${pod.podIP!}</td>
239241
<td>{{ ${pod.creationTimestamp?long?c!} | date:"MMM dd, yyyy hh:mm:ss a"}}</td>

src/test/java/cd/go/contrib/elasticagent/KubernetesAgentInstancesIntegrationTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package cd.go.contrib.elasticagent;
1818

1919
import cd.go.contrib.elasticagent.requests.CreateAgentRequest;
20+
import com.google.gson.Gson;
2021
import io.fabric8.kubernetes.api.model.Container;
2122
import io.fabric8.kubernetes.api.model.EnvVar;
2223
import io.fabric8.kubernetes.api.model.Pod;
@@ -32,6 +33,7 @@
3233
import java.util.ArrayList;
3334
import java.util.HashMap;
3435
import java.util.List;
36+
import java.util.Map;
3537

3638
import static org.hamcrest.Matchers.is;
3739
import static org.junit.Assert.*;
@@ -145,7 +147,10 @@ public void shouldCreateKubernetesPodWithPodAnnotations() throws Exception {
145147

146148
assertNotNull(elasticAgentPod.getMetadata());
147149

148-
assertThat(elasticAgentPod.getMetadata().getAnnotations(), is(createAgentRequest.properties()));
150+
Map<String, String> expectedAnnotations = new HashMap<>();
151+
expectedAnnotations.putAll(createAgentRequest.properties());
152+
expectedAnnotations.put(Constants.JOB_IDENTIFIER_LABEL_KEY, new Gson().toJson(createAgentRequest.jobIdentifier()));
153+
assertThat(elasticAgentPod.getMetadata().getAnnotations(), is(expectedAnnotations));
149154
}
150155

151156
@Test
@@ -249,6 +254,7 @@ public void usingPodYamlConfigurations_shouldCreateKubernetesPodWithPodAnnotatio
249254
HashMap<String, String> expectedAnnotations = new HashMap<>();
250255
expectedAnnotations.putAll(createAgentRequest.properties());
251256
expectedAnnotations.put("annotation-key", "my-fancy-annotation-value");
257+
expectedAnnotations.put(Constants.JOB_IDENTIFIER_LABEL_KEY, new Gson().toJson(createAgentRequest.jobIdentifier()));
252258

253259
assertThat(elasticAgentPod.getMetadata().getAnnotations(), is(expectedAnnotations));
254260
}

0 commit comments

Comments
 (0)