Skip to content

Commit

Permalink
fix: remove hardcoded is for resource profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
jtary committed Sep 1, 2023
1 parent ea38570 commit 7021a3d
Show file tree
Hide file tree
Showing 5 changed files with 398 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/sdl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,9 @@ export class SDL {
};
}

serviceResourcesBeta3(profile: v3ProfileCompute, service: v2Service, asString: boolean = false) {
serviceResourcesBeta3(id: number, profile: v3ProfileCompute, service: v2Service, asString: boolean = false) {
return {
id: 1,
id: id,
cpu: this.serviceResourceCpu(profile.resources.cpu),
memory: this.serviceResourceMemory(profile.resources.memory, asString),
storage: this.serviceResourceStorage(profile.resources.storage, asString),
Expand Down Expand Up @@ -487,7 +487,7 @@ export class SDL {
return manifestService;
}

v3ManifestService(placement: string, name: string, asString: boolean): v3ManifestService {
v3ManifestService(id: number, placement: string, name: string, asString: boolean): v3ManifestService {
const service = this.data.services[name];
const deployment = this.data.deployment[name];
const profile = this.data.profiles.compute[deployment[placement].profile];
Expand All @@ -498,7 +498,7 @@ export class SDL {
command: service.command || null,
args: service.args || null,
env: service.env || null,
resources: this.serviceResourcesBeta3(profile as v3ProfileCompute, service, asString),
resources: this.serviceResourcesBeta3(id, profile as v3ProfileCompute, service, asString),
count: deployment[placement].count,
expose: this.v3ManifestExpose(service),
params: this.v3ManifestServiceParams(service.params),
Expand All @@ -517,8 +517,8 @@ export class SDL {
return Object.keys(this.placements()).map(name => ({
name: name,
services: this.deploymentsByPlacement(name)
.map(([service]) => this.v3ManifestService(name, service, asString))
.sort((a, b) => a.name.localeCompare(b.name))
.sort(([a], [b]) => a.localeCompare(b))
.map(([service], idx) => this.v3ManifestService(idx + 1, name, service, asString))
}));
}

Expand Down Expand Up @@ -714,7 +714,7 @@ export class SDL {
group.boundComputes[placementName] = {};
}

const resources = this.serviceResourcesBeta3(compute as v3ProfileCompute, service, false);
const resources = this.serviceResourcesBeta3(0, compute as v3ProfileCompute, service, false);
const location = group.boundComputes[placementName][svcdepl.profile];

if (!location) {
Expand Down Expand Up @@ -864,4 +864,9 @@ export class SDL {

return new Uint8Array(sum);
}

manifestSorted() {
const sorted = this.manifestSortedJSON();
return JSON.parse(sorted);
}
}
43 changes: 43 additions & 0 deletions tap-snapshots/tests/test_sdl_wordpress.ts.test.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* IMPORTANT
* This snapshot file is auto-generated, but designed for humans.
* It should be checked into source control and tracked carefully.
* Re-generate by setting TAP_SNAPSHOT=1 and running tests.
* Make sure to inspect the output below. Do not ignore changes!
*/
'use strict'
exports[`tests/test_sdl_wordpress.ts TAP SDL: Wordpress Version > Manifest version matches expected result 1`] = `
Uint8Array [
219,
108,
51,
117,
198,
203,
254,
23,
231,
87,
195,
36,
147,
215,
27,
25,
65,
116,
86,
242,
189,
131,
165,
98,
212,
63,
194,
233,
63,
64,
141,
48,
]
`
208 changes: 208 additions & 0 deletions tests/fixtures/wordpress.manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
[
{
"name": "akash",
"services": [
{
"name": "db",
"image": "mariadb:10.6.4",
"command": null,
"args": null,
"env": [
"MYSQL_RANDOM_ROOT_PASSWORD=1",
"MYSQL_DATABASE=wordpress",
"MYSQL_USER=wordpress",
"MYSQL_PASSWORD=testpass4you"
],
"resources": {
"id": 1,
"cpu": {
"units": {
"val": "1000"
}
},
"memory": {
"size": {
"val": "1073741824"
}
},
"storage": [
{
"name": "default",
"size": {
"val": "1073741824"
}
},
{
"name": "wordpress-db",
"size": {
"val": "8589934592"
},
"attributes": [
{
"key": "class",
"value": "beta3"
},
{
"key": "persistent",
"value": "true"
}
]
}
],
"gpu": {
"units": {
"val": "0"
}
},
"endpoints": []
},
"count": 1,
"expose": [
{
"port": 3306,
"externalPort": 0,
"proto": "TCP",
"service": "wordpress",
"global": false,
"hosts": null,
"httpOptions": {
"maxBodySize": 1048576,
"readTimeout": 60000,
"sendTimeout": 60000,
"nextTries": 3,
"nextTimeout": 0,
"nextCases": [
"error",
"timeout"
]
},
"ip": "",
"endpointSequenceNumber": 0
},
{
"port": 33060,
"externalPort": 0,
"proto": "TCP",
"service": "wordpress",
"global": false,
"hosts": null,
"httpOptions": {
"maxBodySize": 1048576,
"readTimeout": 60000,
"sendTimeout": 60000,
"nextTries": 3,
"nextTimeout": 0,
"nextCases": [
"error",
"timeout"
]
},
"ip": "",
"endpointSequenceNumber": 0
}
],
"params": {
"storage": [
{
"name": "wordpress-db",
"mount": "/var/lib/mysql",
"readOnly": false
}
]
}
},
{
"name": "wordpress",
"image": "wordpress",
"command": null,
"args": null,
"env": [
"WORDPRESS_DB_HOST=db",
"WORDPRESS_DB_USER=wordpress",
"WORDPRESS_DB_PASSWORD=testpass4you",
"WORDPRESS_DB_NAME=wordpress"
],
"resources": {
"id": 2,
"cpu": {
"units": {
"val": "4000"
}
},
"memory": {
"size": {
"val": "4294967296"
}
},
"storage": [
{
"name": "default",
"size": {
"val": "4294967296"
}
},
{
"name": "wordpress-data",
"size": {
"val": "34359738368"
},
"attributes": [
{
"key": "class",
"value": "beta3"
},
{
"key": "persistent",
"value": "true"
}
]
}
],
"gpu": {
"units": {
"val": "0"
}
},
"endpoints": [
{
"sequence_number": 0
}
]
},
"count": 1,
"expose": [
{
"port": 80,
"externalPort": 0,
"proto": "TCP",
"service": "",
"global": true,
"hosts": null,
"httpOptions": {
"maxBodySize": 104857600,
"readTimeout": 60000,
"sendTimeout": 60000,
"nextTries": 3,
"nextTimeout": 0,
"nextCases": [
"error",
"timeout"
]
},
"ip": "",
"endpointSequenceNumber": 0
}
],
"params": {
"storage": [
{
"name": "wordpress-data",
"mount": "/var/www/html",
"readOnly": false
}
]
}
}
]
}
]
Loading

0 comments on commit 7021a3d

Please sign in to comment.