Skip to content

Commit

Permalink
Merge pull request #17 from reginapizza/jd-odc-add-devfile
Browse files Browse the repository at this point in the history
Added backend to frontend communication
  • Loading branch information
reginapizza authored Sep 29, 2020
2 parents b5a783c + 428c35f commit b986801
Show file tree
Hide file tree
Showing 47 changed files with 41,005 additions and 214 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
} from './import-types';
import { createPipelineForImportFlow } from './pipeline/pipeline-template-utils';
import { Perspective } from '@console/plugin-sdk';
import { makePortName } from './imagestream-utils';

export const generateSecret = () => {
// http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
Expand All @@ -58,7 +59,7 @@ export const createProject = (projectData: ProjectData): Promise<K8sResourceKind
return k8sCreate(ProjectRequestModel, project);
};

export const createOrUpdateDevfileResources = (
export const createOrUpdateDevfileResources = async (
formData: GitImportFormData,
imageStream: K8sResourceKind,
dryRun: boolean,
Expand Down Expand Up @@ -121,38 +122,38 @@ export const createOrUpdateDevfileResources = (
const defaultAnnotations = { ...getGitAnnotations(repository, ref), ...getCommonAnnotations(), isFromDevfile };


const isDeployImageFormData = (
formData: DeployImageFormData | GitImportFormData,
): formData is DeployImageFormData => {
return 'isi' in (formData as DeployImageFormData);
};

const makePortName = (port: ContainerPort): string =>
`${port.containerPort}-${port.protocol}`.toLowerCase();

let ports = imagePorts;
if (isDeployImageFormData(formData)) {
const {
isi: { ports: isiPorts },
} = formData;
ports = isiPorts;
}

let targetPort;
if (_.get(formData, 'build.strategy') === 'Docker') {
const port = _.get(formData, 'docker.containerPort');
targetPort = makePortName({
containerPort: _.toInteger(port),
protocol: 'TCP',
});
} else if (_.isEmpty(ports)) {
targetPort = makePortName({
containerPort: _.toInteger(unknownTargetPort) || defaultUnknownPort,
protocol: 'TCP',
});
} else {
targetPort = routeTargetPort || makePortName(_.head(ports));
}
// const isDeployImageFormData = (
// formData: DeployImageFormData | GitImportFormData,
// ): formData is DeployImageFormData => {
// return 'isi' in (formData as DeployImageFormData);
// };

// const makePortName = (port: ContainerPort): string =>
// `${port.containerPort}-${port.protocol}`.toLowerCase();

// let ports = imagePorts;
// if (isDeployImageFormData(formData)) {
// const {
// isi: { ports: isiPorts },
// } = formData;
// ports = isiPorts;
// }

// let targetPort;
// if (_.get(formData, 'build.strategy') === 'Docker') {
// const port = _.get(formData, 'docker.containerPort');
// targetPort = makePortName({
// containerPort: _.toInteger(port),
// protocol: 'TCP',
// });
// } else if (_.isEmpty(ports)) {
// targetPort = makePortName({
// containerPort: _.toInteger(unknownTargetPort) || defaultUnknownPort,
// protocol: 'TCP',
// });
// } else {
// targetPort = routeTargetPort || makePortName(_.head(ports));
// }

const webhookTriggerData = {
type: GitReadableTypes[gitType],
Expand All @@ -178,7 +179,7 @@ export const createOrUpdateDevfileResources = (
let webhookSecret = generateSecret();

const devfileData = {
name: name,
name: name,
namespace: namespace,
project: { name: namespace },
application: { name: applicationName },
Expand Down Expand Up @@ -214,8 +215,8 @@ export const createOrUpdateDevfileResources = (
podLabels: podLabels,
};


let devfileResourceObjects = devfileCreate(null, devfileData, dryRun ? dryRunOpt : {});
let devfileResourceObjects = await devfileCreate(null, devfileData, dryRun ? dryRunOpt : {});


requests.push(
createOrUpdateDevfileImageStream(
Expand Down
Loading

0 comments on commit b986801

Please sign in to comment.