Skip to content

TSI-4381: feat(app): 由对象流驱动应用调和与记录清扫 - #33

Closed
multica-tsic404[bot] wants to merge 1 commit into
mainfrom
multica/TSI-4381
Closed

multica-tsic404[bot] wants to merge 1 commit into
mainfrom
multica/TSI-4381

Conversation

@multica-tsic404

@multica-tsic404 multica-tsic404 Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Closes TSI-4381

Issue: TSI-4381(Multica 01a1796b-58a4-7395-9960-4630f8f42ff0)

设计依据

tsic/kos-design@32b4bca

本单冻结锚点为 f7cfaa6,它早于 C-69 的引入;实现与设计 PR 都基于当前设计头。

设计实现

设计要求 代码落点
02-contracts §C-33:新建与变更的 Application 在生产链路上首次入队 pkg/app/runtime.go:Runtime(Application informer 的 Add 与状态变化 Update 入队);tests/acceptance/TC-55/tc55_watch_test.go
02-contracts §C-33:用户重试后回到 Installing 在生产链路可达(Failed 轮次返回零 Result,无自带重排) pkg/app/runtime.go:enqueueRecord(动作记录 informer 按 data.application 入队所属应用);tests/acceptance/TC-55/tc55_watch_test.go
02-contracts §C-13:2 分钟新鲜度与既有 30 秒 RequeueAfter 共存,互不遮蔽 watch 只追加轮次:pkg/app/runtime.go:applicationChanged 让状态写入不入队,轮次返回的 RequeueAfter 原样保留(pkg/app/controller.go 未改);settled 应用仍按 30 秒重观察,Failed 应用没有重排,只能由记录 watch 触达
02-contracts §C-69:动作记录由应用调和器读取后删除 消费仍在 pkg/app/controller.go:pendingAction 与 deleteRecord;pkg/app/runtime.go:enqueueRecord 提供到达它的轮次
02-contracts §C-69:应用对象在非卸载路径消失后的记录清扫 pkg/app/runtime.go:sweepActionRecords、recordOrphaned、Run(缓存同步后先扫一次,随后按间隔清扫);tests/acceptance/TC-139/tc139_test.go
01-scope 禁项 F17:为具体产品在内核新增对象类、页面或名称分支 未引入(只新增对象流接线与记录清扫,对象模型、写入表与页面均未改动)

设计变更

触发 条目 变更 外部可观察行为是否变化
D3 02-contracts §C-69 新增清扫判据:记录以应用 UID 绑定;应用在非卸载路径消失后由应用调和器清扫,不设过期时间、不依赖跨命名空间 ownerReference 回收;应用弃置清单不参与清扫 否(记录属内核内部对象,阶段、健康、投影与控制面响应不变)
D4 03-acceptance §AC-27 / TC-139 新增记录清扫的可观察判据与 TC-139 否

设计 PR: https://gitea.tsic.top/tsic/kos-design/pulls/17

Summary by Sourcery

Wire application reconciliation to object events and clean up action records left behind by applications that disappear.

New Features:

  • Drive application reconciliation from application and action-record object streams, including initial creation, meaningful changes, and retry actions.
  • Periodically remove orphaned action records while preserving abandonment manifests and records belonging to live applications.

Enhancements:

  • Preserve controller requeue scheduling while adding watch-triggered reconciliation and avoid enqueueing rounds for status-only updates.

Tests:

  • Add unit coverage for event filtering, action-record targeting, orphan detection, and safe sweep behavior.
  • Add acceptance coverage for retry delivery through the action-record watch and cleanup of records belonging to deleted applications.

应用调和器此前只由测试直接驱动:新建或变更的应用不会入队,Failed 的
应用在用户重试后没有轮次读取动作记录,应用在卸载路径之外消失时记录留
在 KOS 命名空间里。

新增运行时接线:应用与动作记录各由一个 informer 入队,既有轮次重观察
保持不变;记录所属应用消失后由清扫删除,应用弃置清单不参与清扫。
@sourcery-ai

sourcery-ai Bot commented Nov 1, 2026

Copy link
Copy Markdown

Sorry @multica-tsic404[bot], you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 23 hours and 17 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Nov 1, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR introduces a production Runtime that connects Application and action-record informer streams to reconciliation rounds, filters updates to preserve existing requeue semantics, and periodically removes UID-bound records for disappeared applications; focused unit and acceptance tests cover retry delivery, cleanup safety, restart behavior, and abandonment-manifest preservation.

Sequence diagram for orphaned action-record cleanup

sequenceDiagram
    participant Runtime
    participant Store
    participant AppController

    Runtime->>Store: List action records
    loop each action record
        Runtime->>Store: Get target Application
        alt application absent or UID changed or target missing
            Runtime->>AppController: deleteRecord
            AppController->>Store: Delete action record
        else application still matches record UID
            Runtime-->>Runtime: Keep record
        end
    end
Loading

File-Level Changes

Change Details Files
Added production runtime wiring that drives application reconciliation from informer events while preserving controller requeue behavior.
  • Watch Application additions and meaningful spec/deletion updates.
  • Watch labeled action records and enqueue their target application.
  • Run reconciliation workers with configurable concurrency and sweep interval.
  • Ignore status-only updates so reconciler status writes do not self-trigger rounds.
pkg/app/runtime.go
pkg/app/doc.go
Implemented periodic cleanup for action records that can no longer be consumed.
  • Perform an immediate sweep after informer cache synchronization and repeat it on a configurable interval.
  • Identify orphaned records by missing targets, missing applications, or mismatched application UIDs.
  • Retain records when application reads fail and exclude abandonment manifests from cleanup.
pkg/app/runtime.go
pkg/app/runtime_test.go
tests/acceptance/TC-139/tc139_test.go
Added unit and acceptance coverage for event-driven retries and record cleanup.
  • Verify target parsing and application update filtering.
  • Verify cleanup deletes only orphaned or invalid records and preserves records when reads fail.
  • Verify Failed applications receive user retries through the action-record watch.
  • Verify startup and periodic cleanup while preserving abandonment manifests.
pkg/app/runtime_test.go
tests/acceptance/TC-55/tc55_watch_test.go
tests/acceptance/TC-139/tc139_test.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@tsic404

tsic404 commented Nov 2, 2026

Copy link
Copy Markdown
Owner

随 TSI-4477 的设计重排作废:TSI-4381 已按用户指示关闭,本 PR 不再合入。后续实现按项目划分(tsic404/kosd 等)重新立项与排期。

@tsic404 tsic404 closed this Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant