Skip to content

Commit

Permalink
Merge pull request #16 from reginapizza/EditApplication
Browse files Browse the repository at this point in the history
WIP- successful push to registry but still can't edit
  • Loading branch information
reginapizza authored Sep 25, 2020
2 parents 0999bc2 + 72db3d1 commit b5a783c
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const EditApplicationForm: React.FC<FormikProps<FormikValues> & EditApplicationF
}
<Form onSubmit={handleSubmit}>
{createFlowType !== CreateApplicationFlow.Container && (
<GitSection builderImages={builderImages} />
<GitSection buildStrategy={values.build.strategy} builderImages={builderImages} />
)}
{createFlowType === CreateApplicationFlow.Git && (
<BuilderSection image={values.image} builderImages={builderImages} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ export const getBuildData = (buildConfig: K8sResourceKind, gitType: string) => {
buildStrategyData = { env: [] };
}
if (buildConfig.metadata.annotations['isFromDevfile'] === "true") {
buildStrategyType = BuildStrategyType.Devfile
buildStrategyType = BuildStrategyType.Devfile;
// buildStrategyData = _.get(buildConfig, 'spec.strategy.dockerStrategy');
}
const triggers = _.get(buildConfig, 'spec.triggers');
const buildData = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { getProbesData } from '../health-checks/create-health-checks-probe-utils
import { AppResources } from '../edit-application/edit-application-types';
import {
GitImportFormData,
DeployImageFormData,
ProjectData,
GitTypes,
GitReadableTypes,
Expand Down Expand Up @@ -68,12 +69,25 @@ export const createOrUpdateDevfileResources = (
originalBuildConfig?: K8sResourceKind,
originalDeployment?: K8sResourceKind,
originalDeploymentConfig?: K8sResourceKind,
imageStreamData?: K8sResourceKind,
// originalRoute?: K8sResourceKind,
): Promise<K8sResourceKind[]> => {
const {
name,
project: { name: namespace },
application: { name: applicationName },
route: { create: canCreateRoute, disable },
// route: { create: canCreateRoute, disable },
route: {
disable,
create: canCreateRoute,
targetPort: routeTargetPort,
unknownTargetPort,
defaultUnknownPort,
path,
hostname,
secure,
tls,
},
build: {
env: buildEnv,
strategy: buildStrategy,
Expand All @@ -86,13 +100,14 @@ export const createOrUpdateDevfileResources = (
},
git: { url: repository, type: gitType, ref = 'master', dir: contextDir, secret: secretName },
devfile: { devfileContent, devfilePath },
docker: { dockerfilePath },
image: { ports: imagePorts, tag: selectedTag },
labels: userLabels,
limits: { cpu, memory },
pipeline,
resources,
healthChecks,
route: { hostname, secure, path, tls, targetPort: routeTargetPort },
// route: { hostname, secure, path, tls, targetPort: routeTargetPort },
} = formData;

const requests: Promise<K8sResourceKind>[] = [];
Expand All @@ -105,6 +120,40 @@ export const createOrUpdateDevfileResources = (
const defaultLabels = getAppLabels({ name, applicationName, imageStreamName, selectedTag });
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 webhookTriggerData = {
type: GitReadableTypes[gitType],
[gitType]: {
Expand Down Expand Up @@ -146,6 +195,7 @@ export const createOrUpdateDevfileResources = (
},
git: { url: repository, type: gitType, ref, dir: contextDir, secret: secretName },
devfile: { devfileContent, devfilePath },
docker: { dockerfilePath },
image: { ports: imagePorts, tag: selectedTag },
userLabels: userLabels,
limits: { cpu, memory },
Expand Down
9 changes: 5 additions & 4 deletions frontend/public/module/k8s/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { K8sKind, K8sResourceKind } from './types';
import { selectorToString } from './selector';
import { WSFactory } from '../ws-factory';


/** @type {(model: K8sKind) => string} */
const getK8sAPIPath = ({ apiGroup = 'core', apiVersion }) => {
const isLegacy = apiGroup === 'core' && apiVersion === 'v1';
Expand Down Expand Up @@ -87,7 +88,7 @@ export const devfileCreate = (kind, data, opts = {}) => {
let isMock = true;
data.defaultAnnotations['isFromDevfile'] = "true"
let buildStrategyData = {
dockerStrategy: { env:data.build.buildEnv, dockerfileLocation: "mock-dockerfile-location" }
dockerStrategy: { env:data.build.buildEnv, dockerfilePath: "Dockerfile" }
};

let devfileResources;
Expand Down Expand Up @@ -141,9 +142,9 @@ export const devfileCreate = (kind, data, opts = {}) => {
secretReference: { name: `${data.name}-generic-webhook-secret` },
},
},
// ...(data.build.triggers.webhook && data.git.type !== GitTypes.unsure ? [data.webhookTriggerData] : []),
// ...(data.build.triggers.image ? [{ type: 'ImageChange', imageChange: {} }] : []),
// ...(data.build.triggers.config ? [{ type: 'ConfigChange' }] : []),
...(data.build.triggers.webhook && data.git.type !== 'other' ? [data.webhookTriggerData] : []),
...(data.build.triggers.image ? [{ type: 'ImageChange', imageChange: {} }] : []),
...(data.build.triggers.config ? [{ type: 'ConfigChange' }] : []),
],
},
},
Expand Down

0 comments on commit b5a783c

Please sign in to comment.