Skip to content
This repository was archived by the owner on Feb 28, 2020. It is now read-only.

Commit b6a259c

Browse files
author
Christian Compton
committed
feat: intial kubernetes support
1 parent 64a5919 commit b6a259c

File tree

4 files changed

+90
-14
lines changed

4 files changed

+90
-14
lines changed

package.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,29 @@
2222
"generator"
2323
],
2424
"dependencies": {
25+
"@arf/generator-cloud-enablement": "0.0.25",
26+
"bluebird": "^3.5.0",
2527
"chalk": "^1.1.0",
2628
"debug": "^2.2.0",
27-
"js-yaml": "^3.4.2",
28-
"yeoman-generator": "^1.1.1",
2929
"handlebars": "^4.0.5",
30-
"bluebird": "^3.5.0",
30+
"js-yaml": "^3.9.1",
3131
"request": "^2.81.0",
32-
"swagger-parser": "^3.4.1",
33-
"swagger-schema-official": "^2.0.0-",
34-
"swaggerize-routes": "^1.0.0",
3532
"rimraf": "^2.5.2",
36-
"unzip2": "^0.2.5"
33+
"swagger-parser": "^3.4.2",
34+
"swagger-schema-official": "^2.0.0-d79c205",
35+
"swaggerize-routes": "^1.0.0",
36+
"unzip2": "^0.2.5",
37+
"yeoman-generator": "^1.1.1"
3738
},
3839
"devDependencies": {
39-
"codecov": "^2.1.0",
40+
"codecov": "^2.3.0",
4041
"istanbul": "^0.4.5",
4142
"mem-fs": "^1.1.3",
4243
"mem-fs-editor": "^3.0.2",
43-
"mocha": "^3.2.0",
44+
"mocha": "^3.5.0",
4445
"nock": "^9.0.13",
4546
"nyc": "^10.1.2",
46-
"standard": "^10.0.2",
47+
"standard": "^10.0.3",
4748
"standard-version": "^4.2.0",
4849
"yeoman-assert": "^3.0.0",
4950
"yeoman-test": "^1.6.0"

refresh/index.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ module.exports = Generator.extend({
185185
if (typeof (this.spec.bluemix.instances) === 'number') {
186186
this.bluemix.instances = this.spec.bluemix.instances
187187
}
188+
if (typeof (this.spec.bluemix.namespace) === 'string') {
189+
this.bluemix.namespace = this.spec.bluemix.namespace
190+
}
188191
}
189192

190193
// Clean app name (for containers and other uses)
@@ -1257,7 +1260,8 @@ module.exports = Generator.extend({
12571260
services: this.services,
12581261
capabilities: this.capabilities,
12591262
hostSwagger: this.hostSwagger,
1260-
bluemix: this.bluemix }
1263+
bluemix: this.bluemix
1264+
}
12611265
)
12621266
})
12631267

@@ -1286,6 +1290,14 @@ module.exports = Generator.extend({
12861290
})
12871291
},
12881292

