Skip to content

Commit

Permalink
feat(runJob/kubernetes): render external link (spinnaker#6930)
Browse files Browse the repository at this point in the history
if `context.execution.logs` is present (pulled from manifest annotation
`jobs.spinnaker.io/logs`), render the content as a link, templated with
manifest data.
  • Loading branch information
ethanfrogers authored May 7, 2019
1 parent 1c61cb2 commit d122749
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import { IStageManifest, ManifestService } from '../ManifestService';
import { JobManifestPodLogs } from './JobManifestPodLogs';
import { IManifest } from 'core/domain/IManifest';

import { get } from 'lodash';
import { get, template, isEmpty } from 'lodash';
import { Application } from 'core/application';

interface IJobStageExecutionLogsProps {
manifest: IStageManifest;
deployedName: string;
account: string;
application: Application;
externalLink: string;
}

interface IJobStageExecutionLogsState {
Expand All @@ -30,7 +31,7 @@ export class JobStageExecutionLogs extends React.Component<IJobStageExecutionLog
this.componentDidUpdate(this.props, this.state);
}

public componentWillMount() {
public componentWillUnmount() {
this.unsubscribe();
}

Expand Down Expand Up @@ -84,13 +85,34 @@ export class JobStageExecutionLogs extends React.Component<IJobStageExecutionLog
};
}

private renderExternalLink(link: string, manifest: IManifest): string {
if (!link.includes('{{')) {
return link;
}
// use {{ }} syntax to align with the annotation driven UI which this
// derives from
return template(link, { interpolate: /{{([\s\S]+?)}}/g })({ ...manifest });
}

public render() {
const { manifest } = this.state.subscription;
const { externalLink } = this.props;

// prefer links to external logging platforms
if (!isEmpty(manifest) && externalLink) {
return (
<a target="_blank" href={this.renderExternalLink(externalLink, manifest)}>
Console Output (External)
</a>
);
}

let event: any = null;
if (manifest && manifest.events) {
event = manifest.events.find((e: any) => e.message.startsWith('Created pod'));
}
if (!manifest || !event) {

if (isEmpty(manifest) && isEmpty(event)) {
return <div>No Console Output</div>;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ export class PreconfiguredJobExecutionDetails extends React.Component<IExecution
const namespace = get(manifest, ['metadata', 'namespace']);
const deployedJobs = get(this.props.stage, ['context', 'deploy.jobs']);
const deployedName = get(deployedJobs, namespace, [])[0] || '';
const externalLink = get<string>(this.props.stage, ['context', 'execution', 'logs']);
return (
<div className="well">
<JobStageExecutionLogs
manifest={manifest}
deployedName={deployedName}
account={this.props.stage.context.account}
application={this.props.application}
externalLink={externalLink}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class RunJobExecutionDetails extends React.Component<IExecutionDetailsSec

const { manifest } = context;
const deployedName = this.extractDeployedJobName(manifest, get(context, ['deploy.jobs']));
const externalLink = get<string>(stage, ['context', 'execution', 'logs']);

return (
<ExecutionDetailsSection name={name} current={current}>
Expand All @@ -51,6 +52,7 @@ export class RunJobExecutionDetails extends React.Component<IExecutionDetailsSec
deployedName={deployedName}
account={this.props.stage.context.account}
application={this.props.application}
externalLink={externalLink}
/>
</dd>
</dl>
Expand Down

0 comments on commit d122749

Please sign in to comment.