From 89959c6a0f2273766b02e3aea787b2edd76d82b8 Mon Sep 17 00:00:00 2001 From: Alex Lewitt <48691328+alewitt2@users.noreply.github.com> Date: Thu, 18 Mar 2021 13:35:16 -0400 Subject: [PATCH] feat: set user-agent on kube api-server requests (#168) * feat: set user-agent on kube api-server requests * feat: allow publish rc versions * Update KubeApiConfig.js * Update KubeApiConfig.js * Update KubeApiConfig.js * Update KubeApiConfig.js * Update KubeApiConfig.js * Update lib/KubeApiConfig.js Co-authored-by: Adam King * Update KubeApiConfig.js Co-authored-by: Adam King --- .travis.yml | 12 +++++++++++- lib/KubeApiConfig.js | 4 ++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index cce5927..45461ea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,9 +10,19 @@ script: - if [ "${TRAVIS_PULL_REQUEST}" != "false" ]; then npm audit; else npm audit || true; fi - npm run lint - npm test - - if [ -n "${TRAVIS_TAG}" ]; then npm version --no-git-tag-version "${TRAVIS_TAG}"; fi + - if [[ "${TRAVIS_TAG}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$ ]]; then npm version --no-git-tag-version "${TRAVIS_TAG}"; fi deploy: + # Publish npm package with tag "next" on release candidates + - provider: npm + email: "${NPMJS_EMAIL}" + api_key: "${NPMJS_API_KEY}" + tag: next + skip_cleanup: true + on: + tags: true + condition: ${TRAVIS_TAG} =~ ^[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)$ + # Publish npm package as "latest" on release - provider: npm email: "${NPMJS_EMAIL}" api_key: "${NPMJS_API_KEY}" diff --git a/lib/KubeApiConfig.js b/lib/KubeApiConfig.js index dbf8d9d..3f20ca7 100644 --- a/lib/KubeApiConfig.js +++ b/lib/KubeApiConfig.js @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +const packagejson = require('../package.json'); const fs = require('fs-extra'); const objectPath = require('object-path'); const k8s = require('@kubernetes/client-node'); @@ -74,7 +75,10 @@ module.exports = function kubeApiConfig(options = {}) { } result.baseUrl = cluster.server; + const userAgentName = process.env.USER_AGENT_NAME || 'razee-io/kubernetes-util'; + const userAgentVersion = process.env.USER_AGENT_VERSION || packagejson.version; + objectPath.set(result, 'headers.User-Agent', `${userAgentName}/${userAgentVersion}`); _kubeApiConfig.kubeConfig = result; return result; };