Skip to content

Commit

Permalink
fixes issue with route creation in case of no ports exposed
Browse files Browse the repository at this point in the history
  • Loading branch information
invincibleJai committed Sep 2, 2020
1 parent ceeaacf commit d48058a
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ export const gitImportInitialValues: GitImportFormData = {
disable: true,
create: true,
targetPort: '8080-tcp',
unknownTargetPort: '',
unknownTargetPort: '8080',
defaultUnknownPort: 8080,
path: '',
hostname: 'nationalparks-py-div.apps.rorai-cluster34.devcluster.openshift.com',
Expand Down Expand Up @@ -450,7 +450,7 @@ export const externalImageValues: DeployImageFormData = {
disable: true,
create: true,
targetPort: '8080-tcp',
unknownTargetPort: '',
unknownTargetPort: '8080',
defaultUnknownPort: 8080,
path: '',
hostname: 'nationalparks-py-div.apps.rorai-cluster34.devcluster.openshift.com',
Expand Down Expand Up @@ -527,7 +527,7 @@ export const internalImageValues: DeployImageFormData = {
disable: true,
create: true,
targetPort: '8080-tcp',
unknownTargetPort: '',
unknownTargetPort: '8080',
defaultUnknownPort: 8080,
path: '',
hostname: 'nationalparks-py-div.apps.rorai-cluster34.devcluster.openshift.com',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const getRouteData = (route: K8sResourceKind, resource: K8sResourceKind)
disable: !_.isEmpty(route),
create: true,
targetPort: _.get(route, 'spec.port.targetPort', ''),
unknownTargetPort: '',
unknownTargetPort: _.toString(route?.spec?.port?.targetPort?.split('-')?.[0]) || '',
defaultUnknownPort: 8080,
path: _.get(route, 'spec.path', ''),
hostname: _.get(route, 'spec.host', ''),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const ImportForm: React.FC<ImportFormProps & StateProps> = ({
disable: false,
create: true,
targetPort: '',
defaultUnknownPort: 8080,
path: '',
hostname: '',
secure: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const mockFormData: GitImportFormData = {
route: {
create: false,
targetPort: '',
defaultUnknownPort: 8080,
path: '',
hostname: '',
secure: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ export const createOrUpdateResources = async (
);
}

if (!_.isEmpty(ports) || buildStrategy === 'Docker') {
if (!_.isEmpty(ports) || buildStrategy === 'Docker' || buildStrategy === 'Source') {
const originalService = _.get(appResources, 'service.data');
const service = createService(formData, imageStream, originalService);
requests.push(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,14 @@ Object {
"namespace": "mock-project",
},
"spec": Object {
"ports": Array [],
"ports": Array [
Object {
"name": "8080-tcp",
"port": 8080,
"protocol": "TCP",
"targetPort": 8080,
},
],
"selector": Object {
"app": "test-app",
"deploymentconfig": "test-app",
Expand Down
20 changes: 19 additions & 1 deletion frontend/packages/dev-console/src/utils/shared-submit-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const createService = (
name,
labels: userLabels,
image: { ports: imagePorts, tag: selectedTag },
route: { unknownTargetPort, defaultUnknownPort },
} = formData;

const imageStreamName = _.get(imageStreamData, 'metadata.name') || _.get(formData, 'image.name');
Expand All @@ -49,6 +50,10 @@ export const createService = (
isi: { ports: isiPorts },
} = formData;
ports = isiPorts;
} else if (_.isEmpty(ports)) {
const portData = _.toInteger(unknownTargetPort) || defaultUnknownPort;
const port = { containerPort: portData, protocol: 'TCP' };
ports = [port];
}

const newService: any = {
Expand Down Expand Up @@ -87,7 +92,15 @@ export const createRoute = (
application: { name: applicationName },
name,
labels: userLabels,
route: { hostname, secure, path, tls, targetPort: routeTargetPort },
route: {
hostname,
unknownTargetPort,
defaultUnknownPort,
secure,
path,
tls,
targetPort: routeTargetPort,
},
image: { ports: imagePorts, tag: selectedTag },
} = formData;

Expand All @@ -114,6 +127,11 @@ export const createRoute = (
containerPort: _.toInteger(port),
protocol: 'TCP',
});
} else if (_.isEmpty(ports) && !routeTargetPort) {
targetPort = makePortName({
containerPort: _.toInteger(unknownTargetPort) || defaultUnknownPort,
protocol: 'TCP',
});
} else {
targetPort = routeTargetPort || makePortName(_.head(ports));
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/packages/git-service/src/types/build-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const Golang: BuildTool = {
name: 'Golang',
type: 'golang',
language: 'go',
expectedRegexps: RegExp([`main.go`, `Gopkg.toml`, `glide.yaml`].join('|')),
expectedRegexps: RegExp([`.*.go`, `Gopkg.toml`, `glide.yaml`].join('|')),
expectedFiles: ['main.go', 'Gopkg.toml', 'glide.yaml'],
};

Expand Down

0 comments on commit d48058a

Please sign in to comment.