Skip to content

TSI-4372: feat(app): 安装时物化应用包的卷与入口默认值 - #36

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

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

Conversation

@multica-tsic404

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

Copy link
Copy Markdown
Contributor

Closes TSI-4372

设计依据

tsic/kos-design@f7cfaa6(冻结锚点)

设计变更

触发 条目 变更 外部可观察行为是否变化
D0 落地 02-contracts §C-32 补卷名与入口默认值的声明形态、安装时物化与一次性冻结、主机名不可用与缺卷边界的子项;验收补 AC-67/68/69 与 TC-139/140/141 是

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

实现

  • 应用定义新增 spec.volumes(卷名集合)与 spec.endpoints(入口声明:名称与形态字段);应用新增 spec.endpointHosts(声明名 → 用户给出的主机名)。包校验覆盖名字、形态字段与端口。
  • 安装写入路径把定义声明的卷名并入应用 spec.volumes,单对象创建与计划两条路径走同一处物化。
  • 应用调和器在首次安装时把入口声明写成级联入口对象:无需主机名的形态直接物化,需要主机名的形态在应用给出主机名时物化;已存在的入口不改写,因此定义更新不改变已安装对象。
  • 写入分配新增“应用调和器创建级联入口”一行,对应 C-04 的级联入口列。

验证

  • 新增 tests/acceptance/TC-139、TC-140、TC-141:安装时物化、定义更新不改变已安装对象、缺卷与缺主机名两条边界。
  • make verify 通过;go test ./... 全量通过(177 个包,0 失败)。

Summary by Sourcery

Materialize application package volume and endpoint defaults once at installation while validating declarations and preserving user and already-installed state.

New Features:

  • Add package declarations for application volumes and endpoint defaults, with user-supplied hostnames for applicable endpoint types.
  • Materialize declared volumes and cascade endpoints during first installation while preserving installed values across definition updates.

Bug Fixes:

  • Validate volume and endpoint declarations, hostname assignments, endpoint shapes, ports, and name collisions before installation.
  • Keep missing-volume and missing-hostname cases unavailable without creating user-owned volume resources or rewriting user objects.

Enhancements:

  • Unify default materialization across single-object and planned application creation paths.
  • Allocate cascade endpoint creation to the application reconciler with create-only write permissions.

Documentation:

  • Document the new acceptance coverage for installation materialization, frozen installed defaults, and missing resource or hostname boundaries.

Tests:

  • Add unit and acceptance coverage for declaration validation, endpoint materialization, installation immutability, collisions, and boundary behavior.

@sourcery-ai

sourcery-ai Bot commented Nov 2, 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 5 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Nov 2, 2026

Copy link
Copy Markdown

Reviewer's Guide

本 PR 将包的卷名和入口声明纳入应用定义,通过统一的安装默认值物化路径冻结卷集合,并由应用调和器在首次安装时创建带归属的级联入口;严格校验声明与用户主机名,且以幂等、不改写既有对象的方式支持定义更新,同时补齐写入准入和 TC-139/140/141 验收覆盖。

Sequence diagram for installation default materialization

sequenceDiagram
    actor User
    participant ControlPlane
    participant Application
    participant Definition
    participant EndpointStore

    User->>ControlPlane: Create Application
    ControlPlane->>Definition: ValidateDefinition
    ControlPlane->>ControlPlane: materializeApplicationDefaults
    ControlPlane->>Application: Persist spec.volumes and spec.endpointHosts
    Application->>Definition: materializeEndpoints
    loop Each declared endpoint
        alt Hostname required and missing
            Application-->>Application: Skip endpoint
        else Default available
            Application->>EndpointStore: Get
            alt Endpoint does not exist
                Application->>EndpointStore: CreateEndpoint
            else Endpoint already exists
                Application-->>Application: Leave endpoint unchanged
            end
        end
    end
Loading

File-Level Changes

Change Details Files
扩展应用定义与应用资源模型,声明卷名、入口形态默认值及用户提供的入口主机名,并同步更新 v1alpha1/v1beta1 类型、深拷贝代码和 CRD schema。
  • 新增并校验卷名、入口名称唯一性及 DNS 标签约束。
  • 新增五种入口形态的字段矩阵与端口范围校验。
  • 新增应用入口主机名映射及其声明匹配、形态和 DNS 子域名校验。
