Skip to content

Commit 9d31fca

Browse files
committed
chore: add workload name for skope warn logging
We don't have much context for where the failed pulling image is coming from in the warning log in Skopeo pull. By adding the workload name, we hope to get some association to see where the image is coming from.
1 parent 67b1b83 commit 9d31fca

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

src/scanner/images/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,30 @@ const statAsync = promisify(stat);
2323
*/
2424
async function pullImageBySkopeoRepo(
2525
imageToPull: IPullableImage,
26+
workloadName: string,
2627
): Promise<IPullableImage> {
2728
// Scan image by digest if exists, other way fallback tag
2829
const scanId = imageToPull.imageWithDigest ?? imageToPull.imageName;
2930
await skopeoCopy(
3031
scanId,
3132
imageToPull.fileSystemPath,
3233
imageToPull.skopeoRepoType,
34+
workloadName,
3335
);
3436
return imageToPull;
3537
}
3638

3739
export async function pullImages(
3840
images: IPullableImage[],
41+
workloadName: string,
3942
): Promise<IPullableImage[]> {
4043
const pulledImages: IPullableImage[] = [];
4144
for (const image of images) {
4245
if (!image.fileSystemPath) {
4346
continue;
4447
}
4548
try {
46-
const pulledImage = await pullImageBySkopeoRepo(image);
49+
const pulledImage = await pullImageBySkopeoRepo(image, workloadName);
4750
pulledImages.push(pulledImage);
4851
} catch (error) {
4952
logger.error(

src/scanner/images/skopeo.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export async function pull(
3636
image: string,
3737
destination: string,
3838
skopeoRepoType: SkopeoRepositoryType,
39+
workloadName: string,
3940
): Promise<void> {
4041
const creds = await credentials.getSourceCredentials(image);
4142
const credentialsParameters = getCredentialParameters(creds);
@@ -56,12 +57,13 @@ export async function pull(
5657
sanitise: false,
5758
});
5859

59-
await pullWithRetry(args, destination);
60+
await pullWithRetry(args, destination, workloadName);
6061
}
6162

6263
async function pullWithRetry(
6364
args: Array<processWrapper.IProcessArgument>,
6465
destination: string,
66+
workloadName: string,
6567
): Promise<void> {
6668
const MAX_ATTEMPTS = 10;
6769
const RETRY_INTERVAL_SEC = 0.2;
@@ -77,7 +79,7 @@ async function pullWithRetry(
7779
}
7880
} catch (deleteErr) {
7981
logger.warn(
80-
{ error: deleteErr, destination },
82+
{ workloadName, error: deleteErr, destination },
8183
'could not clean up the Skopeo-copy archive',
8284
);
8385
}

src/scanner/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export async function processWorkload(
4141
);
4242
const imagesWithFileSystemPath = getImagesWithFileSystemPath(uniqueImages);
4343
const imagePullStartTimestampMs = Date.now();
44-
const pulledImages = await pullImages(imagesWithFileSystemPath);
44+
const pulledImages = await pullImages(imagesWithFileSystemPath, workloadName);
4545
const imagePullDurationMs = Date.now() - imagePullStartTimestampMs;
4646
if (pulledImages.length === 0) {
4747
logger.info(

test/unit/scanner/images.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ describe('getImagesWithFileSystemPath()', () => {
5858
describe('pullImages()', () => {
5959
it('skips on missing file system path', async () => {
6060
const badImage = [{ imageName: 'nginx:latest' }];
61-
const result = await scannerImages.pullImages(badImage as IPullableImage[]);
61+
const workloadName = 'workload';
62+
const result = await scannerImages.pullImages(
63+
badImage as IPullableImage[],
64+
workloadName,
65+
);
6266
expect(result).toEqual([]);
6367
});
6468
});

0 commit comments

Comments
 (0)