From 255f3e52fb66ae6cb55e24938fff60ec6e28b285 Mon Sep 17 00:00:00 2001 From: kanishkkatara Date: Wed, 4 Sep 2024 16:33:26 +0530 Subject: [PATCH] fix: add namespace and cluster labels to python transformation functions --- src/util/customTransformer-faas.js | 4 ++++ src/util/openfaas/index.js | 7 +++++++ test/__tests__/user_transformation.test.js | 3 ++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/util/customTransformer-faas.js b/src/util/customTransformer-faas.js index 07dc205582..0f59f5db60 100644 --- a/src/util/customTransformer-faas.js +++ b/src/util/customTransformer-faas.js @@ -8,6 +8,8 @@ const { executeFaasFunction, FAAS_AST_FN_NAME, FAAS_AST_VID, + PARENT_NAMESPACE, + PARENT_CLUSTER, } = require('./openfaas'); const { getLibraryCodeV1 } = require('./customTransforrmationsStore-v1'); @@ -26,6 +28,8 @@ function generateFunctionName(userTransformation, libraryVersionIds, testMode, h (libraryVersionIds || []).sort(), ); + ids = ids.concat([PARENT_NAMESPACE, PARENT_CLUSTER]); + if (hashSecret !== '') { ids = ids.concat([hashSecret]); } diff --git a/src/util/openfaas/index.js b/src/util/openfaas/index.js index 1f44df86bb..7d4adf2321 100644 --- a/src/util/openfaas/index.js +++ b/src/util/openfaas/index.js @@ -38,6 +38,9 @@ const FAAS_READINESS_HTTP_FAILURE_THRESHOLD = const FAAS_READINESS_HTTP_SUCCESS_THRESHOLD = process.env.FAAS_READINESS_HTTP_SUCCESS_THRESHOLD || '1'; +const PARENT_NAMESPACE = process.env.NAMESPACE || 'default'; +const PARENT_CLUSTER = process.env.FAAS_FN_PARENT_CLUSTER || 'default'; + const CONFIG_BACKEND_URL = process.env.CONFIG_BACKEND_URL || 'https://api.rudderlabs.com'; const GEOLOCATION_URL = process.env.GEOLOCATION_URL || ''; const FAAS_AST_VID = 'ast'; @@ -313,6 +316,8 @@ function buildOpenfaasFn(name, code, versionId, libraryVersionIDs, testMode, trM const labels = { 'openfaas-fn': 'true', 'parent-component': 'openfaas', + 'parent-namespace': PARENT_NAMESPACE, + 'parent-cluster': PARENT_CLUSTER, 'com.openfaas.scale.max': FAAS_MAX_PODS_IN_TEXT, 'com.openfaas.scale.min': FAAS_MIN_PODS_IN_TEXT, 'com.openfaas.scale.zero': FAAS_SCALE_ZERO, @@ -431,6 +436,8 @@ module.exports = { buildOpenfaasFn, FAAS_AST_VID, FAAS_AST_FN_NAME, + PARENT_NAMESPACE, + PARENT_CLUSTER, setFunctionInCache, reconcileFunction, }; diff --git a/test/__tests__/user_transformation.test.js b/test/__tests__/user_transformation.test.js index af3d84173a..eff11b083f 100644 --- a/test/__tests__/user_transformation.test.js +++ b/test/__tests__/user_transformation.test.js @@ -92,6 +92,7 @@ const pyLibCode = (name, versionId) => { const pyfaasFuncName = (workspaceId, versionId, libraryVersionIds=[], hashSecret="") => { let ids = [workspaceId, versionId].concat(libraryVersionIds.sort()); + ids = ids.concat(["default", "default"]); if (hashSecret !== "") { ids = ids.concat([hashSecret]); } @@ -119,7 +120,7 @@ describe("User transformation utils", () => { [], false, 'hash-secret'); - expect(fnName).toEqual('fn-workspaceid-34a32ade07ebbc7bc5ea795b8200de9f'); + expect(fnName).toEqual('fn-workspaceid-91d66b4cea6f0ed16cd41258d138d0a8'); }); });