api/v1alpha1/types.go
api/v1alpha1/zz_generated.deepcopy.go
api/v1beta1/types.go
api/v1beta1/zz_generated.deepcopy.go
config/crd/kos.tsic.top_applicationdefinitions.yaml
config/crd/kos.tsic.top_applications.yaml
pkg/app/definition.go
pkg/app/endpoints.go
pkg/app/endpoints_test.go
pkg/controlplane/application.go
在应用安装流程中一次性物化包声明的卷集合与级联入口,并通过对象存在性检查保持已安装对象冻结。
  • 单对象创建和计划路径共用应用默认值物化逻辑,将声明卷名追加到应用 spec 且保留用户顺序和已有值。
  • 首次安装时创建带应用归属、入口形态字段和用户主机名的级联 Endpoint;缺少必需主机名时跳过。
  • 已存在的入口不更新,定义变更不会影响既有应用;新安装按当前定义取值。
pkg/controlplane/application.go
pkg/controlplane/plan.go
pkg/controlplane/server.go
pkg/app/controller.go
pkg/app/endpoints.go
pkg/app/store.go
pkg/app/upgrade_flow.go
为应用调和器分配级联入口写入权限,并限制其只能在应用命名空间执行一次性创建。
  • 新增 Endpoint 创建写入接口和存储实现。
  • 准入规则拒绝调和器对级联入口的更新、非创建操作及跨命名空间写入。
  • 补充对应写入准入单元测试。
pkg/app/controller.go
pkg/app/store.go
pkg/app/maintenance_test.go
pkg/write/admit.go
pkg/write/admit_test.go
新增验收覆盖安装物化、定义更新冻结以及缺卷和缺主机名边界。
  • 验证卷名写入应用 spec、级联入口创建、用户主机名应用及安装不创建卷对象。
  • 验证定义更新不改变既有应用,而新安装使用更新后的卷和入口默认值。
  • 验证缺少卷对象导致应用不健康、缺少主机名不创建入口且用户对象不被改写。
tests/acceptance/TC-139/tc139_test.go
tests/acceptance/TC-140/tc140_test.go
tests/acceptance/TC-141/tc141_test.go
tests/acceptance/harness/application.go
README.md

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 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

审查摘要

  • 规模:23 文件 / +1245 −20。手写生产代码约 500 行(pkg/app/endpoints.go 178、pkg/controlplane/application.go +141 与接线),其余是生成物(deepcopy 64、CRD 116)与测试(单测 183、验收 436、harness 25)。按 L3 分组审:核心逻辑逐行,生成物与测试快速扫。
  • 通过维度:正确性与边界 ◑ | 安全 ✓ | 架构 / 写入者分配 ✓ | 规范与提交信息 ✓ | 测试判别力 ✓ | 设计符合性 ✓
  • 其他审查者:本 PR 目前没有 review(reviews: []),没有被忽略的 CHANGES_REQUESTED。

点赞

  1. 默认值走的是既有写入层(Store.CreateEndpoint → SubjectApplicationReconciler),admit 侧只放行 create、Current != nil 即拒改写,C-04 的写者分配没有被绕开,也没有为这条义务新增第二写者。
  2. validateEntryShape 是按 C-43 的字段矩阵逐条建的(http 不带 port/serviceName、http.path 的 path 必填、http.host 的 path 禁止、mdns 的 serviceName 与 port 必填),不是「先收再调和时炸」。
  3. EndpointDefault / ApplicationDefinitionSpec.Volumes 进了 DefinitionDigest 的输入(整份 spec 序列化),包摘要随默认值变化,不会出现「改了默认值但摘要不动」。
  4. 三条验收用例都有可失败的断言:TC-139 断言卷集合顺序与三个入口的形态字段,TC-140 断言定义改写后已安装对象逐字段不变且不新增入口,TC-141 断言缺卷时健康非 Healthy、缺主机名时不产生入口。
  • 提交信息合规:a16c470 feat(app): 安装时物化应用包的卷与入口默认值,subject 无编号、正文写清为什么与可观察变化、无署名 trailer。

