Skip to content

Commit

Permalink
Chain spec extra check (#27)
Browse files Browse the repository at this point in the history
* add chain-spec raw extra check

* fix namespace

* typo
  • Loading branch information
pepoviola authored Dec 18, 2021
1 parent fccf7bd commit ef89580
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,12 @@ export async function start(
await getChainSpecRaw(namespace, networkSpec.relaychain.defaultImage, chainName, chainSpecFullPath);

// ensure chain raw is ok
const chainRawContent = require(chainSpecFullPath);
debug(`Chain name: ${chainRawContent.name}`);

try {
const chainRawContent = require(chainSpecFullPath);
debug(`Chain name: ${chainRawContent.name}`);
} catch(err) {
throw new Error(`Error: chain-spec raw file at ${chainSpecFullPath} is not a valid JSON`);
}

// files to include in each node
const filesToCopyToNodes = [
Expand Down
26 changes: 24 additions & 2 deletions src/providers/k8s/chain-spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { debug } from "console";
import { genPodDef, getClient } from ".";
import { DEFAULT_CHAIN_SPEC_PATH, TRANSFER_CONTAINER_NAME, FINISH_MAGIC_FILE, DEFAULT_CHAIN_SPEC_COMMAND, DEFAULT_CHAIN_SPEC_RAW_PATH } from "../../configManager";
import { ComputedNetwork } from "../../types";
import { createTempNodeDef, sleep, writeLocalJsonFile } from "../../utils";
const debug = require("debug")("zombie::kube::chain-spec");

import fs from "fs";

Expand Down Expand Up @@ -63,13 +63,35 @@ export async function getChainSpecRaw(namespace: string, image: string, chainNam
}
]);

debug("copy raw chain spec file from pod");
debug("Getting the raw chain spec file from pod to the local environment.");
await client.copyFileFromPod(
podName,
remoteChainSpecRawFullPath,
chainFullPath,
podName
);

// We had some issues where the `raw` file is empty
// let's add some extra checks here to ensure we are ok.
let isValid = false;
try {
let content = require(chainFullPath);
isValid = true;
} catch(_) {}

if(!isValid) {
try {
const result = await client.kubectl(["exec", podName, "--", "cat", remoteChainSpecRawFullPath]);
if(result.exitCode === 0 && result.stdout.length > 0) {
// TODO: remove this debug when we get this fixed.
debug(result.stdout);
fs.writeFileSync(chainFullPath, result.stdout);
isValid = true;
}
} catch(_){}
}

if(!isValid) throw new Error(`Invalid chain spec raw file generated.`);

await client.putLocalMagicFile(podName, podName);
}
2 changes: 1 addition & 1 deletion static-configs/job-svc-account.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ metadata:
subjects:
- kind: ServiceAccount
name: zombie-internal-kubectl
namespace: zombie-561bd6264d4126d4b2631cfb2fabff84
namespace: "{{namespace}}"
roleRef:
kind: ClusterRole
name: delete-podmonitors
Expand Down

0 comments on commit ef89580

Please sign in to comment.