This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

blueprint: Add Infrastructure subclass of Deployment

This commit adds a new subclass of Deployment, Infrastructure,
that makes it simpler to create a new Infrastructure, because it
takes the master(s) and worker(s) as constructur arguments.

The Deployment class is now deprecated, and will be removed
in a future commit.
  • Loading branch information...
kayousterhout authored and kklin committed Oct 6, 2017
1 parent 90af36a commit 376c37be7e5c2ed4d683b0721b844339416a8169
Showing with 108 additions and 31 deletions.
  1. +3 −0 CHANGELOG.md
  2. +69 −31 blueprint/bindings.js
  3. +36 −0 blueprint/bindingsTest.js
View
@@ -12,6 +12,9 @@ parent does not exist.
Quilt-managed SSH key should work most of the time because the
daemon automatically grants it access to the cluster.
- Fix a bug where floating IPs would not get properly assigned in GCE.
- Add Infrastructure class for deploying Quilt machines. createDeployment()
and the Deployment class are now deprecated, and users should transition
to using Infrastructure instead.
JavaScript API-breaking changes:
- Remove the Container.replicate() method. Users should create multiple
View
@@ -12,6 +12,65 @@ let fs = require('fs'); // eslint-disable-line prefer-const
const githubCache = {};
const objectHasKey = Object.prototype.hasOwnProperty;
class Deployment {
/**
* Creates a new deployment object with the given options.
* @deprecated Deployment is now deprecated in favor of {@link Infrastructure}.
* @constructor
*
* @param {Object} [deploymentOpts] - Optional arguments to tweak the behavior
* of the namespace.
* @param {string} [deploymentOpts.namespace=default-namespace] - The name of the
* namespace that the blueprint should operate in.
* @param {string[]} [deploymentOpts.adminACL] - A list of IP addresses that are
* allowed to access the deployed machines. The IP of the machine where the
* daemon is running is always allowed to access the machines. If you would like to allow
* another machine to access the deployed machines (e.g., to SSH into a machine),
* add its IP address here. These IP addresses must be in CIDR notation; e.g.,
* to allow access from 1.2.3.4, set adminACL to ["1.2.3.4/32"]. To allow access
* from all IP addresses, set adminACL to ["0.0.0.0/0"].
*/
constructor(deploymentOpts = {}) {
this.namespace = deploymentOpts.namespace || 'default-namespace';
this.adminACL = getStringArray('adminACL', deploymentOpts.adminACL);
checkExtraKeys(deploymentOpts, this);
this.machines = [];
this.containers = new Set();
this.loadBalancers = [];
global._quiltDeployment = this;
}
}
class Infrastructure extends Deployment {
/**
* Creates a new Infrastructure with the given options.
* @constructor
*
* @param {Machine[]} masters - List of machines to use as the masters.
* @param {Machine[]} workers - List of machines to use as the workers.
* Worker machines are responsible for running application containers.
* @param {Object} [opts] - Optional arguments to tweak the behavior
* of the infrastructure.
* @param {string} [opts.namespace=default-namespace] - The name of the
* namespace that the blueprint should operate in.
* @param {string[]} [opts.adminACL] - A list of IP addresses that are
* allowed to access the deployed machines. The IP of the machine where the
* daemon is running is always allowed to access the machines. If you would like to allow
* another machine to access the deployed machines (e.g., to SSH into a machine),
* add its IP address here. These IP addresses must be in CIDR notation; e.g.,
* to allow access from 1.2.3.4, set adminACL to ["1.2.3.4/32"]. To allow access
* from all IP addresses, set adminACL to ["0.0.0.0/0"].
*/
constructor(masters, workers, opts = {}) {
super(opts);
masters.forEach(master => this.machines.push(master.asMaster()));
workers.forEach(worker => this.machines.push(worker.asWorker()));
}
}
/**
* Gets the public key associated with a github username.
* @param {string} user - The GitHub username.
@@ -113,44 +172,14 @@ let uniqueIDCounter = 0;
* Overwrites the deployment object with a new one.
*
* @deprecated This function is deprecated; users should transition to using
* the Deployment constructor directly.
* the {@link Infrastructure} class constructor instead.
*
* @param {Object} deploymentOpts - Options for the new deployment object.
* @returns {Deployment} A deployment object.
*/
function createDeployment(deploymentOpts) {
return new Deployment(deploymentOpts);
}
/**
* Creates a new deployment object with the given options.
* @constructor
*
* @param {Object} [deploymentOpts] - Optional arguments to tweak the behavior
* of the namespace.
* @param {string} [deploymentOpts.namespace=default-namespace] - The name of the
* namespace that the blueprint should operate in.
* @param {string[]} [deploymentOpts.adminACL] - A list of IP addresses that are
* allowed to access the deployed machines. The IP of the machine where the
* daemon is running is always allowed to access the machines. If you would like to allow
* another machine to access the deployed machines (e.g., to SSH into a machine),
* add its IP address here. These IP addresses must be in CIDR notation; e.g.,
* to allow access from 1.2.3.4, set adminACL to ["1.2.3.4/32"]. To allow access
* from all IP addresses, set adminACL to ["0.0.0.0/0"].
*/
function Deployment(deploymentOpts = {}) {
this.namespace = deploymentOpts.namespace || 'default-namespace';
this.adminACL = getStringArray('adminACL', deploymentOpts.adminACL);
checkExtraKeys(deploymentOpts, this);
this.machines = [];
this.containers = new Set();
this.loadBalancers = [];
global._quiltDeployment = this;
}
/**
* @private
* @returns {integer} A globally unique integer ID.
@@ -719,13 +748,21 @@ Machine.prototype.withRole = function machineWithRole(role) {
};
/**
* @deprecated Users should no longer use this function directly, and instead
* should create infrastructure using the {@link Infrastructure} constructor,
* which handles marking the passed-in machines as workers.
*
* @returns {Machine} A new machine with role Worker.
*/
Machine.prototype.asWorker = function machineAsWorker() {
return this.withRole('Worker');
};
/**
* @deprecated Users should no longer use this function directly, and instead
* should create infrastructure using the {@link Infrastructure} constructor,
* which handles marking the passed-in machines as masters.
*
* @returns {Machine} A new machine with role Master.
*/
Machine.prototype.asMaster = function machineAsMaster() {
@@ -1185,6 +1222,7 @@ function resetGlobals() {
module.exports = {
Container,
Deployment,
Infrastructure,
Image,
Machine,
Port,
View
@@ -676,6 +676,42 @@ describe('Bindings', () => {
.to.throw('Unrecognized keys passed to Deployment constructor: badArg');
});
});
describe('Infrastructure', () => {
it('using Infrastructure constructor overwrites the default Deployment', () => {
const namespace = 'testing-namespace';
const machine = new b.Machine({
provider: 'Amazon',
region: 'us-west-2',
});
const infra = new b.Infrastructure([machine], [machine], { namespace });
expect(infra.toQuiltRepresentation().namespace).to.equal(namespace);
});
it('master and worker machines added correctly', () => {
const machine = new b.Machine({
provider: 'Amazon',
region: 'us-west-2',
});
deployment = new b.Infrastructure([machine], [machine, machine]);
checkMachines([{
role: 'Master',
provider: 'Amazon',
region: 'us-west-2',
}, {
// The ID is included here because otherwise the containSubset function
// used in checkMachines will return true, even if there is only one
// worker and two masters in the actual output.
id: '581b4508454ed983d027d699777004feb5c28de3',
role: 'Worker',
provider: 'Amazon',
region: 'us-west-2',
}, {
id: '2f822f1272e60e357b679cc520134dbc38d40daa',
role: 'Worker',
provider: 'Amazon',
region: 'us-west-2',
}]);
});
});
describe('Query', () => {
it('namespace', () => {
deployment = new b.Deployment({ namespace: 'mynamespace' });

0 comments on commit 376c37b

Please sign in to comment.