Skip to content

Commit

Permalink
Use pipelineTask name for PipelineRun URL addressability
Browse files Browse the repository at this point in the history
Instead of using the TaskRun uid + pod name in the URL to address
a specific TaskRun retry, use the more user-friendly pipeline task
name and a separate retry parameter.

This produces a more user-friendly URL, is more easily constructed
by pipeline authors, and doesn't rely as much on kubernetes-isms
(i.e. pod name).

This change is based on feedback from preview users.
  • Loading branch information
AlanGreene authored and tekton-robot committed Jul 22, 2020
1 parent bb1ffde commit 96663f0
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ export /* istanbul ignore next */ class PipelineRunContainer extends Component {
const logContainer = selectedStepId && (
<Log
downloadButton={
LogDownloadButton && (
LogDownloadButton &&
stepStatus && (
<LogDownloadButton
stepName={stepName}
stepStatus={stepStatus}
Expand Down
97 changes: 85 additions & 12 deletions src/containers/PipelineRun/PipelineRun.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ import { rerunPipelineRun } from '../../api';

import { fetchLogs, followLogs, getViewChangeHandler } from '../../utils';

const PIPELINE_TASK = 'pipelineTask';
const RETRY = 'retry';
const STEP = 'step';
const VIEW = 'view';

export /* istanbul ignore next */ class PipelineRunContainer extends Component {
constructor(props) {
super(props);
Expand Down Expand Up @@ -88,21 +93,86 @@ export /* istanbul ignore next */ class PipelineRunContainer extends Component {
this.setState({ showRerunNotification: value });
}

getSelectedTaskId(pipelineTaskName, retry) {
const { taskRuns } = this.props;
const taskRun = taskRuns.find(
({ metadata }) =>
metadata.labels &&
metadata.labels['tekton.dev/pipelineTask'] === pipelineTaskName
);

if (!taskRun) {
return null;
}

const retryNumber = parseInt(retry, 10);
if (
!Number.isNaN(retryNumber) &&
taskRun.status &&
taskRun.status.retriesStatus
) {
const retryStatus = taskRun.status.retriesStatus[retryNumber];
return retryStatus && taskRun.metadata.uid + retryStatus.podName;
}

return taskRun.metadata.uid + taskRun.status.podName;
}

getSelectedTaskRun(selectedTaskId) {
const { taskRuns } = this.props;
const lookup = taskRuns.reduce((acc, taskRun) => {
const { labels, uid } = taskRun.metadata;
const pipelineTaskName = labels && labels['tekton.dev/pipelineTask'];
const { podName, retriesStatus } = taskRun.status;
acc[uid + podName] = {
pipelineTaskName,
uid
};
if (retriesStatus) {
retriesStatus.forEach((retryStatus, index) => {
acc[uid + retryStatus.podName] = {
pipelineTaskName,
retry: index,
uid
};
});
}
return acc;
}, {});
return lookup[selectedTaskId];
}

handleTaskSelected = (selectedTaskId, selectedStepId) => {
const { history, location, match } = this.props;
const {
history,
location,
match,
pipelineTaskName: currentPipelineTaskName,
retry: currentRetry
} = this.props;
const { pipelineTaskName, retry } = this.getSelectedTaskRun(selectedTaskId);
const queryParams = new URLSearchParams(location.search);

queryParams.set('taskRun', selectedTaskId);
queryParams.set(PIPELINE_TASK, pipelineTaskName);
if (selectedStepId) {
queryParams.set('step', selectedStepId);
queryParams.set(STEP, selectedStepId);
} else {
queryParams.delete('step');
queryParams.delete(STEP);
}

if (Number.isInteger(retry)) {
queryParams.set(RETRY, retry);
} else {
queryParams.delete(RETRY);
}

const currentStepId = this.props.selectedStepId;
const currentTaskId = this.props.selectedTaskId;
const currentTaskId = this.getSelectedTaskId(
currentPipelineTaskName,
currentRetry
);
if (selectedStepId !== currentStepId || selectedTaskId !== currentTaskId) {
queryParams.delete('view');
queryParams.delete(VIEW);
}

const browserURL = match.url.concat(`?${queryParams.toString()}`);
Expand Down Expand Up @@ -132,8 +202,9 @@ export /* istanbul ignore next */ class PipelineRunContainer extends Component {
intl,
match,
pipelineRun,
pipelineTaskName,
retry,
selectedStepId,
selectedTaskId,
tasks,
taskRuns,
view
Expand Down Expand Up @@ -162,6 +233,7 @@ export /* istanbul ignore next */ class PipelineRunContainer extends Component {

const { loading, showRerunNotification } = this.state;
const { pipelineRunName } = match.params;
const selectedTaskId = this.getSelectedTaskId(pipelineTaskName, retry);

const rerun = !this.props.isReadOnly && (
<Rerun
Expand Down Expand Up @@ -237,9 +309,10 @@ function mapStateToProps(state, ownProps) {
const { namespace } = match.params;

const queryParams = new URLSearchParams(location.search);
const selectedTaskId = queryParams.get('taskRun');
const selectedStepId = queryParams.get('step');
const view = queryParams.get('view');
const pipelineTaskName = queryParams.get(PIPELINE_TASK);
const retry = queryParams.get(RETRY);
const selectedStepId = queryParams.get(STEP);
const view = queryParams.get(VIEW);

return {
clusterTasks: getClusterTasks(state),
Expand All @@ -253,11 +326,11 @@ function mapStateToProps(state, ownProps) {
name: ownProps.match.params.pipelineRunName,
namespace
}),
pipelineTaskName,
retry,
selectedStepId,
selectedTaskId,
isLogStreamingEnabled: isLogStreamingEnabled(state),
tasks: getTasks(state, { namespace }),

taskRuns: getTaskRunsByPipelineRunName(
state,
ownProps.match.params.pipelineRunName,
Expand Down

0 comments on commit 96663f0

Please sign in to comment.