From 071875b406dd95b36b934d83e66c9d570d322521 Mon Sep 17 00:00:00 2001 From: Joel Lappalainen Date: Mon, 20 Jan 2025 14:59:31 +0200 Subject: [PATCH 1/4] Use preferably use deployment title instead of app for slack messages --- src/image-freshness-monitor.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/image-freshness-monitor.js b/src/image-freshness-monitor.js index 241ef64..4e37600 100644 --- a/src/image-freshness-monitor.js +++ b/src/image-freshness-monitor.js @@ -22,14 +22,15 @@ export default { const promises = [] deploymentsNeedingCheck.forEach(deployment => { const deploymentId = deployment.metadata.labels.app + const deploymentTitle = deployment.metadata.labels.title || deploymentId const image = deployment.spec.template.spec.containers[0].image - console.log(`Deployment ${deployment.metadata.labels.app} needs image freshness check`) + console.log(`Deployment ${deploymentId} needs image freshness check`) promises.push(new Promise((resolve) => { context.dockerRepo.getImageDate(image).then(repoImageDate => { // check that image is older than 12 hours old if (repoImageDate && repoImageDate < now.getTime() - 12 * 60 * 60 * 1000) { console.log('%s image has not been updated within the last 12 hours', deploymentId) - resolve(deployment.metadata.labels.app) + resolve(deploymentTitle) } else { console.log('%s image has been updated within the last 12 hours', deploymentId) resolve(null) From 88100b0822a6fad80e517dd8396741164b80018a Mon Sep 17 00:00:00 2001 From: Joel Lappalainen Date: Mon, 20 Jan 2025 15:48:10 +0200 Subject: [PATCH 2/4] Add label for deployment title for image freshness check slack messages --- src/image-freshness-monitor.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/image-freshness-monitor.js b/src/image-freshness-monitor.js index 4e37600..fdb7719 100644 --- a/src/image-freshness-monitor.js +++ b/src/image-freshness-monitor.js @@ -6,8 +6,10 @@ import { postAlertSlackMessage } from './util.js' * has been updated within last 24 hours. If not, a message is sent to slack. * Configured with labels as follows: * checkImageFreshnessAt: "hh.mm" + * imageFreshnessTitle: "Service_X" * where checkImageFreshnessAt defines when the check should be done (roughly, - * might be delayed by 0-5 mins) + * might be delayed by 0-5 mins) and imageFreshnessTitle is the deployment's title used in + * slack messaging. */ export default { command: (deployments, context) => { @@ -22,7 +24,7 @@ export default { const promises = [] deploymentsNeedingCheck.forEach(deployment => { const deploymentId = deployment.metadata.labels.app - const deploymentTitle = deployment.metadata.labels.title || deploymentId + const deploymentTitle = deployment.metadata.labels.imageFreshnessTitle || deploymentId const image = deployment.spec.template.spec.containers[0].image console.log(`Deployment ${deploymentId} needs image freshness check`) promises.push(new Promise((resolve) => { @@ -44,7 +46,7 @@ export default { Promise.all(promises).then((values) => { const deploymentsWithOldImages = values.filter(value => value != null) if (deploymentsWithOldImages.length > 0) { - postAlertSlackMessage(`:boom: These deployments have not been updated within the last 12 hours: ${deploymentsWithOldImages.join(', ')} :boom:`) + postAlertSlackMessage(`:boom: These services have not been updated within the last 12 hours: ${deploymentsWithOldImages.join(', ')} :boom:`) } }) } From d711b32ceaa2a87ed0941542fca1d73707689852 Mon Sep 17 00:00:00 2001 From: Joel Lappalainen Date: Mon, 20 Jan 2025 15:48:21 +0200 Subject: [PATCH 3/4] Update README --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8d638fb..bc7a542 100644 --- a/README.md +++ b/README.md @@ -80,11 +80,18 @@ Optional label that defines in minutes how long time has to be since the last re Optionally, it can be checked that an image has been updated within the last 12 hours. -This can be enabled with `checkImageFreshnessAt` label that defines when the check is done in `hh.mm` format: +Example config: ```yaml metadata: labels: update: "auto" checkImageFreshnessAt: "09.00" + imageFreshnessTitle: "Service_X" ``` + +### checkImageFreshnessAt: "04.30" +Label that defines when the check is done in `hh.mm`. If multiple deployments have identical check times, the checks and messaging are grouped together. + +### imageFreshnessTitle: "240" +The title which is used for the deployment when messaging about image freshness over slack. From 9ec228767d006512b31fc68f87c4a95c81634b9f Mon Sep 17 00:00:00 2001 From: Joel Lappalainen Date: Mon, 20 Jan 2025 15:51:57 +0200 Subject: [PATCH 4/4] Clarify message --- src/image-freshness-monitor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/image-freshness-monitor.js b/src/image-freshness-monitor.js index fdb7719..9fb24dd 100644 --- a/src/image-freshness-monitor.js +++ b/src/image-freshness-monitor.js @@ -46,7 +46,7 @@ export default { Promise.all(promises).then((values) => { const deploymentsWithOldImages = values.filter(value => value != null) if (deploymentsWithOldImages.length > 0) { - postAlertSlackMessage(`:boom: These services have not been updated within the last 12 hours: ${deploymentsWithOldImages.join(', ')} :boom:`) + postAlertSlackMessage(`:boom: These have not been updated within the last 12 hours: ${deploymentsWithOldImages.join(', ')} :boom:`) } }) }