Skip to content

Commit

Permalink
feat(provider/k8s): support artifacts in run job (#7309)
Browse files Browse the repository at this point in the history
adds support for artifacts in the v2 run job stage. very similar to
deploy manifest.
  • Loading branch information
ethanfrogers authored Aug 9, 2019
1 parent 74ea2e7 commit 0b1ce1e
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import * as React from 'react';
import Select from 'react-select';
import Select, { Option } from 'react-select';
import { map, capitalize } from 'lodash';

import {
ArtifactTypePatterns,
IStageConfigProps,
AccountService,
YamlEditor,
Expand All @@ -12,27 +14,43 @@ import {
IExpectedArtifact,
IArtifact,
PreRewriteStageArtifactSelector,
StageArtifactSelectorDelegate,
StageConfigField,
RadioButtonInput,
} from '@spinnaker/core';

import { ManifestBasicSettings } from 'kubernetes/v2/manifest/wizard/BasicSettings';
import { ManifestBindArtifactsSelectorDelegate } from '../deployManifest/ManifestBindArtifactsSelectorDelegate';
import { IManifestBindArtifact } from '../deployManifest/ManifestBindArtifactsSelector';

export interface IKubernetesRunJobStageConfigState {
credentials: IAccount[];
rawManifest?: string;
}

export class KubernetesV2RunJobStageConfig extends React.Component<IStageConfigProps> {
public readonly textSource = 'text';
public readonly artifactSource = 'artifact';
public state: IKubernetesRunJobStageConfigState = {
credentials: [],
};

private readonly excludedManifestArtifactTypes = [
ArtifactTypePatterns.DOCKER_IMAGE,
ArtifactTypePatterns.KUBERNETES,
ArtifactTypePatterns.FRONT50_PIPELINE_TEMPLATE,
ArtifactTypePatterns.MAVEN_FILE,
];

constructor(props: IStageConfigProps) {
super(props);
const { stage, application } = this.props;
if (!stage.application) {
stage.application = application.name;
}
if (!stage.source) {
stage.source = this.textSource;
}
}

public outputOptions = [
Expand Down Expand Up @@ -97,6 +115,24 @@ export class KubernetesV2RunJobStageConfig extends React.Component<IStageConfigP
});
};

private onManifestArtifactSelected = (expectedArtifactId: string): void => {
this.props.updateStageField({
manifestArtifactId: expectedArtifactId,
manifestArtifact: null,
});
};

private onManifestArtifactEdited = (artifact: IArtifact) => {
this.props.updateStageField({
manifestArtifactId: null,
manifestArtifact: artifact,
});
};

private onManifestArtifactAccountSelected = (accountName: string): void => {
this.props.updateStageField({ manifestArtifactAccount: accountName });
};

private updatePropertyFile = (event: any) => {
this.props.updateStageField({ propertyFile: event.target.value });
};
Expand Down Expand Up @@ -151,6 +187,27 @@ export class KubernetesV2RunJobStageConfig extends React.Component<IStageConfigP
);
}

private getSourceOptions = (): Array<Option<string>> => {
return map([this.textSource, this.artifactSource], option => ({
label: capitalize(option),
value: option,
}));
};

private getRequiredArtifacts = (): IManifestBindArtifact[] => {
const { requiredArtifactIds, requiredArtifacts } = this.props.stage;
return (requiredArtifactIds || [])
.map((id: string) => ({ expectedArtifactId: id }))
.concat(requiredArtifacts || []);
};

private onRequiredArtifactsChanged = (bindings: IManifestBindArtifact[]): void => {
this.props.updateStageField({
requiredArtifactIds: bindings.filter(b => b.expectedArtifactId).map(b => b.expectedArtifactId),
});
this.props.updateStageField({ requiredArtifacts: bindings.filter(b => b.artifact) });
};

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

Expand All @@ -171,7 +228,45 @@ export class KubernetesV2RunJobStageConfig extends React.Component<IStageConfigP
onAccountSelect={(selectedAccount: string) => this.accountChanged(selectedAccount)}
/>
<h4>Manifest Configuration</h4>
<YamlEditor value={this.state.rawManifest} onChange={this.handleRawManifestChange} />
<StageConfigField label="Manifest Source" helpKey="kubernetes.manifest.source">
<RadioButtonInput
inline={true}
options={this.getSourceOptions()}
onChange={(e: any) => this.props.updateStageField({ source: e.target.value })}
value={stage.source}
/>
</StageConfigField>
{stage.source === this.textSource && (
<YamlEditor value={this.state.rawManifest} onChange={this.handleRawManifestChange} />
)}
{stage.source === this.artifactSource && (
<>
<StageArtifactSelectorDelegate
artifact={stage.manifestArtifact}
excludedArtifactTypePatterns={this.excludedManifestArtifactTypes}
expectedArtifactId={stage.manifestArtifactId}
helpKey="kubernetes.manifest.expectedArtifact"
label="Manifest Artifact"
onArtifactEdited={this.onManifestArtifactEdited}
onExpectedArtifactSelected={(artifact: IExpectedArtifact) => this.onManifestArtifactSelected(artifact.id)}
pipeline={this.props.pipeline}
selectedArtifactAccount={stage.manifestArtifactAccount}
selectedArtifactId={stage.manifestArtifactId}
setArtifactAccount={this.onManifestArtifactAccountSelected}
setArtifactId={this.onManifestArtifactSelected}
stage={stage}
updatePipeline={this.props.updatePipeline}
/>
</>
)}
<StageConfigField label="Required Artifacts to Bind" helpKey="kubernetes.manifest.requiredArtifactsToBind">
<ManifestBindArtifactsSelectorDelegate
bindings={this.getRequiredArtifacts()}
onChangeBindings={this.onRequiredArtifactsChanged}
pipeline={this.props.pipeline}
stage={stage}
/>
</StageConfigField>
<h4>Output</h4>
<StageConfigField label="Capture Output From" helpKey="kubernetes.runJob.captureSource">
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
JobStageExecutionLogs,
DefaultPodNameProvider,
IJobOwnedPodStatus,
StageFailureMessage,
} from '@spinnaker/core';

export class RunJobExecutionDetails extends React.Component<IExecutionDetailsSectionProps> {
Expand All @@ -31,6 +32,7 @@ export class RunJobExecutionDetails extends React.Component<IExecutionDetailsSec

return (
<ExecutionDetailsSection name={name} current={current}>
<StageFailureMessage stage={stage} message={stage.failureMessage} />
<div className="row">
<div className="col-md-9">
<dl className="dl-narrow dl-horizontal">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module(KUBERNETES_V2_RUN_JOB_STAGE, [])
addAliasToConfig: true,
cloudProvider: 'kubernetes',
component: KubernetesV2RunJobStageConfig,
executionDetailsSections: [ExecutionDetailsTasks, RunJobExecutionDetails],
executionDetailsSections: [RunJobExecutionDetails, ExecutionDetailsTasks],
supportsCustomTimeout: true,
producesArtifacts: true,
validators: [
Expand Down

0 comments on commit 0b1ce1e

Please sign in to comment.