Skip to content

Commit

Permalink
fix: add required persistent attribute when using ram class storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Redm4x committed Apr 29, 2024
1 parent df59bb0 commit edd205b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 33 deletions.
18 changes: 3 additions & 15 deletions .commitlintrc.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
{
"extends": [
"@commitlint/config-conventional"
],
"extends": ["@commitlint/config-conventional"],
"rules": {
"scope-enum": [
2,
"always",
[
"certificates",
"network",
"wallet",
"api",
"stargate"
]
]
"scope-enum": [2, "always", ["certificates", "network", "wallet", "api", "stargate"]]
}
}
}
6 changes: 0 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@
"npm run test",
"npm run lint:fix",
"npm run format"
],
"package.json": [
"sort-json package.json"
],
"tsconfig.json": [
"sort-json tsconfig.json"
]
},
"main": "build/index.js",
Expand Down
28 changes: 18 additions & 10 deletions src/sdl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import {
v3ComputeResources,
v2ServiceParams,
v3DeploymentGroup,
v3ManifestServiceParams
v3ManifestServiceParams,
v2StorageAttributes
} from "./types";
import { convertCpuResourceString, convertResourceString } from "./sizes";
import { default as stableStringify } from "json-stable-stringify";
Expand Down Expand Up @@ -234,7 +235,7 @@ export class SDL {
? {
name: storage.name || "default",
[key]: this.resourceUnit(storage.size, asString),
attributes: this.serviceResourceAttributes(storage.attributes)
attributes: this.serviceResourceStorageAttributes(storage.attributes)
}
: {
name: storage.name || "default",
Expand All @@ -252,6 +253,20 @@ export class SDL {
);
}

serviceResourceStorageAttributes(attributes?: v2StorageAttributes) {
if (!attributes) return undefined;

const pairs = Object.keys(attributes).map(key => ({ key, value: attributes[key].toString() }));

if (attributes.class === "ram" && !attributes.persistent) {
pairs.push({ key: "persistent", value: "false" });
}

pairs.sort((a, b) => a.key.localeCompare(b.key));

return pairs;
}

serviceResourceGpu(resource: v3ResourceGPU | undefined, asString: boolean) {
const value = resource?.units || 0;
const numVal = isString(value) ? Buffer.from(value, "ascii") : value;
Expand Down Expand Up @@ -625,14 +640,7 @@ export class SDL {
quantity: {
val: this.resourceValue(convertResourceString(storage.size), asString)
},
attributes:
storage.attributes &&
Object.entries(storage.attributes)
.sort(([k0], [k1]) => k0.localeCompare(k1))
.map(([key, value]) => ({
key: key,
value: value.toString()
}))
attributes: this.serviceResourceStorageAttributes(storage.attributes)
}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ exports[`test sdl persistent storage SDL: Persistent Storage Manifest: SDL: Pers
"key": "class",
"value": "ram",
},
{
"key": "persistent",
"value": "false",
},
],
"name": "shm",
"size": {
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"target": "es2021" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
// "lib": [], /* Specify library files to be included in the compilation. */
"allowJs": true /* Allow javascript files to be compiled. */,
"allowJs": true /* Allow javascript files to be compiled. */,
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
"declaration": true /* Generates corresponding '.d.ts' file. */,
Expand Down Expand Up @@ -43,7 +43,7 @@
// "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */

/* Module Resolution Options */
"moduleResolution": "Node16" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
"moduleResolution": "Node16" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
Expand Down

0 comments on commit edd205b

Please sign in to comment.