Skip to content

Commit 9e377e8

Browse files
committed
Debug
1 parent ec90579 commit 9e377e8

File tree

2 files changed

+50
-35
lines changed

2 files changed

+50
-35
lines changed

.gitlab-ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ paras:
409409
# - job: publish-docker-pr
410410

411411
variables:
412+
DEBUG_DEPTH: 10
412413
GH_DIR: "https://github.com/paritytech/zombienet/tree/${CI_COMMIT_SHORT_SHA}/tests/paras"
413414

414415
before_script:

javascript/packages/orchestrator/src/providers/k8s/kubeClient.ts

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class KubeClient extends Client {
6363
this.configPath = configPath;
6464
this.namespace = namespace;
6565
this.debug = true;
66-
this.timeout = 300; // secs
66+
this.timeout = 600; // secs
6767
this.tmpDir = tmpDir;
6868
this.localMagicFilepath = `${tmpDir}/finished.txt`;
6969
this.remoteDir = DEFAULT_REMOTE_DIR;
@@ -128,7 +128,7 @@ export class KubeClient extends Client {
128128

129129
logTable.print();
130130

131-
await this.createResource(podDef, true, false);
131+
await this.createResource(podDef, true);
132132
await this.wait_transfer_container(name);
133133

134134
if (dbSnapshot) {
@@ -200,6 +200,8 @@ export class KubeClient extends Client {
200200
);
201201
}
202202

203+
debug("spawnFromDef: Before putLocalMagicFile");
204+
await this.wait_container(name, name, "waiting");
203205
await this.putLocalMagicFile(name);
204206
await this.wait_pod_ready(name);
205207
logTable = new CreateLogTable({
@@ -230,7 +232,6 @@ export class KubeClient extends Client {
230232
async createResource(
231233
resourseDef: any,
232234
scoped: boolean = false,
233-
waitReady: boolean = false,
234235
): Promise<void> {
235236
await this.runCommand(["apply", "-f", "-"], {
236237
resourceDef: JSON.stringify(resourseDef),
@@ -240,27 +241,6 @@ export class KubeClient extends Client {
240241
debug(resourseDef);
241242
const name = resourseDef.metadata.name;
242243
const kind: string = resourseDef.kind.toLowerCase();
243-
244-
if (waitReady) {
245-
// loop until ready
246-
let t = this.timeout;
247-
const args = ["get", kind, name, "-o", "jsonpath={.status}"];
248-
do {
249-
const result = await this.runCommand(args);
250-
const status = JSON.parse(result.stdout);
251-
if (["Running", "Succeeded"].includes(status.phase)) return;
252-
253-
// check if we are waiting init container
254-
for (const s of status.initContainerStatuses) {
255-
if (s.name === TRANSFER_CONTAINER_NAME && s.state.running) return;
256-
}
257-
258-
await new Promise((resolve) => setTimeout(resolve, 3000));
259-
t -= 3;
260-
} while (t > 0);
261-
262-
throw new Error(`Timeout(${this.timeout}) for ${kind} : ${name}`);
263-
}
264244
}
265245

266246
async wait_pod_ready(podName: string): Promise<void> {
@@ -279,27 +259,61 @@ export class KubeClient extends Client {
279259

280260
throw new Error(`Timeout(${this.timeout}) for pod : ${podName}`);
281261
}
282-
async wait_transfer_container(podName: string): Promise<void> {
262+
263+
async wait_container(
264+
pod: string,
265+
container: string,
266+
status: string,
267+
): Promise<void> {
283268
// loop until ready
284269
let t = this.timeout;
285-
const args = ["get", "pod", podName, "-o", "jsonpath={.status}"];
270+
const args = ["get", "pod", pod, "-o", "jsonpath={.status}"];
286271
do {
272+
debug("wait_container_ready: loop until ready");
287273
const result = await this.runCommand(args);
288-
const status = JSON.parse(result.stdout);
274+
const json = JSON.parse(result.stdout);
275+
debug(json);
276+
277+
const other_result = await this.runCommand([
278+
"get",
279+
"pod",
280+
pod,
281+
"--no-headers",
282+
]);
283+
debug(other_result.stdout);
289284

290-
// check if we are waiting init container
291-
if (status.initContainerStatuses) {
292-
for (const s of status.initContainerStatuses) {
293-
if (s.name === TRANSFER_CONTAINER_NAME && s.state.running) return;
294-
}
285+
let containerStatuses = json?.containerStatuses ?? [];
286+
let initContainerStatuses = json?.initContainerStatuses ?? [];
287+
for (const s of containerStatuses.concat(initContainerStatuses)) {
288+
if (s.name === container && s.state[status]) return;
295289
}
296290

297291
await new Promise((resolve) => setTimeout(resolve, 3000));
298292
t -= 3;
299293
} while (t > 0);
300294

301295
throw new Error(
302-
`Timeout(${this.timeout}) for transfer container for pod : ${podName}`,
296+
`Timeout(${this.timeout}) for ${container} container for pod : ${pod}`,
297+
);
298+
}
299+
300+
async wait_transfer_container(pod: string): Promise<void> {
301+
await this.wait_container(pod, TRANSFER_CONTAINER_NAME, "running");
302+
303+
// loop until ready
304+
let t = this.timeout;
305+
const args = ["logs", "--tail=1", pod, "-c", `${TRANSFER_CONTAINER_NAME}`];
306+
do {
307+
const result = await this.runCommand(args);
308+
309+
if (result.stdout == "waiting for tar to finish") return;
310+
311+
await new Promise((resolve) => setTimeout(resolve, 3000));
312+
t -= 3;
313+
} while (t > 0);
314+
315+
throw new Error(
316+
`Timeout(${this.timeout}) for pod : ${pod}, container: ${TRANSFER_CONTAINER_NAME}`,
303317
);
304318
}
305319

@@ -386,7 +400,7 @@ export class KubeClient extends Client {
386400
if (unique) {
387401
if (container === TRANSFER_CONTAINER_NAME) {
388402
const args = ["cp", localFilePath, `${identifier}:${podFilePath}`];
389-
if (container) args.push("-c", container);
403+
args.push("-c", container);
390404
await this.runCommand(args);
391405
debug("copyFileToPod", args);
392406
} else {
@@ -723,7 +737,7 @@ export class KubeClient extends Client {
723737
opts?: RunCommandOptions,
724738
): Promise<RunCommandResponse> {
725739
try {
726-
const augmentedCmd: string[] = ["--kubeconfig", this.configPath];
740+
const augmentedCmd: string[] = [];
727741
if (opts?.scoped === undefined || opts?.scoped)
728742
augmentedCmd.push("--namespace", this.namespace);
729743

0 commit comments

Comments
 (0)