Skip to content

Commit

Permalink
feat(runjob): capture output ui (spinnaker#6978)
Browse files Browse the repository at this point in the history
UI for v2 run job capture output. there are 2 options - logs and
artifact. setting to `logs` will set the `propertyFile` option to
trigger the runJob stage to read from the container logs. setting to
artifact will trigger the `ConsumeArtifactTask` to fetch and inject the
defined artifact.
  • Loading branch information
ethanfrogers committed May 13, 2019
1 parent 7df12a1 commit 0194821
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/scripts/modules/kubernetes/src/help/kubernetes.help.ts
Expand Up @@ -225,6 +225,9 @@ const helpContents: { [key: string]: string } = {
<p><b>json</b>: <a href="https://tools.ietf.org/html/rfc6902" target="_blank">JSON Patch, RFC 6902</a></p>
<p><b>merge</b>: <a href="https://tools.ietf.org/html/rfc7386" target="_blank">JSON Merge Patch, RFC 7386</a></p>
`,
'kubernetes.runJob.captureSource':
'Source from which to capture Job output. Captured output will be available in the pipeline context for use in downstream stages.',
'kubernetes.runJob.captureSource.containerName': `Use logs from this container to capture output data.`,
};

Object.keys(helpContents).forEach(key => HelpContentsRegistry.register(key, helpContents[key]));
@@ -1,6 +1,19 @@
import * as React from 'react';
import Select from 'react-select';

import { IStageConfigProps, AccountService, YamlEditor, yamlDocumentsToString, IAccount } from '@spinnaker/core';
import {
IStageConfigProps,
AccountService,
YamlEditor,
yamlDocumentsToString,
IAccount,
StageArtifactSelector,
SETTINGS,
IExpectedArtifact,
IArtifact,
PreRewriteStageArtifactSelector,
StageConfigField,
} from '@spinnaker/core';

import { ManifestBasicSettings } from 'kubernetes/v2/manifest/wizard/BasicSettings';

Expand All @@ -14,6 +27,12 @@ export class KubernetesV2RunJobStageConfig extends React.Component<IStageConfigP
credentials: [],
};

public outputOptions = [
{ label: 'None', value: 'none' },
{ label: 'Logs', value: 'propertyFile' },
{ label: 'Artifact', value: 'artifact' },
];

public accountChanged = (account: string) => {
this.props.updateStageField({
credentails: account,
Expand Down Expand Up @@ -43,9 +62,94 @@ export class KubernetesV2RunJobStageConfig extends React.Component<IStageConfigP
this.initRawManifest();
}

private sourceChanged = (event: any) => {
this.props.updateStageField({ consumeArtifactSource: event.value });
};

private updateArtifactId(artifactId: string) {
this.props.updateStageField({ consumeArtifactId: artifactId });
}

private updateArtifactAccount(artifactAccount: string) {
this.props.updateStageField({ consumeArtifactAccount: artifactAccount });
}

private onArtifactSelected = (artifact: IExpectedArtifact) => {
this.props.updateStageField({ consumeArtifactId: artifact.id });
};

private onArtifactEdited = (artifact: IArtifact) => {
this.props.updateStageField({
consumeArtifact: artifact,
consumeArtifactId: artifact.id,
consumeArtifactAccount: artifact.artifactAccount,
});
};

private updatePropertyFile = (event: any) => {
this.props.updateStageField({ propertyFile: event.target.value });
};

private checkFeatureFlag(flag: string): boolean {
return !!SETTINGS.feature[flag];
}

public logSourceForm() {
const { stage } = this.props;
return (
<StageConfigField label="Container Name" helpKey="kubernetes.runJob.captureSource.containerName">
<input
className="form-control input-sm"
type="text"
value={stage.propertyFile}
onChange={this.updatePropertyFile}
/>
</StageConfigField>
);
}

public artifactRewriteForm() {
const { stage, pipeline } = this.props;
return (
<StageConfigField label="Artifact">
<StageArtifactSelector
pipeline={pipeline}
stage={stage}
artifact={stage.consumeArtifact}
excludedArtifactTypePatterns={[]}
expectedArtifactId={stage.consumeArtifactId}
onExpectedArtifactSelected={this.onArtifactSelected}
onArtifactEdited={this.onArtifactEdited}
/>
</StageConfigField>
);
}

public artifactForm() {
const { stage, pipeline } = this.props;
return (
<PreRewriteStageArtifactSelector
excludedArtifactTypes={[]}
stage={stage}
pipeline={pipeline}
selectedArtifactId={stage.consumeArtifactId}
selectedArtifactAccount={stage.consumeArtifactAccount}
setArtifactAccount={(artifactAccount: string) => this.updateArtifactAccount(artifactAccount)}
setArtifactId={(artifactId: string) => this.updateArtifactId(artifactId)}
/>
);
}

public render() {
const { application, stage } = this.props;

let outputSource = <div />;
if (stage.consumeArtifactSource === 'propertyFile') {
outputSource = this.logSourceForm();
} else if (stage.consumeArtifactSource === 'artifact') {
outputSource = this.checkFeatureFlag('artifactsRewrite') ? this.artifactRewriteForm() : this.artifactForm();
}

return (
<div className="container-fluid form-horizontal">
<h4>Basic Settings</h4>
Expand All @@ -57,6 +161,18 @@ export class KubernetesV2RunJobStageConfig extends React.Component<IStageConfigP
/>
<h4>Manifest Configuration</h4>
<YamlEditor value={this.state.rawManifest} onChange={this.handleRawManifestChange} />
<h4>Output</h4>
<StageConfigField label="Capture Output From" helpKey="kubernetes.runJob.captureSource">
<div>
<Select
clearable={false}
options={this.outputOptions}
value={stage.consumeArtifactSource}
onChange={this.sourceChanged}
/>
</div>
</StageConfigField>
{outputSource}
</div>
);
}
Expand Down

0 comments on commit 0194821

Please sign in to comment.