Skip to content
This repository has been archived by the owner on Jan 11, 2021. It is now read-only.

Add monitoring of container image deployments #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ node_modules
package-lock.json
yarn.lock
config/local*.yaml
*.idea
*.iml
1 change: 1 addition & 0 deletions src/monitors/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = [
require('./waitingpods'),
require('./longnotready'),
require('./newdeployment'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're using one tab indentation. Please reindent this line and the monitor file.

];
44 changes: 44 additions & 0 deletions src/monitors/newdeployment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const EventEmitter = require('events');
const config = require('config');
const kube = require('../kube');

class DeploymentStatus extends EventEmitter{
constructor(){
super();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have nothing but super(); in your constructor, it can be omitted.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually from below, we'll need the constructor to initialize the state store.

}

start(){
setInterval(() => {
this.check();
}, config.get('interval'));

return this;
}

async check(){
let containers = await kube.getContainerStatuses();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think rather than checking for newly deployed containers, we should check for newly deployed pods. This is available in kube.getPods();


for(let item of containers){
if(!item.image === global.image){
continue;
}

if(!item.ready){
continue;
}

this.emit('message', {
fallback: `Container ${item.pod.metadata.namespace}/${item.pod.metadata.name}/${item.name} has deployed image ${item.image}`,
color: 'good',
title: `${item.pod.metadata.namespace}/${item.pod.metadata.name}/${item.name}`,
text: `Container deployed image *${item.image}*`,
mrkdwn_in: ['text'],
_key: `${item.pod.metadata.name}/${item.name}`,
});

global.image = item.image;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is stateful then the state should be stored as instance attribute, rather than as a global variable.

}
}
}

module.exports = () => new DeploymentStatus().start();