Skip to content

Commit

Permalink
feat: add exposeHost option (#558)
Browse files Browse the repository at this point in the history
* add exposeHost option

When using export, a Route is generated, but there was no way to define
the hostname for the route.


Co-authored-by: Maximilian Zellhofer <maximilian.zellhofer@apa.at>
  • Loading branch information
mzellho and mzellho committed May 7, 2021
1 parent 443c24c commit 497f8d3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions bin/nodeshift
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ yargs
type: 'boolean',
default: false
})
.options('exposeHost', {
describe: 'Alias/DNS that points to the service. Must be used with expose',
type: 'string'
})
.options('namespace.displayName', {
describe: 'flag to specify the project namespace display name to build/deploy into. Overwrites any namespace settings in your OpenShift or Kubernetes configuration files',
type: 'string'
Expand Down Expand Up @@ -262,6 +266,7 @@ function createOptions (argv) {
options.removeAll = argv.removeAll;
options.namespace = argv.namespace;
options.expose = argv.expose;
options.exposeHost = argv.exposeHost;
options.configLocation = argv.configLocation;

// Check for the --build.env array
Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function logout (options = {}) {
@param {string} [options.insecure] - flag to pass into the openshift rest client for logging in with a self signed cert. Only used with apiServer login. default to false
@param {string} [options.forceLogin] - Force a login when using the apiServer login. Only used with apiServer login. default to false
@param {boolean} [options.expose] - Set to true to create a default Route and expose the default service. defaults to false
@param {string} [options.exposeHost] - Alias/DNS that points to the service. Must be used with expose
@param {object} [options.namespace] -
@param {string} [options.namespace.displayName] - flag to specify the project namespace display name to build/deploy into. Overwrites any namespace settings in your OpenShift or Kubernetes configuration files
@param {boolean} [options.namespace.create] - flag to create the namespace if it does not exist. Only applicable for the build and deploy command. Must be used with namespace.name
Expand Down Expand Up @@ -92,6 +93,7 @@ function deploy (options = {}) {
@param {string} [options.insecure] - flag to pass into the openshift rest client for logging in with a self signed cert. Only used with apiServer login. default to false
@param {string} [options.forceLogin] - Force a login when using the apiServer login. Only used with apiServer login. default to false
@param {boolean} [options.expose] - Set to true to create a default Route and expose the default service. defaults to false
@param {string} [options.exposeHost] - Alias/DNS that points to the service. Must be used with expose
@param {object} [options.namespace] -
@param {string} [options.namespace.displayName] - flag to specify the project namespace display name to build/deploy into. Overwrites any namespace settings in your OpenShift or Kubernetes configuration files
@param {string} [options.namespace.name] - flag to specify the project namespace name to build/deploy into. Overwrites any namespace settings in your OpenShift or Kubernetes configuration files
Expand Down Expand Up @@ -127,6 +129,7 @@ function resource (options = {}) {
@param {string} [options.insecure] - flag to pass into the openshift rest client for logging in with a self signed cert. Only used with apiServer login. default to false
@param {string} [options.forceLogin] - Force a login when using the apiServer login. Only used with apiServer login. default to false
@param {boolean} [options.expose] - Set to true to create a default Route and expose the default service. defaults to false
@param {string} [options.exposeHost] - Alias/DNS that points to the service. Must be used with expose
@param {object} [options.namespace] -
@param {string} [options.namespace.displayName] - flag to specify the project namespace display name to build/deploy into. Overwrites any namespace settings in your OpenShift or Kubernetes configuration files
@param {boolean} [options.namespace.create] - flag to create the namespace if it does not exist. Only applicable for the build and deploy command. Must be used with namespace.name
Expand Down
2 changes: 1 addition & 1 deletion lib/definitions/route-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const baseRouteSpec = {
};

module.exports = (resource, config) => {
resource.spec = _.merge({}, baseRouteSpec, { port: { targetPort: config.port } }, resource.spec);
resource.spec = _.merge({}, baseRouteSpec, { port: { targetPort: config.port }, host: config.exposeHost }, resource.spec);

resource.spec.to.name = resource.spec.to.name ? resource.spec.to.name : config.projectName;
return resource;
Expand Down
11 changes: 8 additions & 3 deletions test/definitions-tests/route-spec-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ test('route spec test', (t) => {

const config = {
projectName: 'project name',
port: 8080
port: 8080,
exposeHost: 'project.name'
};

const rs = routeSpec(resource, config);
t.equal(rs.spec.port.targetPort, 8080, 'targetPort should be 8080');
t.equal(rs.spec.host, 'project.name', 'host should be project.name');
t.equal(rs.spec.to.kind, 'Service', 'should have a kind of Service');
t.equal(rs.spec.to.name, config.projectName, `name should be config.name ${config.projectName}`);
t.end();
Expand All @@ -29,17 +31,20 @@ test('route spec test', (t) => {
},
port: {
targetPort: 3000
}
},
host: 'not.project.name'
}
};

const config = {
projectName: 'project name',
port: 8080
port: 8080,
exposeHost: 'project.name'
};

const rs = routeSpec(resource, config);
t.equal(rs.spec.port.targetPort, 3000, 'targetPort should be 3000');
t.equal(rs.spec.host, 'not.project.name', `host should not be overridden and use ${resource.spec.host}`);
t.equal(rs.spec.to.kind, 'Service', 'should have a kind of Service');
t.equal(rs.spec.to.name, 'Not Project Name', `name should not be overridden and use ${resource.spec.to.name}`);
t.end();
Expand Down

0 comments on commit 497f8d3

Please sign in to comment.