Skip to content

Commit 22023da

Browse files
committed
Group all containers under pod
Also shows if container is init or not. This makes the volume of data less to send to the backend Signed-off-by: Charlie Egan <[email protected]>
1 parent c354eb7 commit 22023da

File tree

2 files changed

+41
-14
lines changed

2 files changed

+41
-14
lines changed

pkg/datagatherer/versionchecker/versionchecker.go

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,14 @@ type DataGatherer struct {
236236
// of the containers for that pod. Exported so the backend can destructure
237237
// json.
238238
type PodResult struct {
239-
Pod v1.Pod `json:"pod"`
240-
Result *vcchecker.Result `json:"result"`
239+
Pod v1.Pod `json:"pod"`
240+
Results []containerResult `json:"results"`
241+
}
242+
243+
type containerResult struct {
244+
ContainerName string `json:"container_name"`
245+
InitContinainer bool `json:"init_container"`
246+
Result *vcchecker.Result `json:"result"`
241247
}
242248

243249
// Fetch retrieves cluster information from GKE.
@@ -260,20 +266,35 @@ func (g *DataGatherer) Fetch() (interface{}, error) {
260266
return nil, fmt.Errorf("failed to parse pod from unstructured data")
261267
}
262268

263-
// allContainers will contain a list of containers and init containers,
264-
// they will be checked in the same way
265269
var allContainers []v1.Container
266-
allContainers = append(allContainers, pod.Spec.Containers...)
267-
allContainers = append(allContainers, pod.Spec.InitContainers...)
270+
var isInitContainer []bool
271+
for _, c := range pod.Spec.Containers {
272+
allContainers = append(allContainers, c)
273+
isInitContainer = append(isInitContainer, false)
274+
}
275+
for _, c := range pod.Spec.InitContainers {
276+
allContainers = append(allContainers, c)
277+
isInitContainer = append(isInitContainer, true)
278+
}
268279

269-
for _, c := range allContainers {
280+
var containerResults []containerResult
281+
for i, c := range allContainers {
270282
result, err := g.versionChecker.Container(g.ctx, g.versionCheckerLog, &pod, &c, &g.versionCheckerOptions)
271283
if err != nil {
272284
return nil, fmt.Errorf("failed to check image for container: %s", err)
273285
}
274286

275-
results = append(results, PodResult{Pod: pod, Result: result})
287+
containerResults = append(
288+
containerResults,
289+
containerResult{
290+
ContainerName: c.Name,
291+
InitContinainer: isInitContainer[i],
292+
Result: result,
293+
},
294+
)
276295
}
296+
297+
results = append(results, PodResult{Pod: pod, Results: containerResults})
277298
}
278299

279300
return results, nil

pkg/datagatherer/versionchecker/versionchecker_test.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,18 @@ registries:
225225
]
226226
}
227227
},
228-
"result": {
229-
"CurrentVersion": "v1.0.0",
230-
"LatestVersion": "v1.0.1",
231-
"IsLatest": false,
232-
"ImageURL": "%s/jetstack/example"
233-
}
228+
"results": [
229+
{
230+
"container_name": "example",
231+
"init_container": false,
232+
"result": {
233+
"CurrentVersion": "v1.0.0",
234+
"LatestVersion": "v1.0.1",
235+
"IsLatest": false,
236+
"ImageURL": "%s/jetstack/example"
237+
}
238+
}
239+
]
234240
}
235241
]`, parsedURL.Host, parsedURL.Host)
236242

0 commit comments

Comments
 (0)