1293+
writeKubernetesFiles: function () {
1294+
if (!this.docker) return
1295+
1296+
var server = (this.bluemix.domain && this.bluemix.namespace) ? {domain: this.bluemix.domain, namespace: this.bluemix.namespace } : undefined;
1297+
this.composeWith(require.resolve('@arf/generator-cloud-enablement/generators/kubernetes'), {force: this.force, bluemix: { backendPlatform: "SWIFT", name: this.cleanAppName, server: server }} )
1298+
1299+
},
1300+
12891301
writePackageSwift: function () {
12901302
// Check if there is a Package.swift, create one if there isn't
12911303
this._ifNotExistsInProject('Package.swift', (filepath) => {

refresh/templates/docker/cli-config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ container-path-run : "/swift-project"
1414
container-path-tools : "/swift-project"
1515
container-port-map : "8080:8080"
1616
container-port-map-debug : "2048:1024,2049:1025"
17+
chart-path : "helm/<%- cleanAppName.toLowerCase() %>"

test/unit/refresh.js

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ var expectedBluemixFiles = ['manifest.yml',
5151
'.bluemix/toolchain.yml',
5252
'.bluemix/deploy.json']
5353

54+
var expectedDockerFiles = ['cli-config.yml',
55+
'.dockerignore',
56+
'Dockerfile',
57+
'Dockerfile-tools']
58+
59+
var expectedKubernetesFiles = [`helm/${appName}/Chart.yaml`,
60+
`helm/${appName}/values.yaml`,
61+
`helm/${appName}/templates/deployment.yaml`,
62+
`helm/${appName}/templates/service.yaml`]
63+
5464
describe('swiftserver:refresh', function () {
5565
before('set sdkgen status check delay to 1ms', function () {
5666
// alter delay between status checks to speed up unit tests
@@ -939,6 +949,14 @@ describe('swiftserver:refresh', function () {
939949
assert.noFile(expectedBluemixFiles)
940950
})
941951

952+
it('does not generate the docker files', function () {
953+
assert.noFile(expectedDockerFiles)
954+
})
955+
956+
it('does not generate the kubernetes files', function () {
957+
assert.noFile(expectedKubernetesFiles)
958+
})
959+
942960
it('does not generate any capabilities', function () {
943961
assert.noFileContent(`Sources/${applicationModule}/Application.swift`, 'import SwiftMetrics')
944962
assert.noFileContent(`Sources/${applicationModule}/Application.swift`, 'import SwiftMetricsDash')
@@ -1076,6 +1094,7 @@ describe('swiftserver:refresh', function () {
10761094
logger: 'helium',
10771095
port: 4567
10781096
},
1097+
docker: true,
10791098
'models': [
10801099
{
10811100
'name': modelName,
@@ -1129,6 +1148,14 @@ describe('swiftserver:refresh', function () {
11291148
assert.file(expectedBluemixFiles)
11301149
})
11311150

1151+
it('generates the docker files', function () {
1152+
assert.file(expectedDockerFiles)
1153+
})
1154+
1155+
it('generates the expected kubernetes files', function () {
1156+
assert.file(expectedKubernetesFiles)
1157+
})
1158+
11321159
it('defines OPENAPI_SPEC environment variable', function () {
11331160
assert.fileContent('manifest.yml', 'OPENAPI_SPEC: "/swagger/api"')
11341161
})
@@ -1452,12 +1479,14 @@ describe('swiftserver:refresh', function () {
14521479
bluemix: {
14531480
'name': 'test',
14541481
'host': 'myhost',
1455-
'domain': 'mydomain.net'
1482+
'domain': 'mydomain.net',
1483+
'namespace': 'mynamespace'
14561484
},
14571485
config: {
14581486
logger: 'helium',
14591487
port: 4567
1460-
}
1488+
},
1489+
docker: true
14611490
}
14621491
runContext = helpers.run(path.join(__dirname, '../../refresh'))
14631492
.withOptions({
@@ -1513,11 +1542,27 @@ describe('swiftserver:refresh', function () {
15131542
it('produces the correct disk quota in the manifest', function () {
15141543
assert.fileContent('manifest.yml', 'disk_quota: 1024M')
15151544
})
1545+
1546+
it('adds the proper chart-path in cli-config.yml', function () {
1547+
assert.fileContent('cli-config.yml', 'chart-path : "helm/test"')
1548+
})
1549+
1550+
it('populates the correct name in Chart.yaml', function () {
1551+
assert.fileContent('helm/test/Chart.yaml', 'name: test')
1552+
})
1553+
1554+
it('populates the correct values in values.yaml', function () {
1555+
assert.fileContent('helm/test/values.yaml', 'name: test')
1556+
assert.fileContent('helm/test/values.yaml', 'repository: registry.mydomain.net/mynamespace/')
1557+
})
1558+
15161559
})
15171560

15181561
describe('Generate skeleton web application for bluemix with incorrect custom options', function () {
15191562
var runContext
15201563

1564+
//CHRISTIAN ToDo: Add testcases for cloud-enablement with these incorrect options
1565+
15211566
before(function () {
15221567
// Set up the spec file which should create all the necessary files for a server
15231568
var spec = {
@@ -1601,6 +1646,14 @@ describe('swiftserver:refresh', function () {
16011646
it('does not generate the bluemix files', function () {
16021647
assert.noFile(expectedBluemixFiles)
16031648
})
1649+
1650+
it('does not generate the docker files', function () {
1651+
assert.noFile(expectedDockerFiles)
1652+
})
1653+
1654+
it('does not generate the kubernetes files', function () {
1655+
assert.noFile(expectedKubernetesFiles)
1656+
})
16041657
})
16051658

16061659
describe('Generate a web application with capabilities', function () {
@@ -2262,7 +2315,8 @@ describe('swiftserver:refresh', function () {
22622315
config: {
22632316
logger: 'helium',
22642317
port: 4567
2265-
}
2318+
},
2319+
docker: true
22662320
}
22672321
runContext = helpers.run(path.join(__dirname, '../../refresh'))
22682322
.withOptions({
@@ -2296,6 +2350,14 @@ describe('swiftserver:refresh', function () {
22962350
assert.file(expectedBluemixFiles)
22972351
})
22982352

2353+
it('generates the docker files', function () {
2354+
assert.file(expectedDockerFiles)
2355+
})
2356+
2357+
it('generates the kubernetes files with expected values', function () {
2358+
assert.file(expectedKubernetesFiles)
2359+
})
2360+
22992361
it('defines example endpoints', function () {
23002362
var productsRoutesFile = `Sources/${applicationModule}/Routes/ProductsRoutes.swift`
23012363
assert.file(productsRoutesFile)

0 commit comments

Comments
 (0)