@@ -236,8 +236,14 @@ type DataGatherer struct {
236236// of the containers for that pod. Exported so the backend can destructure
237237// json.
238238type 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
0 commit comments