Skip to content

Commit

Permalink
fix(ui): don't use Buffer for FNV hash (#11766)
Browse files Browse the repository at this point in the history
  • Loading branch information
agilgur5 authored and terrytangyuan committed Oct 19, 2023
1 parent 9ebb70a commit f553d7f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions ui/src/app/shared/pod-name.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe('pod names', () => {
expect(createFNVHash('You cannot alter your fate. However, you can rise to meet it.')).toEqual(827171719);
});

// note: the below is intended to be equivalent to the server-side Go code in workflow/util/pod_name_test.go
const nodeName = 'nodename';
const nodeID = '1';

Expand Down
9 changes: 5 additions & 4 deletions ui/src/app/shared/pod-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const k8sNamingHashLength = 10;
// getPodName returns a deterministic pod name
// In case templateName is not defined or that version is explicitly set to POD_NAME_V1, it will return the nodeID (v1)
// In other cases it will return a combination of workflow name, template name, and a hash (v2)
// note: this is intended to be equivalent to the server-side Go code in workflow/util/pod_name.go
export const getPodName = (workflowName: string, nodeName: string, templateName: string, nodeID: string, version: string): string => {
if (version !== POD_NAME_V1 && templateName !== '') {
if (workflowName === nodeName) {
Expand All @@ -35,17 +36,17 @@ export const ensurePodNamePrefixLength = (prefix: string): string => {
};

export const createFNVHash = (input: string): number => {
const data = Buffer.from(input);

let hashint = 2166136261;

/* tslint:disable:no-bitwise */
for (const character of data) {
for (let i = 0; i < input.length; i++) {
const character = input.charCodeAt(i);
/* tslint:disable:no-bitwise */
hashint = hashint ^ character;
hashint += (hashint << 1) + (hashint << 4) + (hashint << 7) + (hashint << 8) + (hashint << 24);
}

return hashint >>> 0;
/* tslint:enable:no-bitwise */
};

export const getTemplateNameFromNode = (node: NodeStatus): string => {
Expand Down

0 comments on commit f553d7f

Please sign in to comment.