-
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): Adds the rh-metering flag for adding Red Hat Runtimes…
… metering to your application. (#543) * feat(enricher): Adds the rh-metering flag for adding Red Hat Runtimes metering to your application. * The new flag is `--rh-metering`. can also be used as `--rh-metering.nodeVersion=NODE_VERSION` * This is currently an undocumented feature since it is more for those using Red Hat Runtimes build of Node.js
- Loading branch information
1 parent
089809e
commit 0486d33
Showing
9 changed files
with
315 additions
and
17 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
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
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", "runtime-label" | ||
"deployment-config", "deployment-env", "service", "route", "labels", "git-info", "health-check", "runtime-label", "meterting" | ||
] |
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", "service", "route", "labels", "git-info", "health-check", "runtime-label" | ||
"deployment", "service", "route", "labels", "git-info", "health-check", "runtime-label", "meterting" | ||
] |
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,86 @@ | ||
/* | ||
* | ||
* Copyright 2016-2017 Red Hat, Inc, and individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// Enricher for adding metering metadata | ||
const METERING_LABELS = { | ||
'com.redhat.component-name': 'Node.js', | ||
'com.redhat.component-type': 'application', | ||
'com.redhat.component-version': '14.x.x', // Need to look at the image | ||
'com.redhat.product-name': 'Red_Hat_Runtimes', | ||
'com.redhat.product-version': '2021/Q1' // Node 14 - 2021/Q1 Node 16 2021/Q4(?) | ||
}; | ||
|
||
const _ = require('lodash'); | ||
|
||
function parseNodeMajor (nodeVersion) { | ||
return nodeVersion.split('.')[0]; | ||
} | ||
|
||
function getProductVersion (nodeVersion) { | ||
let productVersion; | ||
switch (parseNodeMajor(nodeVersion)) { | ||
case '14': | ||
productVersion = '2021/Q1'; | ||
break; | ||
default: | ||
productVersion = 'unknown'; | ||
break; | ||
} | ||
|
||
return productVersion; | ||
} | ||
|
||
function parseNodeImage (imageName) { | ||
const split = imageName.split('/'); | ||
|
||
const justNode = split.find((val) => { | ||
return val.includes('nodejs'); | ||
}); | ||
|
||
const nodeVersion = justNode.split('-')[1]; | ||
return nodeVersion; | ||
} | ||
|
||
async function addMeteringInfo (config, resourceList) { | ||
return resourceList.map((resource) => { | ||
if (resource.kind === 'DeploymentConfig' || resource.kind === 'Deployment') { | ||
// Check that the metering flag was added | ||
// Also check that a "Red Hat" image is being used? | ||
if (!config.metering) { | ||
return resource; | ||
} | ||
|
||
const nodeVersion = config.metering.nodeVersion ? config.metering.nodeVersion : parseNodeImage(config.dockerImage); | ||
|
||
resource.spec.template.metadata.labels = _.merge({}, METERING_LABELS, resource.spec.template.metadata.labels); | ||
resource.spec.template.metadata.labels['com.redhat.component-version'] = nodeVersion; | ||
resource.spec.template.metadata.labels['com.redhat.product-version'] = getProductVersion(nodeVersion); | ||
|
||
return resource; | ||
} | ||
|
||
return resource; | ||
}); | ||
} | ||
|
||
module.exports = { | ||
enrich: addMeteringInfo, | ||
name: 'metering' | ||
}; |
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
Oops, something went wrong.