Skip to content

Commit

Permalink
chore: added parent cluster and namespace in function name
Browse files Browse the repository at this point in the history
  • Loading branch information
kanishkkatara committed Sep 4, 2024
1 parent 57634f1 commit 7c9157e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
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]);

// 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
2 changes: 2 additions & 0 deletions src/util/openfaas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,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

0 comments on commit 7c9157e

Please sign in to comment.