Skip to content
This repository was archived by the owner on Jan 29, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,9 @@ defaults: &defaults
secret: 'service-fabrik-blueprint-secret'
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe its better to have a new plan to have support for k8s and leave the current one's for cf as the plan name in k8s has to be in different format ?!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There will not be any new plan. The same existing BOSH plans will be shown for K8S as well.

redirect_uri: <%= redirect_uri %>
plan_updateable: true
supported_platform:
- k8s
- cf
plans:
###########################
# CONTAINER SERVICE PLANS #
Expand Down Expand Up @@ -565,6 +568,9 @@ defaults: &defaults
- '1 vCPUs'
- '1 GB Memory'
- '1 GB Disk'
supported_platform:
- k8s
- cf
- &blueprint_plan4
id: 'bc158c9a-7934-401e-94ab-057082a5073e'
name: 'v1.0-small'
Expand Down Expand Up @@ -594,6 +600,9 @@ defaults: &defaults
- '1 vCPUs'
- '1 GB Memory'
- '2 GB Disk'
supported_platform:
- k8s
- cf
- &blueprint_plan5
id: 'd616b00a-5949-4b1c-bc73-0d3c59f3954a'
name: 'v1.0-large'
Expand Down Expand Up @@ -624,6 +633,9 @@ defaults: &defaults
- '1 vCPUs'
- '2 GB Memory'
- '2 GB Disk'
supported_platform:
- k8s
- cf
- &blueprint_plan6
id: 'b91d9512-b5c9-4c4a-922a-fa54ae67d235'
name: 'v1.0-dedicated-large-deprecated'
Expand Down
8 changes: 7 additions & 1 deletion lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,14 @@ module.exports = Object.freeze({
K8S: 'kubernetes'
},

PLATFORM_ALIAS_MAPPINGS: {
'cf': 'cloudfoundry',
'k8s': 'kubernetes'
},

PLATFORM_MANAGER: {
'cloudfoundry': 'CfPlatformManager'
'cloudfoundry': 'CfPlatformManager',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of duping, would it rather make sense to set PLATFORM_ALIAS in context at the top of broker processing? that way we always access the manager class via the alias?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have change this and removed the duped ones. Have handled that in the getPlatformManager code.

'kubernetes': 'K8sPlatformManager'
},

AGENT: {
Expand Down
10 changes: 1 addition & 9 deletions lib/controllers/ServiceBrokerApiController.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class ServiceBrokerApiController extends BaseController {
apiVersion(req, res) {
/* jshint unused:false */
const minVersion = CONST.SF_BROKER_API_VERSION_MIN;
const minCloudControllerApiVersion = '2.57.0';
const version = _.get(req.headers, 'x-broker-api-version', '1.0');
return Promise
.try(() => {
Expand All @@ -34,20 +33,13 @@ class ServiceBrokerApiController extends BaseController {
} else {
throw new PreconditionFailed(`At least Broker API version ${minVersion} is required.`);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The below ensures that if the calls from CF are coming in, then for the dependencies of SF on CF are checked via this. This might be true always, but nevertheless a check that could help in rarest of scenarios. Obviously if we are never going to increase the version of minCloudControllerApiVersion & we for sure know CF is already upgraded above this version then this check is unnecessary. Nevertheless worth a discussion before removal.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Post discussion, this is not needed. Keeping this comment for history.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure.

return this.cloudController
.getApiVersion()
.then(apiVersion => {
if (utils.compareVersions(apiVersion, minCloudControllerApiVersion) < 0) {
throw new PreconditionFailed(`At least Cloud Controller API version ${minCloudControllerApiVersion} is required.`);
}
});
})
.throw(new ContinueWithNext());
}

getCatalog(req, res) {
/* jshint unused:false */
res.status(200).json(catalog);
res.status(200).json(this.fabrik.getPlatformManager(req.params.platform).getCatalog(catalog));
}

putInstance(req, res) {
Expand Down
22 changes: 5 additions & 17 deletions lib/fabrik/BasePlatformManager.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
'use strict';

const CONST = require('../constants');

class BasePlatformManager {
constructor(guid, context) {
this.guid = guid;
this.context = context;
constructor(platform) {
this.platform = platform;
}

get platform() {
return this.context.platform;
getCatalog(catalog) {
return catalog;
}

postInstanceProvisionOperations(options) {
Expand All @@ -24,18 +21,9 @@ class BasePlatformManager {
/* jshint unused:false */
}

ensureTenantId(tenant_id) {
ensureTenantId(options) {
/* jshint unused:false */
}

static getInstance(instance_id, context) {
const PlatformManager = (context && CONST.PLATFORM_MANAGER[context.platform]) ? require(`./${CONST.PLATFORM_MANAGER[context.platform]}`) : undefined;  
if (PlatformManager === undefined) {
return new BasePlatformManager(instance_id, context);  
} else { 
return new PlatformManager(instance_id, context);  
}
}

}
module.exports = BasePlatformManager;
43 changes: 21 additions & 22 deletions lib/fabrik/CfPlatformManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,36 @@ const SecurityGroupNotFound = errors.SecurityGroupNotFound;
const ordinals = ['First', 'Second', 'Third', 'Fourth', 'Fifth', 'Sixth', 'Seventh', 'Eighth', 'Ninth', 'Tenth'];

class CfPlatformManager extends BasePlatformManager {
constructor(guid, context) {
super(guid, context);
this.space_guid = context.space_guid;
constructor(platform) {
super(platform);
this.cloudController = cloudController;
}

get securityGroupName() {
return `${CONST.SERVICE_FABRIK_PREFIX}-${this.guid}`;
getSecurityGroupName(guid) {
return `${CONST.SERVICE_FABRIK_PREFIX}-${guid}`;
}

postInstanceProvisionOperations(options) {
return this.createSecurityGroup(options.ipRuleOptions);
return this.createSecurityGroup(options);
}

preInstanceDeleteOperations() {
return this.deleteSecurityGroup();
preInstanceDeleteOperations(options) {
return this.deleteSecurityGroup(options);
}

postInstanceUpdateOperations(options) {
return this.ensureSecurityGroupExists(options.ipRuleOptions);
return this.ensureSecurityGroupExists(options);
}

createSecurityGroup(ruleOptions) {
const name = this.securityGroupName;
const rules = _.map(ruleOptions, opts => this.buildSecurityGroupRules(opts));
createSecurityGroup(options) {
const name = this.getSecurityGroupName(options.guid);
const rules = _.map(options.ruleOptions, opts => this.buildSecurityGroupRules(opts));
logger.info(`Creating security group '${name}' with rules ...`, rules);
return utils
.retry(tries => {
logger.info(`+-> ${ordinals[tries]} attempt to create security group '${name}'...`);
return this.cloudController
.createSecurityGroup(name, rules, [this.space_guid])
.createSecurityGroup(name, rules, [options.context.space_guid])
.catch(err => {
logger.error(err);
throw err;
Expand All @@ -62,21 +61,21 @@ class CfPlatformManager extends BasePlatformManager {
});
}

ensureSecurityGroupExists(ruleOptions) {
const name = this.securityGroupName;
ensureSecurityGroupExists(options) {
const name = this.getSecurityGroupName(options.guid);
logger.info(`Ensuring existence of security group '${name}'...`);
return this.cloudController
.findSecurityGroupByName(name)
.tap(() => logger.info('+-> Security group exists'))
.catch(SecurityGroupNotFound, () => {
logger.warn('+-> Security group does not exist. Trying to create it again.');
return this.ensureTenantId(this.space_guid)
.then(() => this.createSecurityGroup(ruleOptions));
return this.ensureTenantId(options.context.space_guid)
.then(() => this.createSecurityGroup(options.ruleOptions));
});
}

deleteSecurityGroup() {
const name = this.securityGroupName;
deleteSecurityGroup(options) {
const name = this.getSecurityGroupName(options.guid);
logger.info(`Deleting security group '${name}'...`);
return this.cloudController
.findSecurityGroupByName(name)
Expand All @@ -95,10 +94,10 @@ class CfPlatformManager extends BasePlatformManager {
});
}

ensureTenantId(space_guid) {
ensureTenantId(options) {
return Promise
.try(() => space_guid ? space_guid : this.cloudController
.getServiceInstance(this.guid)
.try(() => options.context.space_guid ? options.context.space_guid : this.cloudController
.getServiceInstance(options.guid)
.then(instance => instance.entity.space_guid)
);
}
Expand Down
17 changes: 13 additions & 4 deletions lib/fabrik/DirectorInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ class DirectorInstance extends BaseInstance {
if (operation.type === 'delete') {
return Promise
.all([
this.platformManager.preInstanceDeleteOperations(),
this.platformManager.preInstanceDeleteOperations({
guid: this.guid
}),
this.deleteRestoreFile()
]);
}
Expand All @@ -80,7 +82,10 @@ class DirectorInstance extends BaseInstance {

deleteRestoreFile() {
if (_.includes(this.manager.agent.features, 'backup')) {
return Promise.try(() => this.platformManager.ensureTenantId())
return Promise.try(() => this.platformManager.ensureTenantId({
context: this.platformContext,
guid: this.guid
}))
.then(tenant_id => tenant_id ? this.manager.deleteRestoreFile(tenant_id, this.guid) : Promise.resolve({}))
.catch(err => {
logger.error(`Failed to delete restore file of instance '${this.guid}'`);
Expand Down Expand Up @@ -110,13 +115,17 @@ class DirectorInstance extends BaseInstance {
minDelay: 1000
})
.then(() => this.platformManager.postInstanceProvisionOperations({
ipRuleOptions: this.buildIpRules()
ipRuleOptions: this.buildIpRules(),
guid: this.guid,
context: this.platformContext
}))
.tap(() => operation.state === CONST.OPERATION.SUCCEEDED ? this.scheduleAutoUpdate() : {});

case 'update':
return this.platformManager.postInstanceUpdateOperations({
ipRuleOptions: this.buildIpRules()
ipRuleOptions: this.buildIpRules(),
guid: this.guid,
context: this.platformContext
});
}
})
Expand Down
8 changes: 6 additions & 2 deletions lib/fabrik/DockerInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ class DockerInstance extends BaseInstance {
.catchThrow(DockerError.Conflict, new ServiceInstanceAlreadyExists(this.guid))
.then(() => this.ensureContainerIsRunning(true))
.then(() => this.platformManager.postInstanceProvisionOperations({
ipRuleOptions: this.buildIpRules()
ipRuleOptions: this.buildIpRules(),
guid: this.guid,
context: this.platformContext
}));
}

Expand All @@ -106,7 +108,9 @@ class DockerInstance extends BaseInstance {
delete(params) {
/* jshint unused:false */
return Promise.try(() => this
.platformManager.preInstanceDeleteOperations()
.platformManager.preInstanceDeleteOperations({
guid: this.guid
})
)
.then(() => this.removeContainer())
.catchThrow(DockerError.NotFound, new ServiceInstanceNotFound(this.guid))
Expand Down
12 changes: 11 additions & 1 deletion lib/fabrik/Fabrik.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const FabrikStatusPoller = require('./FabrikStatusPoller');
const DBManager = require('./DBManager');
const OobBackupManager = require('./OobBackupManager');
const BasePlatformManager = require('./BasePlatformManager');
const CONST = require('../constants');

class Fabrik {
static createManager(plan) {
Expand Down Expand Up @@ -41,11 +42,20 @@ class Fabrik {
const instance = manager.createInstance(instance_id);
return Promise
.try(() => context ? context : instance.platformContext)
.then(context => instance.assignPlatformManager(BasePlatformManager.getInstance(instance_id, context)))
.then(context => instance.assignPlatformManager(Fabrik.getPlatformManager(context.platform)))
.return(instance);
});
}

static getPlatformManager(platform) {
const PlatformManager = (platform && CONST.PLATFORM_MANAGER[platform]) ? require(`./${CONST.PLATFORM_MANAGER[platform]}`) : ((platform && CONST.PLATFORM_MANAGER[CONST.PLATFORM_ALIAS_MAPPINGS[platform]]) ? require(`./${CONST.PLATFORM_MANAGER[CONST.PLATFORM_ALIAS_MAPPINGS[platform]]}`) : undefined);
if (PlatformManager === undefined) {
return new BasePlatformManager(platform);  
} else { 
return new PlatformManager(platform);  
}
}

static createOperation(name, opts) {
return new ServiceFabrikOperation(name, opts);
}
Expand Down
41 changes: 41 additions & 0 deletions lib/fabrik/K8sPlatformManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';

const BasePlatformManager = require('./BasePlatformManager');
const _ = require('lodash');

class K8sPlatformManager extends BasePlatformManager {
constructor(platform) {
super(platform);
this.platform = platform;
}

getCatalog(catalog) {
const modifiedCatalog = _.cloneDeep(catalog);
const platform = this.platform;
_.remove(modifiedCatalog.services, function (service) {
_.remove(service.plans, function (plan) {
return !_.includes(_.get(plan, 'supported_platform'), platform);
});
return !_.includes(_.get(service, 'supported_platform'), platform);
});
return modifiedCatalog;
}

postInstanceProvisionOperations(options) {
/* jshint unused:false */
}

preInstanceDeleteOperations(options) {
/* jshint unused:false */
}

postInstanceUpdateOperations(options) {
/* jshint unused:false */
}

ensureTenantId(options) {
/* jshint unused:false */
}

}
module.exports = K8sPlatformManager;
8 changes: 7 additions & 1 deletion lib/fabrik/VirtualHostInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const bosh = require('../bosh');
const utils = require('../utils');
const mapper = require('./VirtualHostRelationMapper');
const catalog = require('../models').catalog;
const CONST = require('../constants');

class VirtualHostInstance extends BaseInstance {
constructor(guid, manager) {
Expand All @@ -24,7 +25,12 @@ class VirtualHostInstance extends BaseInstance {
.then(deploymentName => this.deploymentName = deploymentName);
}

get platformContext() {}
get platformContext() {
const context = {
platform: CONST.PLATFORM.CF
};
return context;
}

create(params) {
return this.cloudController.getServiceInstanceByName(params.parameters.dedicated_rabbitmq_instance, params.space_guid)
Expand Down
4 changes: 3 additions & 1 deletion lib/routes/cf/index.js → lib/routes/broker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@

const express = require('express');
require('../../utils/enableAbsMatchingRouteLookup')(express);
const router = module.exports = express.Router();
const router = module.exports = express.Router({
mergeParams: true
});
router.use('/v2', require('./v2'));
4 changes: 3 additions & 1 deletion lib/routes/cf/v2.js → lib/routes/broker/v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ const config = require('../../config');
const middleware = require('../../middleware');
const controller = require('../../controllers').serviceBrokerApi;

const router = module.exports = express.Router();
const router = module.exports = express.Router({
mergeParams: true
});
const instanceRouter = express.Router({
mergeParams: true
});
Expand Down
Loading