Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add parent namespace and cluster information #3608

Closed
wants to merge 11 commits into from
Closed
4 changes: 4 additions & 0 deletions src/util/customTransformer-faas.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const {
executeFaasFunction,
FAAS_AST_FN_NAME,
FAAS_AST_VID,
PARENT_NAMESPACE,
PARENT_CLUSTER,
} = require('./openfaas');
const { getLibraryCodeV1 } = require('./customTransforrmationsStore-v1');

Expand All @@ -30,6 +32,8 @@ function generateFunctionName(userTransformation, libraryVersionIds, testMode, h
ids = ids.concat([hashSecret]);
}

ids = ids.concat([PARENT_NAMESPACE, PARENT_CLUSTER]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: add this line above hashsecret


// FIXME: Why the id's are sorted ?!
const hash = crypto.createHash('md5').update(`${ids}`).digest('hex');
return `fn-${userTransformation.workspaceId}-${hash}`.substring(0, 63).toLowerCase();
Expand Down
7 changes: 7 additions & 0 deletions src/util/openfaas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -431,6 +436,8 @@ module.exports = {
buildOpenfaasFn,
FAAS_AST_VID,
FAAS_AST_FN_NAME,
PARENT_NAMESPACE,
PARENT_CLUSTER,
setFunctionInCache,
reconcileFunction,
};
3 changes: 2 additions & 1 deletion test/__tests__/user_transformation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ const pyfaasFuncName = (workspaceId, versionId, libraryVersionIds=[], hashSecret
if (hashSecret !== "") {
ids = ids.concat([hashSecret]);
}
ids = ids.concat(["default", "default"]);

const hash = crypto.createHash('md5').update(`${ids}`).digest('hex');

Expand All @@ -119,7 +120,7 @@ describe("User transformation utils", () => {
[],
false,
'hash-secret');
expect(fnName).toEqual('fn-workspaceid-34a32ade07ebbc7bc5ea795b8200de9f');
expect(fnName).toEqual('fn-workspaceid-c9345699beabf6de99a764cdb1a349e5');
});

});
Expand Down
Loading