UNPKG

@zombienet/orchestrator

Version:

ZombieNet aim to be a testing framework for substrate based blockchains, providing a simple cli tool that allow users to spawn and test ephemeral Substrate based networks

51 lines (50 loc) 1.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ChaosResource = void 0; class ChaosResource { constructor(name, namespace, delay) { this.name = name; this.namespace = namespace; this.delay = delay; } generateSpec() { if (this.delay.latency.slice(-2) !== "ms") { throw Error("Latency value should include the 'ms' indicator (e.g. '100ms')"); } if (this.delay.jitter && this.delay.jitter.slice(-2) !== "ms") { throw Error("Jitter value should include the 'ms' indicator (e.g. '100ms')"); } if (this.delay.correlation) { const correlation = parseFloat(this.delay.correlation); if (Number.isNaN(correlation)) { throw Error("Correlation value should be parsable as Float by k8s api (e.g. '100')"); } else { this.delay.correlation = correlation.toString(); } } else { // set default correlation (100) this.delay.correlation = "100"; } return this.generateChaosSpec(); } generateChaosSpec() { return { apiVersion: "chaos-mesh.org/v1alpha1", kind: "NetworkChaos", metadata: { name: this.name }, spec: { mode: "all", action: "delay", selector: { pods: { [this.namespace]: [this.name], }, }, delay: this.delay, }, }; } } exports.ChaosResource = ChaosResource;