Skip to content

Commit

Permalink
fix(k8s): handle 404 exception when tagging image for deletion (#1485)
Browse files Browse the repository at this point in the history
* fix(k8s): handle 404 exception when tagging image for deletion

* fix(k8s): catch 404 error only

* fix(k8s): cleaner relational check, remove log line
  • Loading branch information
solomonope authored Jan 9, 2020
1 parent 4c51aae commit f7c5ed4
Showing 1 changed file with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,20 +169,26 @@ async function deleteImagesFromRegistry(ctx: KubernetesPluginContext, log: LogEn
})

await Bluebird.map(images, async (image) => {
// Get the digest for the image
const [name, tag] = splitLast(image, ":")
const res = await queryRegistry(ctx, log, `${name}/manifests/${tag}`, {
method: "HEAD",
headers: {
Accept: "application/vnd.docker.distribution.manifest.v2+json",
},
})
const digest = res.headers["docker-content-digest"]
try {
// Get the digest for the image
const [name, tag] = splitLast(image, ":")
const res = await queryRegistry(ctx, log, `${name}/manifests/${tag}`, {
method: "HEAD",
headers: {
Accept: "application/vnd.docker.distribution.manifest.v2+json",
},
})
const digest = res.headers["docker-content-digest"]

// Issue the delete request
await queryRegistry(ctx, log, `${name}/manifests/${digest}`, {
method: "DELETE",
})
// Issue the delete request
await queryRegistry(ctx, log, `${name}/manifests/${digest}`, {
method: "DELETE",
})
} catch (err) {
if (err.response && err.response.status !== 404) {
throw err
}
}
})

log.info(`Flagged ${images.length} images as deleted in the registry.`)
Expand Down

0 comments on commit f7c5ed4

Please sign in to comment.