瀏覽代碼

HPCC-24288 Check pod status after startup.

Check if return status of pod.
Also fix issue in agentexec when using child processes.
Wait on pipe and abort if non-zero return code.

Signed-off-by: Jake Smith <jake.smith@lexisnexisrisk.com>
Jake Smith 5 年之前
父節點
當前提交
6fe543a36f
共有 2 個文件被更改,包括 10 次插入1 次删除
  1. 6 0
      common/workunit/workunit.cpp
  2. 4 1
      ecl/agentexec/agentexec.cpp

+ 6 - 0
common/workunit/workunit.cpp

@@ -13918,6 +13918,7 @@ void waitK8sJob(const char *componentName, const char *job)
     jobname.toLowerCase();
     VStringBuffer waitJob("kubectl get jobs %s -o jsonpath={.status.active}", jobname.str());
     VStringBuffer getScheduleStatus("kubectl get pods --selector=job-name=%s --output=jsonpath={.items[*].status.conditions[?(@.type=='PodScheduled')].status}", jobname.str());
+    VStringBuffer checkJobExitCode("kubectl get pods --selector=job-name=%s --output=jsonpath={.items[*].status.containerStatuses[?(@.name==\"%s\")].state.terminated.exitCode}", jobname.str(), jobname.str());
 
     unsigned delay = 100;
     unsigned start = msTick();
@@ -13932,6 +13933,11 @@ void waitK8sJob(const char *componentName, const char *job)
         {
             // Job is no longer active - we can terminate
             DBGLOG("kubectl jobs output: %s", output.str());
+            unsigned ret = runExternalCommand(nullptr, output.clear(), error.clear(), checkJobExitCode.str(), nullptr);
+            if (ret || error.length())
+                throw makeStringExceptionV(0, "Failed to run %s: error %u: %s", checkJobExitCode.str(), ret, error.str());
+            if (!streq(output, "0"))  // state.terminated.exitCode
+                throw makeStringExceptionV(0, "Failed to run %s: pod exited with error: %s", jobname.str(), output.str());
             break;
         }
         ret = runExternalCommand(nullptr, output.clear(), error.clear(), getScheduleStatus.str(), nullptr);

+ 4 - 1
ecl/agentexec/agentexec.cpp

@@ -263,7 +263,10 @@ public:
                     exec.appendf(" --graphName=%s", graphName.get());
                 Owned<IPipeProcess> pipe = createPipeProcess();
                 if (!pipe->run(apptype.str(), exec.str(), ".", false, true, false, 0, false))
-                    throw makeStringExceptionV(0, "Failed to run %s", exec.str());
+                    throw makeStringExceptionV(0, "Failed to run \"%s\"", exec.str());
+                unsigned retCode = pipe->wait();
+                if (retCode)
+                    throw makeStringExceptionV(0, "Failed to run \"%s\": process exited with error: %u", exec.str(), retCode);
             }
         }
         catch (IException *e)