C-45 边界判定(不在本 diff 的可锚定范围内,放正文):pkg/endpoint.Actions.DeleteForApplication 在 base 里就没有生产调用方,本改动没有引入它,也没有改卸载路径;但影响面变了——声明的入口对象现在由安装默认产生,卸载只删 status.rendered、应用对象随后被回收,入口留在原命名空间;同名重装时 Get 命中旧实例的入口会被当成「已物化」跳过,新实例沿用旧主机名与旧形态,属主标签指向已删除应用的 UID。base 上的复现路径是「用户手工建一个 managed 入口指向某应用再卸载,入口残留」,所以它是既有缺陷;建议按 C-45 另立 Bug 并附该复现,本单不据此阻塞。行内第 3 条只针对注释把未落地的保证写成既成事实。

测试依据说明:开发评论没有单列 ## 测试依据 表,但测试证据逐条嵌在 ## 设计实现 的 TC-139/140/141 行里,且三条用例的断言能失败(不是空跑),Test Gate 报 177 包通过 —— 按 G5 的意图判定为已具备,不列为 finding。

阻塞项见行内评论(1 条 🔴、2 条 🟡,均已锚定 diff 行)。

Comment thread pkg/app/endpoints.go Resolved
Comment thread pkg/controlplane/application.go Resolved
Comment thread pkg/app/endpoints.go Resolved

@tsic404 tsic404 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

复审摘要(94e6028,delta 9 文件 +365 −43)

  • 规模:整 PR 24 文件 +1575 −28;本轮 delta 里手写代码约 90 行、测试约 240 行。
  • 通过维度:正确性与边界 ✓ | 安全 ✓ | 架构/写入者分配 ✓ | 规范与提交信息 ✓ | 测试判别力 ✓ | 设计符合性 ✓
  • 其他审查者:除我上一轮的 CHANGES_REQUESTED(本 review 取代之)外无他人 review。

上一轮三条的关闭判定

  1. 🔴 名称碰撞 → 代码与测试已关闭,注释残留一处。pkg/app/endpoints.go:84 materializedEntry 分得清四类:spec.targetApp 不等于本应用 → InvalidPackage;owner-uid 存在且不等于本实例 UID → InvalidPackage;本应用自己的入口(targetApp 相符且属主相符)与用户自建入口(无 owner-uid)→ 跳过。:56-70 的 IsAlreadyExists 竞态分支重读对象后调用同一个判定函数(重读失败则直接返回错误,fail-closed)。permanent() 收入 InvalidPackage 后,安装经 recordBaseline → materializeEndpoints → fail 以 ConditionInvalidPackage 终止,NextRetryAt 置空、不耗重试预算。TestMaterializeEndpointsJudgesAnExistingName 的四个子例各打一条分支(前两个 wantErr 在旧实现下会因 continue 而拿到 nil,能失败);TestTC139NameCollisionRefusesTheInstall 断言 PhaseFailed + 条件为 True + 原因含 a-b-web + 先装应用的 targetApp 不变,旧实现下第二个应用会停在 Ready 且无入口,同样能失败。
    残留:endpointName 的注释(:29)仍写「two applications of one namespace, cannot collide」,与 materializedEntry 的文档、单测与 TC-139 碰撞用例直接矛盾,且是上一轮行内意见明确点出要改的一项 → 本轮唯一 finding,见行内。
  2. 🟡 旧键冻结 → 关闭。validateApplicationEndpointHosts(spec, current, definition) 对「在库同值键」直接放行,新键与改值仍走声明/形态/主机名校验;create 传 nil(server.go:506、plan.go:173)、update 传 current.Object(server.go:625、plan.go:215),set/plan 两个分支都在读出 current 之后判定,三条路径不再有冻结。TestValidateApplicationEndpointHostsKeepsStoredKeysAsRecords 的四例里「在库同值通过」在旧实现下会被拒(能失败);TC-140 扩展用定义改名 web→portal 后改 replicas 的 PUT 断言 202,并逐字段核对已安装入口未变、新装应用取新定义。
  3. 🟡 C-45 注释 → 关闭。cascadeEndpoint 现在只陈述前置条件(「The installation only creates the object; its removal follows C-45 and is not performed here」),不再把级联写成既成事实。

permanent() 分类变化:InvalidPackage 的生产者只有定义/摘要/模板/渲染/默认值校验(pkg/app/render.go、definition.go、hooks.go、endpoints.go),全部是对同一份内容的确定性拒绝;permanent() 的另外三个调用点(upgrade_flow.go:104、:473、quiesce.go:125)接的是 applyManifests 的存储/API 错误,不会出现 InvalidPackage,因此既有重试路径的形态没有变。该行为已进 ## 设计实现 新增行(pkg/app/controller.go:1182),C-33 允许「不可重试时进入 Failed」。

