diff --git a/src/orchestrator.ts b/src/orchestrator.ts index 4bef30990..163e60135 100644 --- a/src/orchestrator.ts +++ b/src/orchestrator.ts @@ -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 = [ diff --git a/src/providers/k8s/chain-spec.ts b/src/providers/k8s/chain-spec.ts index 7bb28bd12..3522286d2 100644 --- a/src/providers/k8s/chain-spec.ts +++ b/src/providers/k8s/chain-spec.ts @@ -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"; @@ -63,7 +63,7 @@ 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, @@ -71,5 +71,27 @@ export async function getChainSpecRaw(namespace: string, image: string, chainNam 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); } \ No newline at end of file diff --git a/static-configs/job-svc-account.yaml b/static-configs/job-svc-account.yaml index 8b901c443..3e1123a1c 100644 --- a/static-configs/job-svc-account.yaml +++ b/static-configs/job-svc-account.yaml @@ -31,7 +31,7 @@ metadata: subjects: - kind: ServiceAccount name: zombie-internal-kubectl - namespace: zombie-561bd6264d4126d4b2631cfb2fabff84 + namespace: "{{namespace}}" roleRef: kind: ClusterRole name: delete-podmonitors