Skip to content

Commit

Permalink
feat(enricher): add runtime labels to resources. (#380)
Browse files Browse the repository at this point in the history
* feat(enricher): add runtime labels to resources.

* This adds more labels to the created resources to better identify that this is a Node.js application in the Developer Topology view in Openshift 4.2

* There are also labels added to the BuildConfig, that allows for better ux when looking at the topolgy view.

fixes #374
  • Loading branch information
lholmquist committed Nov 15, 2019
1 parent 57ad3b7 commit 1028af2
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/build-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ function createBuildConfig (config, options) {
namespace: config.namespace.name,
labels: {
project: config.projectName,
version: config.projectVersion
version: config.projectVersion,
'app.kubernetes.io/name': 'nodejs',
'app.kubernetes.io/component': config.projectName,
'app.kubernetes.io/instance': config.projectName,
'app.openshift.io/runtime': 'nodejs'
}
});

Expand Down
2 changes: 1 addition & 1 deletion lib/resource-enrichers/default-enrichers.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[
"deployment-config", "deployment-env", "service", "route", "labels", "git-info", "health-check"
"deployment-config", "deployment-env", "service", "route", "labels", "git-info", "health-check", "runtime-label"
]
22 changes: 22 additions & 0 deletions lib/resource-enrichers/runtime-label-enricher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

const _ = require('lodash');

async function addRuntimeLabelToResource (config, resourceList) {
const runtimeLabels = {
'app.kubernetes.io/name': 'nodejs',
'app.kubernetes.io/component': config.projectName,
'app.kubernetes.io/instance': config.projectName,
'app.openshift.io/runtime': 'nodejs'
};

return resourceList.map((resource) => {
resource.metadata.labels = _.merge({}, resource.metadata.labels, runtimeLabels);
return resource;
});
}

module.exports = module.exports = {
enrich: addRuntimeLabelToResource,
name: 'runtime-label'
};
43 changes: 43 additions & 0 deletions test/enricher-tests/runtime-label-enricher-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';

const test = require('tape');
const rle = require('../../lib/resource-enrichers/runtime-label-enricher');

const config = {
projectName: 'Project Name',
version: '1.0.0',
namespace: {
name: 'the namespace'
},
port: 8080
};

test('runtime-label-enricher', (t) => {
t.ok(rle.enrich, 'has an enrich property');
t.equal(typeof rle.enrich, 'function', 'enrich property is a function');
t.ok(rle.name, 'has an name property');
t.equal(rle.name, 'runtime-label', 'name property is runtime-label');
t.end();
});

test('test runtime-label addition', async (t) => {
const resourceList = [
{
kind: 'Service',
metadata: {}
},
{
kind: 'Deployment',
metadata: {}
}
];
const le = await rle.enrich(config, resourceList);
t.notEqual(le, resourceList, 'arrays should not be equal');
t.equal(Array.isArray(le), true, 'should return an array');
t.equal(resourceList.length, 2, 'resourceList size should not increases by 2');
t.equal(resourceList[0].metadata.labels['app.openshift.io/runtime'], 'nodejs', 'should have the proper label');
t.equal(resourceList[0].metadata.labels['app.kubernetes.io/name'], 'nodejs', 'should have the proper label');
t.equal(resourceList[0].metadata.labels['app.kubernetes.io/component'], config.projectName, 'should have the proper label');
t.equal(resourceList[0].metadata.labels['app.kubernetes.io/instance'], config.projectName, 'should have the proper label');
t.end();
});

0 comments on commit 1028af2

Please sign in to comment.