设计:## 设计变更 未动,设计 PR design/TSI-4372-ratify head 仍 e3a579e(契约面票有效);本轮的碰撞失败与旧键记账都在 C-32 判据内,不需要新的设计笔。

测试证据:本轮新增的单测与验收断言都能失败(判据见上),CI Build and test pass。竞态分支没有专门用例,但它只重读后调用已覆盖的判定函数且 fail-closed,不另记 finding。

提交信息:amend 后 94e6028 feat(app): 安装时物化应用包的卷与入口默认值 仍合规(无编号、正文含碰撞行为、无 trailer)。

Comment thread pkg/app/endpoints.go Resolved
应用包只承诺卷与入口默认值在安装时物化,却没有可实施的声明形态与落点,
实现者推不出唯一行为。
现在定义声明卷名与入口形态,安装把卷名并入应用卷集合,把入口声明写成
应用调和器持有的级联入口对象;主机名由用户按声明名给出,未给出的入口
默认值不可用,定义更新不再改动已安装对象。
入口名与其它应用或上一实例已有的对象冲突时安装失败并给出原因,不会被
当成已物化跳过。

@tsic404 tsic404 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

APPROVED(74ec777,24 文件 +1577 −28)

  • 规模:手写生产代码约 500 行(pkg/app/endpoints.go 210、pkg/controlplane/application.go +154 与接线),其余为生成物(deepcopy 64、CRD 116)与测试(单测约 320、验收约 520、harness 25)。
  • 通过维度:正确性与边界 ✓ | 安全 ✓ | 架构/写入者分配 ✓ | 规范与提交信息 ✓ | 测试判别力 ✓ | 设计符合性 ✓
  • 其他审查者:无。我自己的两条 CHANGES_REQUESTED 挂在 a16c470 与 94e6028,均由本 review 取代。

终判依据:注释以外与上轮一致

94e6028 的 git 对象在本仓仍可用(SHA 内容寻址,就是我上一轮审过的那棵树),git diff 94e6028 74ec777 的输出只有一处:pkg/app/endpoints.go:27-31 的注释块 +4 −2,没有第二处代码、测试或生成物变化。整 diff 24 文件 +1577 −28,上轮同一基准是 +1575 −28,文件清单逐项相同——与上面那处注释的唯一增量吻合,没有夹带。

上一轮唯一 finding 关闭

endpointName 的注释现在是「The composition is unique within one application, but not across the applications of a namespace; an object that already carries the name is therefore judged by materializedEntry before it counts as materialized (C-32)」,与 :86 的归属判定、TestMaterializeEndpointsJudgesAnExistingName、TC-139 的碰撞用例一致;不再有「two applications … cannot collide」这种错误前提。

点赞

  1. 默认值走既有写入层(Store.CreateEndpoint → SubjectApplicationReconciler,pkg/app/store.go:72-74),admit 只放行 create、Current != nil 即拒(pkg/write/admit.go:176-184),C-04 的写者分配没有被绕开,也没有新增第二写者。
  2. materializedEntry 把「别的应用占用 / 上一实例遗留 / 本应用自己的入口 / 用户自建入口」四类分开,竞态分支重读后走同一判定且 fail-closed,permanent() 收入 InvalidPackage 后安装以 ConditionInvalidPackage 终止而不是耗满重试预算。
  3. validateApplicationEndpointHosts 把在库同值键当记账放行、新写或改值仍严格校验,create 传 nil、update 与 plan 两个分支传 current,定义更新不再冻结应用的可写性。
  4. 测试判别力足:碰撞单测四例各打一条分支、验收用例断言 PhaseFailed + 条件 True + 原因含碰撞名 + 先装应用入口不变;TC-140 扩展在定义改名后断言 update 202 且已安装入口逐字段不变。

提交信息:74ec777 feat(app): 安装时物化应用包的卷与入口默认值 —— subject 无编号、正文含根因与可观察行为(含碰撞失败),无任何署名 trailer。

范围说明:C-45 的级联删除归 TSI-4478,本 PR 只在注释里陈述前置条件,未把未落地的保证写成既成事实。

@tsic404

tsic404 commented Nov 2, 2026

Copy link
Copy Markdown
Owner

随 TSI-4477 的设计重排作废:TSI-4372 已按用户指示关闭,本 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