Skip to content

Commit

Permalink
feat: add the namespace flag (#234)
Browse files Browse the repository at this point in the history
This allows the user to specify a namespace project during the build/deploy. Overwrites any namespace settings in your OpenShift or Kubernetes configuration files

fixes #233
  • Loading branch information
lholmquist committed Jun 1, 2018
1 parent 5e7eb71 commit 13e5316
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ Shows the below help
[default: "latest"]
--quiet supress INFO and TRACE lines from output logs
[boolean]
--expose flag to create a default Route and expose the default
service [boolean] [choices: true, false] [default: false]
--namespace flag to specify the project namespace to build/deploy
into. Overwrites any namespace settings in your OpenShift or Kubernetes configuration files
[string]
--deploy.port flag to update the default ports on the resource files.
Defaults to 8080 [default: 8080]
--build.recreate flag to recreate a buildConfig or Imagestream
Expand Down
5 changes: 5 additions & 0 deletions bin/nodeshift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ yargs
type: 'boolean',
default: false
})
.options('namespace', {
describe: 'flag to specify the project namespace to build/deploy into. Overwrites any namespace settings in your OpenShift or Kubernetes configuration files',
type: 'string'
})
.options('deploy.port', {
describe: 'flag to update the default ports on the resource files. Defaults to 8080',
default: 8080
Expand Down Expand Up @@ -140,6 +144,7 @@ function createOptions (argv) {
options.cmd = argv.cmd;
// undeploy might have a positional argument
options.removeAll = argv.removeAll;
options.namespace = argv.namespace;
options.expose = argv.expose;
options.strictSSL = argv.strictSSL !== 'false';
options.tryServiceAccount = argv.tryServiceAccount !== 'false';
Expand Down
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const cli = require('./bin/cli');
@param {boolean} [options.strictSSL] - Set to false to allow self-signed Certs
@param {boolean} [options.tryServiceAccount] - Set to false to by-pass service account lookup
@param {boolean} [options.expose] - Set to true to create a default Route and expose the default service. defaults to false
@param {string} [options.namespace] - Overwrites any namespace settings in your OpenShift or Kubernetes configuration files
@param {string} [options.nodeVersion] - set the nodeversion to use for the bucharest-gold/centos7-s2i-image. Versions are docker hub tags: https://hub.docker.com/r/bucharestgold/centos7-s2i-nodejs/tags/
@param {boolean} [options.quiet] - supress INFO and TRACE lines from output logs
@param {object} [options.deploy] -
Expand All @@ -43,6 +44,7 @@ function deploy (options = {}) {
@param {boolean} [options.strictSSL] - Set to false to allow self-signed Certs
@param {boolean} [options.tryServiceAccount] - Set to false to by-pass service account lookup
@param {boolean} [options.expose] - Set to true to create a default Route and expose the default service. defaults to false
@param {string} [options.namespace] - Overwrites any namespace settings in your OpenShift or Kubernetes configuration files
@param {string} [options.nodeVersion] - set the nodeversion to use for the bucharest-gold/centos7-s2i-image. Versions are docker hub tags: https://hub.docker.com/r/bucharestgold/centos7-s2i-nodejs/tags/
@param {boolean} [options.quiet] - supress INFO and TRACE lines from output logs
@param {object} [options.build] -
Expand All @@ -64,6 +66,7 @@ function resource (options = {}) {
@param {boolean} [options.strictSSL] - Set to false to allow self-signed Certs
@param {boolean} [options.tryServiceAccount] - Set to false to by-pass service account lookup
@param {boolean} [options.expose] - Set to true to create a default Route and expose the default service. defaults to false
@param {string} [options.namespace] - Overwrites any namespace settings in your OpenShift or Kubernetes configuration files
@param {string} [options.nodeVersion] - set the nodeversion to use for the bucharest-gold/centos7-s2i-image. Versions are docker hub tags: https://hub.docker.com/r/bucharestgold/centos7-s2i-nodejs/tags/
@param {boolean} [options.quiet] - supress INFO and TRACE lines from output logs
@param {object} [options.deploy] -
Expand All @@ -87,6 +90,7 @@ function applyResource (options = {}) {
@param {string} [options.projectLocation] - the location(directory) of your projects package.json. Defaults to `process.cwd`
@param {boolean} [options.strictSSL] - Set to false to allow self-signed Certs
@param {boolean} [options.tryServiceAccount] - Set to false to by-pass service account lookup
@param {string} [options.namespace] - Overwrites any namespace settings in your OpenShift or Kubernetes configuration files
@param {string} [options.nodeVersion] - set the nodeversion to use for the bucharest-gold/centos7-s2i-image. Versions are docker hub tags: https://hub.docker.com/r/bucharestgold/centos7-s2i-nodejs/tags/
@param {boolean} [options.quiet] - supress INFO and TRACE lines from output logs
@param {boolean} [options.removeAll] - option to remove builds, buildConfigs and Imagestreams. Defaults to false
Expand All @@ -111,6 +115,7 @@ function undeploy (options = {}) {
@param {string} [options.projectLocation] - the location(directory) of your projects package.json. Defaults to `process.cwd`
@param {boolean} [options.strictSSL] - Set to false to allow self-signed Certs
@param {boolean} [options.tryServiceAccount] - Set to false to by-pass service account lookup
@param {string} [options.namespace] - Overwrites any namespace settings in your OpenShift or Kubernetes configuration files
@param {string} [options.nodeVersion] - set the nodeversion to use for the bucharest-gold/centos7-s2i-image. Versions are docker hub tags: https://hub.docker.com/r/bucharestgold/centos7-s2i-nodejs/tags/
@param {boolean} [options.quiet] - supress INFO and TRACE lines from output logs
@param {object} [options.build] -
Expand Down
3 changes: 3 additions & 0 deletions lib/nodeshift-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ async function setup (options = {}) {
logger.info('loading configuration');
const projectPackage = require(`${options.projectLocation}/package.json`);
const config = await openshiftConfigLoader(Object.assign({}, {tryServiceAccount: options.tryServiceAccount, configLocation: options.configLocation}));
if (options.namespace) {
config.context.namespace = options.namespace;
}
logger.info(`using namespace ${config.context.namespace} at ${config.cluster}`);

if (!projectPackage.name.match(/^[a-z][0-9a-z-]+[0-9a-z]$/)) {
Expand Down
23 changes: 23 additions & 0 deletions test/nodeshift-config-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,26 @@ test('nodeshift-config options for the config loader', (t) => {
t.end();
});
});

test('nodeshift-config options for the config loader - change the namespace', (t) => {
const nodeshiftConfig = proxyquire('../lib/nodeshift-config', {
'openshift-config-loader': (options) => {
return Promise.resolve({
context: {
namespace: 'test-namespace'
},
cluster: 'http://mock-cluster'
});
},
'openshift-rest-client': () => { return Promise.resolve({}); }
});

const options = {
namespace: 'foo'
};

nodeshiftConfig(options).then((config) => {
t.equal(config.namespace, options.namespace, 'namespace should be changed');
t.end();
});
});

0 comments on commit 13e5316

Please sign in to comment.