Skip to content

Commit

Permalink
remove the string version of the namespace flag (#299)
Browse files Browse the repository at this point in the history
* feat: remove the string option for namespace creation.

BREAKING CHANGE: remove the string option for namespace creation.  This has been deprecated and it is now time to remove it

fixes #282
  • Loading branch information
lholmquist committed Mar 27, 2019
1 parent 1c104ff commit 5674b89
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 102 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,6 @@ Shows the below help
[boolean]
--expose flag to create a default Route and expose the default
service [boolean] [choices: true, false] [default: false]
--namespace DEPRECATED - use object form instead. flag to
specify the project namespace to build/deploy into.
Overwrites any namespace settings in your OpenShift
or Kubernetes configuration files [string]
--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
Expand Down
4 changes: 0 additions & 4 deletions bin/nodeshift
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ yargs
type: 'boolean',
default: false
})
.options('namespace', {
describe: 'DEPRECATED - use object form instead. flag to specify the project namespace to build/deploy into. Overwrites any namespace settings in your OpenShift or Kubernetes configuration files',
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
5 changes: 0 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ 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(deprecated)] - DEPRECATED - use object form instead. Overwrites any namespace settings in your OpenShift or Kubernetes configuration files
@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 @@ -48,7 +47,6 @@ 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(deprecated)] - DEPRECATED - use object form instead. Overwrites any namespace settings in your OpenShift or Kubernetes configuration files
@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.namesapce.name] - flag to specify the project namespace name to build/deploy into. Overwrites any namespace settings in your OpenShift or Kubernetes configuration files
Expand All @@ -73,7 +71,6 @@ 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(deprecated)] - DEPRECATED - use object form instead. Overwrites any namespace settings in your OpenShift or Kubernetes configuration files
@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 @@ -101,7 +98,6 @@ 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(deprecated)] - DEPRECATED - use object form instead. Overwrites any namespace settings in your OpenShift or Kubernetes configuration files
@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.remove] - flag to remove the user created namespace. Only applicable for the undeploy command. Must be used with namespace.name
Expand Down Expand Up @@ -130,7 +126,6 @@ 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(deprecated)] - DEPRECATED - use object form instead. Overwrites any namespace settings in your OpenShift or Kubernetes configuration files
@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
28 changes: 2 additions & 26 deletions lib/nodeshift-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,39 +35,15 @@ async function setup (options = {}) {
const projectPackage = require(`${options.projectLocation}/package.json`);
const config = await openshiftConfigLoader(Object.assign({}, { tryServiceAccount: options.tryServiceAccount, configLocation: options.configLocation }));
if (options.namespace) {
// options.namespace can be either a String, Array or Object
// If it is an Array, Then if there is a value that is a string, that means the user specifed "--namespace=Name" and "--namespace.something=ELSE", we are deprecating just the string form, but we need to take this into account
if (Array.isArray(options.namespace)) {
// Map the values and then convert to an object using spread
options.namespace = Object.assign({}, ...options.namespace.map((n) => {
if (typeof n === 'string') {
return { _name: n };
}
return n;
}));

options.namespace.name = options.namespace.name ? options.namespace.name : options.namespace._name;
} else if (typeof options.namespace === 'object') {
// If the value is an Object, then they are specifying things. And at name is required.
if (!options.namespace.name) {
throw new Error('namespace.name must be specified when using the --namespace flag');
}
} else {
// It is a string, then just "--namespace=NAME" was used, this is deprecated
logger.warning('--namespace=NAME is deprecated, please use object form. ex: --namespace.name=NAME');
options.namespace = {
create: false,
displayName: options.namespace,
name: options.namespace
};
if (!options.namespace.name) {
throw new Error('namespace.name must be specified when using the --namespace flag');
}

// Add this userDefined property that will be used during undeploy
options.namespace.userDefined = true;
// Need to remove any spaces and convert to lowe case
options.namespace.name = options.namespace.name.replace(/\s+/g, '').toLowerCase();
// A user is overriding the namespace
// convert options.namespce into an object for later use
config.context.namespace = options.namespace.name;
}

Expand Down
69 changes: 6 additions & 63 deletions test/nodeshift-config-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ test('nodeshift-config options for the config loader - change the namespace', (t
});

const options = {
namespace: 'foo'
namespace: {
name: 'foo'
}
};

nodeshiftConfig(options).then((config) => {
Expand All @@ -236,7 +238,9 @@ test('nodeshift-config options for the config loader - change the namespace, for
});

const options = {
namespace: 'New Project'
namespace: {
name: 'New Project'
}
};

nodeshiftConfig(options).then((config) => {
Expand Down Expand Up @@ -297,64 +301,3 @@ test('nodeshift-config options for the config loader - using namespace object fo
t.end();
});
});

// This test is a little contrived since someone using the API would probably never do this
// This is just testing what the CLI would provide is someone used --namespace=VALUE and --namespace.displayName=VALUE for instance
test('nodeshift-config options for the config loader - using namespace as a string and object, provide name', (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: ['Name', {
displayName: 'New Project',
name: 'Project Name'
}]
};

nodeshiftConfig(options).then((config) => {
t.equal(config.context.namespace, 'projectname', 'context and options namespace should be the same');
t.equal(config.namespace._name, 'Name', 'should have the "private" _name field');
t.equal(config.namespace.userDefined, true, 'should have the user defined variable');
t.equal(config.namespace.displayName, options.namespace.displayName, 'should have the displayName');
t.end();
});
});

// This test is a little contrived since someone using the API would probably never do this
// This is just testing what the CLI would provide is someone used --namespace=VALUE and --namespace.displayName=VALUE for instance
test('nodeshift-config options for the config loader - using namespace as a string and object, provide name', (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: ['Name', {
displayName: 'New Project'
}]
};

nodeshiftConfig(options).then((config) => {
t.equal(config.context.namespace, 'name', 'context and options namespace should be the same');
t.equal(config.namespace._name, 'Name', 'should have the "private" _name field');
t.equal(config.namespace.userDefined, true, 'should have the user defined variable');
t.equal(config.namespace.displayName, options.namespace.displayName, 'should have the displayName');
t.end();
});
});

0 comments on commit 5674b89

Please sign in to comment.