cilium PR 自检

25 阅读2分钟

Cilium PR 自测检查清单

参考文档: docs.cilium.io/en/stable/c…


1. 代码编译验证

确保每个 commit 可以独立编译:

cd /root/f/cilium

# 编译 cilium-agent
make build

# 或者仅验证代码编译
go build ./...

2. 单元测试

2.1 运行特定包的单元测试

# 测试 endpoint 包
make test PKG=./pkg/endpoint/...

# 测试 k8s watchers 包
make test PKG=./pkg/k8s/watchers/...

# 测试 annotation 包
make test PKG=./pkg/annotation/...

2.2 运行完整单元测试(耗时较长)

make test

2.3 运行单个测试函数

# 运行特定测试
go test -v -run TestApplySourceIPVerificationFromAnnotation ./pkg/endpoint/...

3. Lint 检查

3.1 完整 Lint 检查

make lint

3.2 快速 Go Lint

# 仅运行 golangci-lint
golangci-lint run ./pkg/endpoint/... ./pkg/k8s/watchers/... ./pkg/annotation/...

4. Postcheck(CLI 变更时需要)

如果修改了 CLI 参数,需要更新命令参考文档:

make postcheck
git add Documentation/cmdref
git commit --amend

5. Go Module 检查

如果修改了依赖:

go mod tidy && go mod vendor
git diff --exit-code go.mod go.sum vendor/

6. Image 构建验证(可选)

# 构建 cilium-agent 镜像
make docker-cilium-image

# 或使用 Makefile.docker
make -f Makefile.docker cilium-agent

7. E2E 测试(可选,CI 会运行)

# 本地 Kind 集群测试
make kind
make kind-install-cilium
make connectivity-test

8. 本 PR 特定的测试命令

针对 PR #43505 (DisableSourceIPVerification annotation):

# Step 1: 编译验证
go build ./pkg/endpoint/... ./pkg/k8s/watchers/... ./pkg/annotation/...

# Step 2: 单元测试
go test -v -run TestApplySourceIPVerificationFromAnnotation ./pkg/endpoint/...
go test -v ./pkg/endpoint/... -count=1
go test -v ./pkg/k8s/watchers/... -count=1

# Step 3: Lint
make lint

# Step 4: 完整包测试
make test PKG=./pkg/endpoint/...

9. 自测检查清单

提交 PR 前确认:

  • go build ./... 编译通过
  • make test PKG=<changed-packages> 测试通过
  • make lint 无新增警告
  • 新增代码有对应的单元测试
  • Commit 包含 Signed-off-by: 签名
  • Commit message 格式正确(<scope>: <description>
  • 如有 CLI 变更,已运行 make postcheck

10. 常见问题排查

Lint 失败

# 查看详细错误
golangci-lint run --verbose ./...

# 自动修复部分问题
gofmt -w ./pkg/endpoint/
goimports -w ./pkg/endpoint/

测试超时

# 增加超时时间
go test -timeout 10m ./pkg/endpoint/...

依赖问题

go mod tidy
go mod vendor
go mod verify