Skip to content

Commit

Permalink
fix: Use proper podname for containers
Browse files Browse the repository at this point in the history
Signed-off-by: instauro <instauro@proton.me>
  • Loading branch information
instauro authored and agilgur5 committed Jun 23, 2024
1 parent 6c33cbb commit 213151d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
22 changes: 21 additions & 1 deletion ui/src/app/shared/pod-name.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
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} from './pod-name';
import {
createFNVHash,
ensurePodNamePrefixLength,
getPodName,
getTemplateNameFromNode,
k8sNamingHashLength,
maxK8sResourceNameLength,
POD_NAME_V1,
POD_NAME_V2,
getNodeIdFromNodeName
} from './pod-name';

describe('pod names', () => {
test('createFNVHash', () => {
Expand Down Expand Up @@ -76,4 +86,14 @@ 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');
});
});
11 changes: 11 additions & 0 deletions ui/src/app/shared/pod-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,14 @@ 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} from '../../../shared/pod-name';
import {getPodName, getNodeIdFromNodeName} 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,7 +472,15 @@ export function WorkflowDetails({history, location, match}: RouteComponentProps<
});
}

const podName = workflow && selectedNode ? getPodName(workflow, selectedNode) : nodeId;
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 archived = isArchivedWorkflow(workflow);

Expand Down

0 comments on commit 213151d

Please sign in to comment.