-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(enricher): add runtime labels to resources. (#380)
* 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
1 parent
57ad3b7
commit 1028af2
Showing
4 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |