Skip to content

Commit

Permalink
revert back to the older version plus add comments
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Gilgur <agilgur5@gmail.com>
  • Loading branch information
agilgur5 committed Jun 23, 2024
1 parent 213151d commit 39c44cb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 45 deletions.
24 changes: 3 additions & 21 deletions ui/src/app/shared/pod-name.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import {NodeStatus, Workflow} from '../../models';
import {ANNOTATION_KEY_POD_NAME_VERSION} from './annotations';

import {
createFNVHash,
ensurePodNamePrefixLength,
getPodName,
getTemplateNameFromNode,
k8sNamingHashLength,
maxK8sResourceNameLength,
POD_NAME_V1,
POD_NAME_V2,
getNodeIdFromNodeName
} from './pod-name';
import {createFNVHash, ensurePodNamePrefixLength, getPodName, getTemplateNameFromNode, k8sNamingHashLength, maxK8sResourceNameLength, POD_NAME_V1, POD_NAME_V2} from './pod-name';


describe('pod names', () => {
test('createFNVHash', () => {
Expand Down Expand Up @@ -62,6 +53,7 @@ describe('pod names', () => {
expect(getPodName(wf, node)).toEqual(v2podName);
delete wf.metadata.annotations;
expect(getPodName(wf, node)).toEqual(v2podName);
expect(getPodName(wf, {...node, name: node.name + '.mycontainername', type: 'Container'})).toEqual(v2podName); // containerSet node check

wf.metadata.name = longWfName;
node.templateName = longTemplateName;
Expand All @@ -86,14 +78,4 @@ describe('pod names', () => {
node.templateName = 'test-template';
expect(getTemplateNameFromNode(node)).toEqual(node.templateName);
});

test('getNodeIdFromNodeName', () => {
const wf = {
metadata: {
name: 'outputs-result-5cffb'
}
} as unknown as Workflow;
expect(getNodeIdFromNodeName(wf, 'outputs-result-5cffb.a.main')).toEqual('outputs-result-5cffb-534491738');
expect(getNodeIdFromNodeName(wf, 'outputs-result-5cffb.b')).toEqual('outputs-result-5cffb-3597813194');
});
});
20 changes: 6 additions & 14 deletions ui/src/app/shared/pod-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ const maxPrefixLength = maxK8sResourceNameLength - k8sNamingHashLength;
// 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
// note: this is intended to be equivalent to the server-side Go code in workflow/util/pod_name.go#GeneratePodName
export function getPodName(workflow: Workflow, node: NodeStatus): string {
const version = workflow.metadata?.annotations?.[ANNOTATION_KEY_POD_NAME_VERSION];
if (version === POD_NAME_V1) {
return node.id;
}

const workflowName = workflow.metadata.name;
if (workflowName === node.name) {
// convert containerSet node name to its corresponding pod node name by removing the ".<containerName>" postfix
// this part is from workflow/controller/container_set_template.go#executeContainerSet; the inverse never happens in the back-end, so is unique to the front-end
const podNodeName = node.type == 'Container' ? node.name.replace(/\.[^/.]+$/, '') : node.name;
if (workflowName === podNodeName) {
return workflowName;
}

Expand All @@ -30,7 +33,7 @@ export function getPodName(workflow: Workflow, node: NodeStatus): string {
}
prefix = ensurePodNamePrefixLength(prefix);

const hash = createFNVHash(node.name);
const hash = createFNVHash(podNodeName);
return `${prefix}-${hash}`;
}

Expand Down Expand Up @@ -58,14 +61,3 @@ export function getTemplateNameFromNode(node: NodeStatus): string {
// fall back to v1 pod names if no templateName or templateRef defined
return node.templateName || node.templateRef?.template || '';
}

// Calculates the node id from a node name.
// note: this is intended to be equivalent to the server-side Go code in pkg/apis/workflow/v1alpha1/workflow_types.go
export function getNodeIdFromNodeName(workflow: Workflow, nodeName: string): string {
if (workflow.metadata.name === nodeName) {
return workflow.metadata.name;
}

const hash = createFNVHash(nodeName);
return `${workflow.metadata.name}-${hash}`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {useCollectEvent} from '../../../shared/use-collect-event';
import {hasArtifactGCError, hasWarningConditionBadge} from '../../../shared/conditions-panel';
import {Context} from '../../../shared/context';
import {historyUrl} from '../../../shared/history';
import {getPodName, getNodeIdFromNodeName} from '../../../shared/pod-name';
import {getPodName} from '../../../shared/pod-name';
import {RetryWatch} from '../../../shared/retry-watch';
import {services} from '../../../shared/services';
import {getResolvedTemplates} from '../../../shared/template-resolution';
Expand Down Expand Up @@ -472,15 +472,7 @@ export function WorkflowDetails({history, location, match}: RouteComponentProps<
});
}

const podName = (() => {
if (workflow && selectedNode?.type === 'Container') {
// A containerset node name can be converted to its corresponding pod node name by removing the postfix
const podNodeName = selectedNode.name.replace(/\.[^/.]+$/, '');
const podNode = workflow.status.nodes[getNodeIdFromNodeName(workflow, podNodeName)];
return getPodName(workflow, podNode);
} else if (workflow && selectedNode) return getPodName(workflow, selectedNode);
else return nodeId;
})();
const podName = workflow && selectedNode ? getPodName(workflow, selectedNode) : nodeId;

const archived = isArchivedWorkflow(workflow);

Expand Down

0 comments on commit 39c44cb

Please sign in to comment.