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

Create buildConfig or pipeline based on user input #6874

Merged
merged 6 commits into from
Nov 3, 2020
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 @@ -7,6 +7,7 @@ import {
BanIcon,
ExclamationTriangleIcon,
UnknownIcon,
OutlinedHourglassIcon,
} from '@patternfly/react-icons';
import { DASH } from '../../constants';
import { YellowExclamationTriangleIcon } from './icons';
Expand Down Expand Up @@ -93,6 +94,9 @@ export const Status: React.FC<StatusProps> = ({
case 'Unknown':
return <StatusIconAndText {...statusProps} icon={<UnknownIcon />} />;

case 'PipelineNotStarted':
return <StatusIconAndText {...statusProps} icon={<OutlinedHourglassIcon />} />;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created a Story to update this icon now they have it figured out. https://issues.redhat.com/browse/ODC-5047


default:
return <>{status || DASH}</>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { referenceForModel } from '@console/internal/module/k8s';
import NamespacedPage, { NamespacedPageVariants } from '../NamespacedPage';
import EditApplication from './EditApplication';
import { EditApplicationProps } from './edit-application-types';
import { PipelineModel } from '../../models';

const INSTANCE_LABEL = 'app.kubernetes.io/instance';
const EditApplicationComponentLoader: React.FunctionComponent<EditApplicationProps> = (
Expand Down Expand Up @@ -39,6 +40,13 @@ const EditApplicationPage: React.FunctionComponent<ImportPageProps> = ({ match,
namespace,
optional: true,
},
{
kind: referenceForModel(PipelineModel),
prop: PipelineModel.id,
name: appName,
namespace,
optional: true,
},
{
kind: 'Route',
prop: 'route',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,130 @@ export const appResources: AppResources = {
},
},
},
pipeline: {
loaded: true,
loadError: '',
data: {
apiVersion: 'tekton.dev/v1beta1',
kind: 'Pipeline',
metadata: {
selfLink: '/apis/tekton.dev/v1beta1/namespaces/div/pipelines/nationalparks-py',
resourceVersion: '406718',
name: 'nationalparks-py',
uid: '131662ce-62a8-4e4c-8520-a85bc35a31b3',
creationTimestamp: '2020-10-13T12:56:49Z',
generation: 1,
namespace: 'div',
labels: {
'app.kubernetes.io/instance': 'nationalparks-py',
'pipeline.openshift.io/runtime': 'python',
'pipeline.openshift.io/type': 'kubernetes',
},
},
spec: {
params: [
{
default: 'nationalparks-py',
name: 'APP_NAME',
type: 'string',
},
{
default: 'https://github.com/divyanshiGupta/nationalparks-py',
name: 'GIT_REPO',
type: 'string',
},
{
default: 'master',
name: 'GIT_REVISION',
type: 'string',
},
{
default: 'image-registry.openshift-image-registry.svc:5000/div/nationalparks-py',
name: 'IMAGE_NAME',
type: 'string',
},
],
tasks: [
{
name: 'fetch-repository',
params: [
{
name: 'url',
value: '$(params.GIT_REPO)',
},
{
name: 'revision',
value: '$(params.GIT_REVISION)',
},
{
name: 'subdirectory',
value: '',
},
{
name: 'deleteExisting',
value: 'true',
},
],
taskRef: {
kind: 'ClusterTask',
name: 'git-clone',
},
workspaces: [
{
name: 'output',
},
],
},
{
name: 'build',
params: [
{
name: 'IMAGE',
value: '$(params.IMAGE_NAME)',
},
{
name: 'TLSVERIFY',
value: 'false',
},
],
runAfter: ['fetch-repository'],
taskRef: {
kind: 'ClusterTask',
name: 's2i-python-3',
},
workspaces: [
{
name: 'source',
},
],
},
{
name: 'deploy',
params: [
{
name: 'SCRIPT',
value: 'kubectl $@',
},
{
name: 'ARGS',
value: ['rollout', 'status', 'deploy/$(params.APP_NAME)'],
},
],
runAfter: ['build'],
taskRef: {
kind: 'ClusterTask',
name: 'openshift-client',
},
},
],
workspaces: [
{
name: 'workspace',
},
],
},
},
},
imageStream: {
loaded: true,
loadError: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
getInitialValues,
getExternalImagelValues,
} from '../edit-application-utils';
import { Resources } from '../../import/import-types';
import { GitImportFormData, Resources } from '../../import/import-types';
import {
knativeService,
knAppResources,
Expand All @@ -29,7 +29,31 @@ describe('Edit Application Utils', () => {
});

it('getInitialValues should return values based on the resources and the create flow used to create the application', () => {
const { route, editAppResource, buildConfig, imageStream } = appResources;
const { route, editAppResource, buildConfig, pipeline, imageStream } = appResources;
const gitImportValues: GitImportFormData = {
...gitImportInitialValues,
git: {
...gitImportInitialValues.git,
ref: 'master',
},
pipeline: {
enabled: true,
},
build: {
...gitImportInitialValues.build,
triggers: { config: false, image: false, webhook: false },
},
image: {
...gitImportInitialValues.image,
tag: '',
},
};
expect(
getInitialValues({ pipeline, editAppResource, route }, 'nationalparks-py', 'div'),
).toEqual(gitImportValues);
expect(
getInitialValues({ buildConfig, editAppResource, route }, 'nationalparks-py', 'div'),
).toEqual(gitImportInitialValues);
expect(
getInitialValues({ buildConfig, editAppResource, route }, 'nationalparks-py', 'div'),
).toEqual(gitImportInitialValues);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { K8sResourceKind } from '@console/internal/module/k8s';
import { FirehoseResult } from '@console/internal/components/utils';
import { Pipeline } from '../../utils/pipeline-augment';

export interface AppResources {
service?: FirehoseResult<K8sResourceKind>;
route?: FirehoseResult<K8sResourceKind>;
buildConfig?: FirehoseResult<K8sResourceKind>;
pipeline?: FirehoseResult<Pipeline>;
imageStream?: FirehoseResult<K8sResourceKind[]>;
editAppResource?: FirehoseResult<K8sResourceKind>;
imageStreams?: FirehoseResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { AppResources } from './edit-application-types';
import { RegistryType } from '../../utils/imagestream-utils';
import { getHealthChecksData } from '../health-checks/create-health-checks-probe-utils';
import { detectGitType } from '../import/import-validation-utils';
import { Pipeline } from '../../utils/pipeline-augment';

export enum CreateApplicationFlow {
Git = 'Import from Git',
Expand Down Expand Up @@ -59,7 +60,7 @@ const checkIfTriggerExists = (
});
};

export const getGitData = (buildConfig: K8sResourceKind) => {
export const getGitDataFromBuildConfig = (buildConfig: K8sResourceKind) => {
const url = buildConfig?.spec?.source?.git?.uri ?? '';
const gitData = {
url,
Expand All @@ -73,6 +74,22 @@ export const getGitData = (buildConfig: K8sResourceKind) => {
return gitData;
};

const getGitDataFromPipeline = (pipeline: Pipeline) => {
const params = pipeline?.spec?.params;
const url = (params?.find((param) => param?.name === 'GIT_REPO')?.default ?? '') as string;
const ref = params?.find((param) => param?.name === 'GIT_REVISION')?.default ?? '';
const dir = params?.find((param) => param?.name === 'PATH_CONTEXT')?.default ?? '/';
return {
url,
ref,
dir,
type: detectGitType(url),
showGitType: false,
secret: '',
isUrlValidating: false,
};
};

export const getRouteData = (route: K8sResourceKind, resource: K8sResourceKind) => {
let routeData = {
disable: !_.isEmpty(route),
Expand Down Expand Up @@ -110,7 +127,7 @@ export const getRouteData = (route: K8sResourceKind, resource: K8sResourceKind)
return routeData;
};

export const getBuildData = (buildConfig: K8sResourceKind, gitType: string) => {
export const getBuildData = (buildConfig: K8sResourceKind, pipeline: Pipeline, gitType: string) => {
const buildStrategyType = _.get(buildConfig, 'spec.strategy.type', '');
let buildStrategyData;
switch (buildStrategyType) {
Expand All @@ -131,7 +148,12 @@ export const getBuildData = (buildConfig: K8sResourceKind, gitType: string) => {
image: checkIfTriggerExists(triggers, 'ImageChange'),
config: checkIfTriggerExists(triggers, 'ConfigChange'),
},
strategy: buildStrategyType,
strategy:
buildStrategyType ||
(pipeline?.metadata?.labels?.['pipeline.openshift.io/strategy'] ===
_.toLower(BuildStrategyType.Docker)
? BuildStrategyType.Docker
: BuildStrategyType.Source),
};
return buildData;
};
Expand Down Expand Up @@ -252,6 +274,7 @@ export const getUserLabels = (resource: K8sResourceKind) => {
export const getCommonInitialValues = (
editAppResource: K8sResourceKind,
route: K8sResourceKind,
pipelineData: Pipeline,
name: string,
namespace: string,
) => {
Expand All @@ -270,7 +293,7 @@ export const getCommonInitialValues = (
resources: getResourcesType(editAppResource),
serverless: getServerlessData(editAppResource),
pipeline: {
enabled: false,
enabled: !_.isEmpty(pipelineData),
},
deployment: getDeploymentData(editAppResource),
labels: getUserLabels(editAppResource),
Expand All @@ -290,36 +313,37 @@ export const getIconInitialValues = (editAppResource: K8sResourceKind) => {

export const getGitAndDockerfileInitialValues = (
buildConfig: K8sResourceKind,
pipeline: Pipeline,
route: K8sResourceKind,
) => {
if (_.isEmpty(buildConfig)) {
if (_.isEmpty(buildConfig) && _.isEmpty(pipeline)) {
return {};
}
const currentImage = _.split(
_.get(buildConfig, 'spec.strategy.sourceStrategy.from.name', ''),
':',
);
const git = getGitData(buildConfig);

const currentImage = _.split(buildConfig?.spec?.strategy?.sourceStrategy?.from?.name ?? '', ':');
const git = !_.isEmpty(buildConfig)
? getGitDataFromBuildConfig(buildConfig)
: getGitDataFromPipeline(pipeline);
const initialValues = {
git,
docker: {
dockerfilePath: _.get(
buildConfig,
'spec.strategy.dockerStrategy.dockerfilePath',
dockerfilePath:
buildConfig?.spec?.strategy?.dockerStrategy?.dockerfilePath ||
pipeline?.spec?.params?.find((param) => param?.name === 'DOCKERFILE')?.default ||
'Dockerfile',
),
containerPort: parseInt(_.split(_.get(route, 'spec.port.targetPort'), '-')[0], 10),
},
image: {
selected: currentImage[0] || '',
selected:
currentImage[0] || (pipeline?.metadata?.labels?.['pipeline.openshift.io/runtime'] ?? ''),
recommended: '',
tag: currentImage[1] || '',
tagObj: {},
ports: [],
isRecommending: false,
couldNotRecommend: false,
},
build: getBuildData(buildConfig, git.type),
build: getBuildData(buildConfig, pipeline, git.type),
};
return initialValues;
};
Expand Down Expand Up @@ -423,9 +447,20 @@ export const getInitialValues = (
const editAppResourceData = appResources.editAppResource?.data;
const routeData = appResources.route?.data;
const buildConfigData = appResources.buildConfig?.data;
const pipelineData = appResources.pipeline?.data;

const commonValues = getCommonInitialValues(editAppResourceData, routeData, appName, namespace);
const gitDockerValues = getGitAndDockerfileInitialValues(buildConfigData, routeData);
const commonValues = getCommonInitialValues(
editAppResourceData,
routeData,
pipelineData,
appName,
namespace,
);
const gitDockerValues = getGitAndDockerfileInitialValues(
buildConfigData,
pipelineData,
routeData,
);

let iconValues = {};
let externalImageValues = {};
Expand Down