Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chain spec extra check #27

Merged
merged 3 commits into from
Dec 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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