Skip to content

Commit

Permalink
Features/new storage class ram (#68)
Browse files Browse the repository at this point in the history
* added validation for storage class ram

* added tests for the ram storage validation

* refactored tap test to jest

* remove tap snapshot for persistent storage
  • Loading branch information
baktun14 authored Mar 19, 2024
1 parent b1b0f14 commit c8573ed
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 91 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {
{
displayName: "unit",
...common,
testMatch: ["<rootDir>/src/**/*.spec.ts"],
testMatch: ["<rootDir>/src/**/*.spec.ts", "<rootDir>/tests/**/*.spec.ts"],
setupFilesAfterEnv: ["./test/setup-unit-tests.ts"]
}
]
Expand Down
26 changes: 25 additions & 1 deletion src/sdl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const Endpoint_RANDOM_PORT = 1;
const Endpoint_LEASED_IP = 2;

function isArray<T>(obj: any): obj is Array<T> {
return obj && obj.map !== undefined;
return Array.isArray(obj);
}

function isString(str: any): str is string {
Expand Down Expand Up @@ -71,6 +71,8 @@ export class SDL {
if (version === "beta3") {
SDL.validateGPU(name, profile.resources.gpu);
}

SDL.validateStorage(name, profile.resources.storage);
}

return data;
Expand Down Expand Up @@ -105,6 +107,28 @@ export class SDL {
}
}

static validateStorage(name: string, storage?: v2ResourceStorage | v2ResourceStorageArray) {
if (!storage) {
throw new Error("Storage is required for service " + name);
}

const storages = isArray(storage) ? storage : [storage];

for (const storage of storages) {
if (typeof storage.size === "undefined") {
throw new Error("Storage size is required for service " + name);
}

if (!!storage.attributes) {
for (const [key, value] of Object.entries(storage.attributes)) {
if (key === "class" && value === "ram" && storage.attributes.persistent === true) {
throw new Error("Storage attribute 'ram' must have 'persistent' set to 'false' or not defined for service " + name);
}
}
}
}
}

services() {
if (this.data) {
return this.data.services;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
/* 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_persistent_storage_attributes.ts TAP SDL: Persistent Storage Manifest > Manifest matches expected result 1`] = `
Array [
Object {
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`test sdl persistent storage SDL: Persistent Storage Manifest: SDL: Persistent Storage Manifest 1`] = `
[
{
"Name": "akash",
"Services": Array [
Object {
"Services": [
{
"Args": null,
"Command": null,
"Count": 1,
"Env": Array [
"Env": [
"WORDPRESS_DB_HOST=db",
"WORDPRESS_DB_USER=wordpress",
"WORDPRESS_DB_PASSWORD=testpass4you",
"WORDPRESS_DB_NAME=wordpress",
],
"Expose": Array [
Object {
"Expose": [
{
"EndpointSequenceNumber": 0,
"ExternalPort": 0,
"Global": true,
"Hosts": null,
"HTTPOptions": Object {
"HTTPOptions": {
"MaxBodySize": 104857600,
"NextCases": Array [
"NextCases": [
"error",
"timeout",
],
Expand All @@ -37,6 +31,7 @@ Array [
"ReadTimeout": 60000,
"SendTimeout": 60000,
},
"Hosts": null,
"IP": "",
"Port": 80,
"Proto": "TCP",
Expand All @@ -45,72 +40,71 @@ Array [
],
"Image": "wordpress",
"Name": "wordpress",
"params": Object {
"Storage": Array [
Object {
"mount": "/var/www/html",
"name": "wordpress-data",
"readOnly": false,
},
],
},
"Resources": Object {
"cpu": Object {
"units": Object {
"Resources": {
"cpu": {
"units": {
"val": "4000",
},
},
"endpoints": null,
"memory": Object {
"size": Object {
"memory": {
"size": {
"val": 4294967296,
},
},
"storage": Array [
Object {
"storage": [
{
"name": "default",
"size": Object {
"size": {
"val": 4294967296,
},
},
Object {
"attributes": Array [
Object {
{
"attributes": [
{
"key": "class",
"value": "beta3",
},
Object {
{
"key": "persistent",
"value": "true",
},
],
"name": "wordpress-data",
"size": Object {
"size": {
"val": 34359738368,
},
},
],
},
"params": {
"Storage": [
{
"mount": "/var/www/html",
"name": "wordpress-data",
"readOnly": false,
},
],
},
},
Object {
{
"Args": null,
"Command": null,
"Count": 1,
"Env": Array [
"Env": [
"MYSQL_RANDOM_ROOT_PASSWORD=1",
"MYSQL_DATABASE=wordpress",
"MYSQL_USER=wordpress",
"MYSQL_PASSWORD=testpass4you",
],
"Expose": Array [
Object {
"Expose": [
{
"EndpointSequenceNumber": 0,
"ExternalPort": 0,
"Global": false,
"Hosts": null,
"HTTPOptions": Object {
"HTTPOptions": {
"MaxBodySize": 1048576,
"NextCases": Array [
"NextCases": [
"error",
"timeout",
],
Expand All @@ -119,19 +113,19 @@ Array [
"ReadTimeout": 60000,
"SendTimeout": 60000,
},
"Hosts": null,
"IP": "",
"Port": 3306,
"Proto": "TCP",
"Service": "wordpress",
},
Object {
{
"EndpointSequenceNumber": 0,
"ExternalPort": 0,
"Global": false,
"Hosts": null,
"HTTPOptions": Object {
"HTTPOptions": {
"MaxBodySize": 1048576,
"NextCases": Array [
"NextCases": [
"error",
"timeout",
],
Expand All @@ -140,6 +134,7 @@ Array [
"ReadTimeout": 60000,
"SendTimeout": 60000,
},
"Hosts": null,
"IP": "",
"Port": 33060,
"Proto": "TCP",
Expand All @@ -148,54 +143,71 @@ Array [
],
"Image": "mariadb:10.6.4",
"Name": "db",
"params": Object {
"Storage": Array [
Object {
"mount": "/var/lib/mysql",
"name": "wordpress-db",
"readOnly": false,
},
],
},
"Resources": Object {
"cpu": Object {
"units": Object {
"Resources": {
"cpu": {
"units": {
"val": "1000",
},
},
"endpoints": null,
"memory": Object {
"size": Object {
"memory": {
"size": {
"val": 1073741824,
},
},
"storage": Array [
Object {
"storage": [
{
"name": "default",
"size": Object {
"size": {
"val": 1073741824,
},
},
Object {
"attributes": Array [
Object {
{
"attributes": [
{
"key": "class",
"value": "beta3",
},
Object {
{
"key": "persistent",
"value": "true",
},
],
"name": "wordpress-db",
"size": Object {
"size": {
"val": 8589934592,
},
},
{
"attributes": [
{
"key": "class",
"value": "ram",
},
],
"name": "shm",
"size": {
"val": 1073741824,
},
},
],
},
"params": {
"Storage": [
{
"mount": "/var/lib/mysql",
"name": "wordpress-db",
"readOnly": false,
},
{
"mount": "/dev/shm",
"name": "shm",
"readOnly": false,
},
],
},
},
],
},
]
`
`;
52 changes: 52 additions & 0 deletions tests/fixtures/persistent_storage_invalid.sdl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
version: "2.0"

services:
grafana:
image: grafana/grafana
expose:
- port: 3000
as: 80
to:
- global: true
accept:
- webdistest.localhost
params:
storage:
data:
mount: /var/lib/grafana
shm:
mount: /dev/shm
profiles:
compute:
grafana:
resources:
cpu:
units: 1
memory:
size: 1Gi
storage:
- size: 512Mi
- name: data
size: 1Gi
attributes:
persistent: true
class: beta2
- name: shm
size: 1Gi
attributes:
persistent: true
class: ram
placement:
westcoast:
attributes:
region: us-west
pricing:
grafana:
denom: uakt
amount: 1000
deployment:
grafana:
westcoast:
profile: grafana
count: 1
Loading

0 comments on commit c8573ed

Please sign in to comment.