File tree Expand file tree Collapse file tree 2 files changed +32
-8
lines changed Expand file tree Collapse file tree 2 files changed +32
-8
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,12 @@ export function buildImageMetadata(
2626 containerNameToStatus [ containerStatus . name ] = containerStatus ;
2727 }
2828
29- const images = containerStatuses . map ( ( { name : containerName } ) => ( {
29+ const images : IWorkload [ ] = [ ] ;
30+ for ( const containerStatus of containerStatuses ) {
31+ if ( ! ( containerStatus . name in containerNameToSpec ) ) {
32+ continue
33+ }
34+ images . push ( {
3035 type : kind ,
3136 name : name || 'unknown' ,
3237 namespace,
@@ -35,14 +40,15 @@ export function buildImageMetadata(
3540 uid,
3641 specLabels : specMeta . labels || { } ,
3742 specAnnotations : specMeta . annotations || { } ,
38- containerName,
39- imageName : containerNameToSpec [ containerName ] . image ,
40- imageId : containerNameToStatus [ containerName ] . imageID ,
43+ containerName : containerStatus . name ,
44+ imageName : containerNameToSpec [ containerStatus . name ] . image ,
45+ imageId : containerNameToStatus [ containerStatus . name ] . imageID ,
4146 cluster : currentClusterName ,
4247 revision,
4348 podSpec,
44- } as IWorkload ) ,
45- ) ;
49+ } as IWorkload ) ;
50+ }
51+
4652 return images ;
4753}
4854
Original file line number Diff line number Diff line change @@ -72,8 +72,26 @@ tap.test('buildImageMetadata', async (t) => {
7272 podSpec : deploymentObject . spec ! . template . spec ! ,
7373 }
7474
75- t . throws ( ( ) => metadataExtractor . buildImageMetadata (
75+ const imageMetadataResult = metadataExtractor . buildImageMetadata (
7676 deploymentWeirdWrapper ,
7777 podObject . status ! . containerStatuses ! ,
78- ) , 'buildImageMetadata can\'t handle discrepancies between spec and status' ) ;
78+ ) ;
79+
80+ t . ok ( Array . isArray ( imageMetadataResult ) , 'returns an array' ) ;
81+ t . equals (
82+ imageMetadataResult . length ,
83+ 1 ,
84+ 'the size of the container status array that also appears in the spec' ,
85+ ) ;
86+ t . equals ( imageMetadataResult [ 0 ] . type , 'Deployment' , 'with the workload type of the parent' ) ;
87+ t . equals (
88+ imageMetadataResult [ 0 ] . imageId ,
89+ 'docker-pullable://eu.gcr.io/cookie/hello-world@sha256:1ac413b2756364b7b856c64d557fdedb97a4ba44ca16fc656e08881650848fe2' ,
90+ 'the image ID of the first container'
91+ ) ;
92+ t . equals (
93+ imageMetadataResult [ 0 ] . imageName ,
94+ 'eu.gcr.io/cookie/hello-world:1.20191125.132107-4664980' ,
95+ 'the image name of the first container'
96+ ) ;
7997} ) ;
You can’t perform that action at this time.
0 commit comments