Skip to content

Commit 7cdbee0

Browse files
JPZ13sarabala1979
authored andcommitted
fix(ui): Change pod names to new format. Fixes argoproj#6865 (argoproj#6925)
1 parent 5df91b2 commit 7cdbee0

File tree

6 files changed

+82
-7
lines changed

6 files changed

+82
-7
lines changed

ui/src/app/archived-workflows/components/archived-workflow-details/archived-workflow-details.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {ResourceEditor} from '../../../shared/components/resource-editor/resourc
1212
import {services} from '../../../shared/services';
1313
import {WorkflowArtifacts} from '../../../workflows/components/workflow-artifacts';
1414

15+
import {Utils} from '../../../shared/utils';
1516
import {WorkflowResourcePanel} from '../../../workflows/components/workflow-details/workflow-resource-panel';
1617
import {WorkflowLogsViewer} from '../../../workflows/components/workflow-logs-viewer/workflow-logs-viewer';
1718
import {WorkflowNodeInfo} from '../../../workflows/components/workflow-node-info/workflow-node-info';
@@ -217,7 +218,9 @@ export class ArchivedWorkflowDetails extends BasePage<RouteComponentProps<any>,
217218
)}
218219
<SlidingPanel isShown={!!this.sidePanel} onClose={() => (this.sidePanel = null)}>
219220
{this.sidePanel === 'yaml' && <WorkflowYamlViewer workflow={this.state.workflow} selectedNode={this.node} />}
220-
{this.sidePanel === 'logs' && <WorkflowLogsViewer workflow={this.state.workflow} nodeId={this.nodeId} container={this.container} archived={true} />}
221+
{this.sidePanel === 'logs' && (
222+
<WorkflowLogsViewer workflow={this.state.workflow} initialPodName={this.podName} nodeId={this.nodeId} container={this.container} archived={true} />
223+
)}
221224
{this.sidePanel === 'resubmit' && (
222225
<ResourceEditor<Workflow>
223226
editing={true}
@@ -246,6 +249,14 @@ export class ArchivedWorkflowDetails extends BasePage<RouteComponentProps<any>,
246249
return this.nodeId && this.state.workflow.status.nodes[this.nodeId];
247250
}
248251

252+
private get podName() {
253+
if (this.nodeId && this.state.workflow) {
254+
const workflowName = this.state.workflow.metadata.name;
255+
const {name, templateName} = this.node;
256+
return Utils.getPodName(workflowName, name, templateName, this.nodeId);
257+
}
258+
}
259+
249260
private deleteArchivedWorkflow() {
250261
if (!confirm('Are you sure you want to delete this archived workflow?\nThere is no undo.')) {
251262
return;

ui/src/app/shared/utils.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import {NODE_PHASE} from '../../models';
44

55
const managedNamespaceKey = 'managedNamespace';
66
const currentNamespaceKey = 'current_namespace';
7+
const maxK8sResourceNameLength = 253;
8+
const k8sNamingHashLength = 10;
9+
710
export const Utils = {
811
statusIconClasses(status: string): string {
912
let classes = [];
@@ -117,5 +120,42 @@ export const Utils = {
117120
// return a namespace, never return null/undefined, defaults to "default"
118121
getNamespaceWithDefault(namespace: string) {
119122
return this.managedNamespace || namespace || this.currentNamespace || 'default';
123+
},
124+
125+
ensurePodNamePrefixLength(prefix: string): string {
126+
const maxPrefixLength = maxK8sResourceNameLength - k8sNamingHashLength;
127+
128+
if (prefix.length > maxPrefixLength - 1) {
129+
return prefix.substring(0, maxPrefixLength - 1);
130+
}
131+
132+
return prefix;
133+
},
134+
135+
// getPodName returns a deterministic pod name
136+
getPodName(workflowName: string, nodeName: string, templateName: string, nodeID: string): string {
137+
if (workflowName === nodeName) {
138+
return workflowName;
139+
}
140+
141+
let prefix = `${workflowName}-${templateName}`;
142+
prefix = this.ensurePodNamePrefixLength(prefix);
143+
144+
const hash = createFNVHash(nodeName);
145+
return `${prefix}-${hash}`;
146+
}
147+
};
148+
149+
const createFNVHash = (input: string): number => {
150+
const data = new Buffer(input);
151+
152+
let hashint = 2166136261;
153+
154+
/* tslint:disable:no-bitwise */
155+
for (const character of data) {
156+
hashint = hashint ^ character;
157+
hashint += (hashint << 1) + (hashint << 4) + (hashint << 7) + (hashint << 8) + (hashint << 24);
120158
}
159+
160+
return hashint >>> 0;
121161
};

ui/src/app/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"experimentalDecorators": true,
1010
"noUnusedLocals": true,
1111
"declaration": false,
12+
"downlevelIteration": true,
1213
"lib": [
1314
"es2017",
1415
"dom"

ui/src/app/workflows/components/workflow-details/workflow-details.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as classNames from 'classnames';
33
import * as React from 'react';
44
import {useContext, useEffect, useState} from 'react';
55
import {RouteComponentProps} from 'react-router';
6-
import {execSpec, Link, Workflow} from '../../../../models';
6+
import {execSpec, Link, NodeStatus, Workflow} from '../../../../models';
77
import {uiUrl} from '../../../shared/base';
88
import {CostOptimisationNudge} from '../../../shared/components/cost-optimisation-nudge';
99
import {ErrorNotice} from '../../../shared/components/error-notice';
@@ -16,6 +16,7 @@ import {historyUrl} from '../../../shared/history';
1616
import {RetryWatch} from '../../../shared/retry-watch';
1717
import {services} from '../../../shared/services';
1818
import {useQueryParams} from '../../../shared/use-query-params';
19+
import {Utils} from '../../../shared/utils';
1920
import * as Operations from '../../../shared/workflow-operations-map';
2021
import {WorkflowOperations} from '../../../shared/workflow-operations-map';
2122
import {WidgetGallery} from '../../../widgets/widget-gallery';
@@ -224,7 +225,18 @@ export const WorkflowDetails = ({history, location, match}: RouteComponentProps<
224225
}
225226
};
226227

228+
229+
const getPodName = (wf: Workflow, node: NodeStatus, nodeID: string): string => {
230+
if (workflow && node) {
231+
return Utils.getPodName(wf.metadata.name, node.name, node.templateName, node.id);
232+
}
233+
234+
return nodeID;
235+
};
236+
227237
const selectedNode = workflow && workflow.status && workflow.status.nodes && workflow.status.nodes[nodeId];
238+
const podName = getPodName(workflow, selectedNode, nodeId);
239+
228240
return (
229241
<Page
230242
title={'Workflow Details'}
@@ -292,7 +304,7 @@ export const WorkflowDetails = ({history, location, match}: RouteComponentProps<
292304
{workflow && (
293305
<SlidingPanel isShown={!!sidePanel} onClose={() => setSidePanel(null)}>
294306
{parsedSidePanel.type === 'logs' && (
295-
<WorkflowLogsViewer workflow={workflow} nodeId={parsedSidePanel.nodeId} container={parsedSidePanel.container} archived={false} />
307+
<WorkflowLogsViewer workflow={workflow} initialPodName={podName} nodeId={parsedSidePanel.nodeId} container={parsedSidePanel.container} archived={false} />
296308
)}
297309
{parsedSidePanel.type === 'events' && <EventsPanel namespace={namespace} kind='Pod' name={parsedSidePanel.nodeId} />}
298310
{parsedSidePanel.type === 'share' && <WidgetGallery namespace={namespace} name={name} />}

ui/src/app/workflows/components/workflow-logs-viewer/workflow-logs-viewer.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ import {ErrorNotice} from '../../../shared/components/error-notice';
99
import {InfoIcon, WarningIcon} from '../../../shared/components/fa-icons';
1010
import {Links} from '../../../shared/components/links';
1111
import {services} from '../../../shared/services';
12+
import {Utils} from '../../../shared/utils';
1213
import {FullHeightLogsViewer} from './full-height-logs-viewer';
1314

1415
interface WorkflowLogsViewerProps {
1516
workflow: models.Workflow;
1617
nodeId?: string;
18+
initialPodName: string;
1719
container: string;
1820
archived: boolean;
1921
}
@@ -22,8 +24,8 @@ function identity<T>(value: T) {
2224
return () => value;
2325
}
2426

25-
export const WorkflowLogsViewer = ({workflow, nodeId, container, archived}: WorkflowLogsViewerProps) => {
26-
const [podName, setPodName] = useState(nodeId || '');
27+
export const WorkflowLogsViewer = ({workflow, nodeId, initialPodName, container, archived}: WorkflowLogsViewerProps) => {
28+
const [podName, setPodName] = useState(initialPodName || '');
2729
const [selectedContainer, setContainer] = useState(container);
2830
const [grep, setGrep] = useState('');
2931
const [error, setError] = useState<Error>();
@@ -59,7 +61,11 @@ export const WorkflowLogsViewer = ({workflow, nodeId, container, archived}: Work
5961
const podNames = [{value: '', label: 'All'}].concat(
6062
Object.values(workflow.status.nodes || {})
6163
.filter(x => x.type === 'Pod')
62-
.map(x => ({value: x.id, label: (x.displayName || x.name) + ' (' + x.id + ')'}))
64+
.map(targetNode => {
65+
const {name, id, templateName, displayName} = targetNode;
66+
const targetPodName = Utils.getPodName(workflow.metadata.name, name, templateName, id);
67+
return {value: targetPodName, label: (displayName || name) + ' (' + targetPodName + ')'};
68+
})
6369
);
6470

6571
const node = workflow.status.nodes[nodeId];

ui/src/app/workflows/components/workflow-node-info/workflow-node-info.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {Timestamp} from '../../../shared/components/timestamp';
1515
import {ResourcesDuration} from '../../../shared/resources-duration';
1616
import {services} from '../../../shared/services';
1717
import {getResolvedTemplates} from '../../../shared/template-resolution';
18+
import {Utils} from '../../../shared/utils';
1819

1920
require('./workflow-node-info.scss');
2021

@@ -78,6 +79,10 @@ const AttributeRows = (props: {attributes: {title: string; value: any}[]}) => (
7879
);
7980

8081
const WorkflowNodeSummary = (props: Props) => {
82+
const {workflow, node} = props;
83+
84+
const podName = Utils.getPodName(workflow.metadata.name, node.name, node.templateName, node.id);
85+
8186
const attributes = [
8287
{title: 'NAME', value: <ClipboardText text={props.node.name} />},
8388
{title: 'TYPE', value: props.node.type},
@@ -130,7 +135,7 @@ const WorkflowNodeSummary = (props: Props) => {
130135
attributes.splice(
131136
2,
132137
0,
133-
{title: 'POD NAME', value: <ClipboardText text={props.node.id} />},
138+
{title: 'POD NAME', value: <ClipboardText text={podName} />},
134139
{
135140
title: 'HOST NODE NAME',
136141
value: <ClipboardText text={props.node.hostNodeName} />

0 commit comments

Comments
 (0)