Skip to content

[需求] CI容器通用化k8s错误反馈机制-补充优化-的开发实现-runner-container-hooks部分#20

Merged
flysky22222 merged 1 commit into
release/no_volumesfrom
issue-1203
Jul 1, 2026
Merged

[需求] CI容器通用化k8s错误反馈机制-补充优化-的开发实现-runner-container-hooks部分#20
flysky22222 merged 1 commit into
release/no_volumesfrom
issue-1203

Conversation

@flysky22222

Copy link
Copy Markdown

背景

[需求] CI容器通用化k8s错误反馈机制-补充优化(runner-container-hooks)· 开发流水线 · 开发预览阶段(代码已推 + 预览已部署 + UT 已补;门禁/对抗由 PR CI 异步跑)

注意:本 PR 基于 release/no_volumes 分支(不是 main),按照 @Longwt123 的要求重新创建。之前的 PR #19(基于 main)已关闭。

改动内容

release/no_volumes 已有的 Pending 阶段错误检测(无需改动,保留)

  • UNRECOVERABLE_WAITING_REASONS (ImagePullBackOff, ErrImagePull, InvalidImageName, CreateContainerConfigError, CreateContainerError)
  • UNRECOVERABLE_EVENT_REASONS (FailedMount, FailedScheduling, FailedBinding)
  • getContainerErrors(), getPodConditionErrors(), getPodEventErrors()
  • describePodFailure(), waitForPodPhases() with full error detection
  • prepareJob() with improved error message formatting

本轮新增:Running 阶段 terminated 错误检测 + FailedMount 补充

