Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-4.4] Bug 1807133: Add pipeline for resource and runtime #4499

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,10 @@ export const createOrUpdateResources = async (

const defaultAnnotations = getAppAnnotations(repository, ref);

if (pipeline.enabled && pipeline.template && !dryRun) {
requests.push(createPipelineForImportFlow(formData));
}

if (formData.resources === Resources.KnativeService) {
// knative service doesn't have dry run capability so returning the promises.
if (dryRun) {
Expand Down Expand Up @@ -499,10 +503,6 @@ export const createOrUpdateResources = async (
}
}

if (pipeline.enabled && pipeline.template && !dryRun) {
requests.push(createPipelineForImportFlow(formData));
}

if (webhookTrigger && verb === 'create') {
requests.push(createWebhookSecret(formData, gitType, dryRun));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ export enum ImportTypes {

export enum Resources {
OpenShift = 'openshift',
Kubernetes = 'k8s',
KnativeService = 'knativeservice',
Kubernetes = 'kubernetes',
KnativeService = 'knative',
}

export interface ImportData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@ import { CheckboxField } from '@console/shared';
import { CLUSTER_PIPELINE_NS } from '../../../const';
import { PipelineModel } from '../../../models';
import PipelineVisualization from '../../pipelines/detail-page-tabs/pipeline-details/PipelineVisualization';
import { Pipeline } from '../../../utils/pipeline-augment';

const MISSING_DOCKERFILE_LABEL_TEXT =
'The pipeline template for Dockerfiles is not available at this time.';
const MISSING_RUNTIME_LABEL_TEXT = 'There are no pipeline templates available for this runtime.';

const labelType = 'pipeline.openshift.io/type';
const labelRuntime = 'pipeline.openshift.io/runtime';
const labelDocker = 'pipeline.openshift.io/strategy';

const PipelineTemplate: React.FC = () => {
const [noTemplateForRuntime, setNoTemplateForRuntime] = React.useState(false);
const [isExpanded, setIsExpanded] = React.useState(false);
const pipelineStorageRef = React.useRef<{ [image: string]: Pipeline[] }>({});

const {
values: { pipeline, image, build },
values: { pipeline, image, build, resources },
setFieldValue,
} = useFormikContext<FormikValues>();

Expand All @@ -26,20 +32,33 @@ const PipelineTemplate: React.FC = () => {
React.useEffect(() => {
let ignore = false;

const builderPipelineLabel = { 'pipeline.openshift.io/runtime': image.selected };
const dockerPipelineLabel = { 'pipeline.openshift.io/strategy': 'docker' };
const builderPipelineLabel = { [labelRuntime]: image.selected };
const dockerPipelineLabel = { [labelDocker]: 'docker' };

const labelSelector = isDockerStrategy ? dockerPipelineLabel : builderPipelineLabel;

const fetchPipelineTemplate = async () => {
const templates = await k8sList(PipelineModel, {
ns: CLUSTER_PIPELINE_NS,
labelSelector,
});
const pipelineTemplate = templates && templates[0];
let fetchedPipelines: Pipeline[] = null;
if (!pipelineStorageRef.current[image.selected]) {
fetchedPipelines = (await k8sList(PipelineModel, {
ns: CLUSTER_PIPELINE_NS,
labelSelector,
})) as Pipeline[];
}

if (ignore) return;

if (fetchedPipelines) {
pipelineStorageRef.current[image.selected] = fetchedPipelines;
}

const imagePipelines: Pipeline[] = pipelineStorageRef.current[image.selected] || [];
const resourceSpecificPipeline = imagePipelines.find(
(pl) => pl.metadata?.labels?.[labelType] === resources,
);
const pipelineTemplate =
resourceSpecificPipeline || imagePipelines.find((pl) => !pl.metadata?.labels?.[labelType]);

if (pipelineTemplate) {
setFieldValue('pipeline.template', pipelineTemplate);
setNoTemplateForRuntime(false);
Expand All @@ -55,7 +74,7 @@ const PipelineTemplate: React.FC = () => {
return () => {
ignore = true;
};
}, [image.selected, isDockerStrategy, setFieldValue]);
}, [resources, image.selected, isDockerStrategy, setFieldValue]);

if (noTemplateForRuntime) {
return (
Expand Down