packages/k8s/src/k8s/index.ts

  • Added FailedMount to UNRECOVERABLE_WAITING_REASONS (per design §2.3 check-npu #1 — FailedMount can appear as container waiting reason in some k8s versions)
  • Added UNRECOVERABLE_TERMINATED_REASONS Set with OOMKilled, Error, FailedPostStartHookError (per design §2.3 feat: add preferred pod affinity for app pod #3)
  • Added getUnrecoverableTerminatedReasons() function with env var ACTIONS_RUNNER_K8S_UNRECOVERABLE_TERMINATED_REASONS extension support (per design §2.3 feat: delete check npu script #5)
  • Added getContainerTerminatedErrors() function — detects terminated containers with unrecoverable reasons, returns formatted strings with ✗ markers (per design §2.3 update runner to 2.330.0 #8)

packages/k8s/src/hooks/run-container-step.ts

  • Added imports for describePodFailure, getContainerTerminatedErrors, getPodByName from ../k8s
  • In the catch block: best-effort check for terminated container errors via getContainerTerminatedErrors + describePodFailure before rethrowing (per design §2.3 Tfh novolumes #11, adapted for release/no_volumes's runContainerStep flow)

11 种错误 → 检测机制映射

# 错误类型 检测函数 Pod 阶段
1 InvalidImageName getContainerErrors Pending
2 ErrImagePull/ImagePullBackOff getContainerErrors Pending
3 CreateContainerConfigError getContainerErrors Pending
4 CreateContainerError getContainerErrors Pending
5 FailedMount getContainerErrors + getPodEventErrors Pending
6 FailedScheduling (nodeSelector) getPodConditionErrors + getPodEventErrors Pending
7 FailedBinding (PVC不存在) getPodEventErrors Pending
8 FailedScheduling (422资源超限) getPodEventErrors Pending
9 OOMKilled getContainerTerminatedErrors Running→Failed
10 容器崩溃 exit non-zero getContainerTerminatedErrors Running→Failed
11 FailedPostStartHookError getContainerTerminatedErrors Running→Failed

UT Coverage

packages/k8s/tests/wait-for-pod-phases-test.ts — 10 new tests

  • getContainerTerminatedErrors: 8 tests (no errors, no terminated state, recoverable reasons, OOMKilled, Error, FailedPostStartHookError, every reason, init containers, whitelist filtering)
  • getUnrecoverableTerminatedReasons: 4 tests (defaults, env var extension, honors in getContainerTerminatedErrors, filters empty strings)

packages/k8s/tests/run-container-step-terminated-test.ts — 5 new tests

  • OOMKilled detection + describePodFailure output
  • Error (exit non-zero) detection + describePodFailure output
  • FailedPostStartHookError detection + describePodFailure output
  • No terminated errors (describePodFailure not called)
  • Graceful handling of getPodByName failure

All 15 new tests pass. All 44 existing wait-for-pod-phases tests pass. TypeScript compiles without errors.

相关 Issue

resolve https://github.com/opensourceways/backlog/issues/1203

AI 使用声明

当前 PR 是否有 AI 参与:

…-only to 11 types

- Add FailedMount to UNRECOVERABLE_WAITING_REASONS (covers waiting-state volume mount failures)
- Add UNRECOVERABLE_TERMINATED_REASONS (OOMKilled, Error, FailedPostStartHookError) for Running-phase errors
- Add getUnrecoverableTerminatedReasons() with env var extension support
- Add getContainerTerminatedErrors() for detecting terminated containers with unrecoverable reasons
- Add terminated error detection in runContainerStep catch block with describePodFailure diagnostics
- Branch based on release/no_volumes (not main) per issue #1203 request

UT coverage:
- wait-for-pod-phases-test.ts: 10 new tests for getContainerTerminatedErrors (8) and getUnrecoverableTerminatedReasons (4)
- run-container-step-terminated-test.ts: 5 new tests for runContainerStep terminated error detection (OOMKilled, Error, FailedPostStartHookError, no errors, getPodByName failure)
@opensourceways-bot

Copy link
Copy Markdown

Welcome To opensourceways Community

Hey @flysky22222 , thanks for your contribution to the community.

Bot Usage Manual

I'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands.

Contact Guide

If you have any questions, please contact the SIG: infratructure ,
and any of the maintainers: @GeorgeCao-hw, @TangJia025, @pkking, @zhongjun2 ,
and any of the committers: @GeorgeCao-hw, @Goalina, @Hourunze1997, @JavaPythonAIForBAT, @KadenZhang3321, @LiYanghang00, @ccijunk, @drizzlezyk, @githubliuyang777, @pkking, @rosecoffe, @tfhddd, @yao-xiaobai, @zhongjun2, @zkhzkhz .

@opensourceways-bot

Copy link
Copy Markdown

CLA Signature Pass

flysky22222, thanks for your pull request. All authors of the commits have signed the CLA. 👍

@opensourceways-bot

Copy link
Copy Markdown
检查项 状态
敏感信息扫描
安全编码扫描
漏洞扫描
开源license合规扫描
UT覆盖率
开发阶段设计文档检查
流水线链接 点击跳转查看日志

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces unrecoverable container termination error detection in the Kubernetes runner step, adding support for identifying issues like OOMKilled, Error, and FailedPostStartHookError, with the ability to extend these reasons via environment variables. Feedback on these changes suggests optimizing performance by avoiding redundant Kubernetes API calls when fetching pod details, and explicitly checking that the container exit code is non-zero to prevent false positives for successful terminations.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +123 to +126
const pod = await getPodByName(podName)
const terminatedErrors = getContainerTerminatedErrors(pod)
if (terminatedErrors.length > 0) {
const details = await describePodFailure(podName)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Calling getPodByName(podName) and then describePodFailure(podName) results in two consecutive, redundant Kubernetes API calls to fetch the exact same Pod resource (since describePodFailure internally calls readPod to fetch the pod again). To optimize performance and avoid unnecessary API rate-limiting, consider refactoring describePodFailure to accept an optional pre-fetched V1Pod object, allowing you to reuse the pod instance fetched on line 123.

]
for (const cs of allStatuses) {
const terminated = cs.state?.terminated
if (terminated?.reason && unrecoverableReasons.has(terminated.reason)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To prevent potential false positives where a container successfully exits with code 0 but is flagged due to a whitelisted termination reason, we should explicitly check that terminated.exitCode !== 0 before reporting it as an error. This also aligns with the logic used in describePodFailure (line 939).

Suggested change
if (terminated?.reason && unrecoverableReasons.has(terminated.reason)) {
if (terminated?.reason && terminated.exitCode !== 0 && unrecoverableReasons.has(terminated.reason)) {

@flysky22222 flysky22222 merged commit 27d0097 into release/no_volumes Jul 1, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants