-
Notifications
You must be signed in to change notification settings - Fork 902
feat(ingress/annotation): support external service in the mirror annotations #2679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
支持在镜像注解中使用外部服务FQDN变更概述
变更文件
时序图sequenceDiagram
participant A as Annotations
participant M as Mirror Parser
participant C as Ingress Config
participant R as HTTP Route
A->>M: Parse annotations
alt FQDN exists
M->>M: Parse FQDN and port
M->>C: Set MirrorConfig with FQDN
else Service exists
M->>M: Parse service info
M->>C: Set MirrorConfig with service
end
C->>M: ApplyRoute
alt FQDN configured
M->>R: Set mirror destination with FQDN
else Service configured
M->>R: Set mirror destination with service FQDN
end
💡 小贴士与 lingma-agents 交流的方式📜 直接回复评论
📜 在代码行处标记
📜 在讨论中提问
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔎 代码评审报告
🎯 评审意见概览
| 严重度 | 数量 | 说明 |
|---|---|---|
| 🔴 Blocker | 0 | 阻断性问题,需立即修复。例如:系统崩溃、关键功能不可用或严重安全漏洞。 |
| 🟠 Critical | 1 | 严重问题,高优先级修复。例如:核心功能异常或性能瓶颈影响用户体验。 |
| 🟡 Major | 1 | 主要问题,建议修复。例如:非核心功能缺陷或代码维护性较差。 |
| 🟢 Minor | 1 | 次要问题,酬情优化。例如:代码格式不规范或注释缺失。 |
总计: 3 个问题
📋 评审意见详情
💡 代码实现建议
以下是文件级别的代码建议,聚焦于代码的可读性、可维护性和潜在问题。
🔹 pkg/ingress/kube/annotations/mirror.go (2 💬)
- 应该在解析到FQDN时就返回,避免继续解析mirrorTargetService (L51-L66)
- 变量命名拼写错误,应为fqdn而不是fadn (L51)
🔹 pkg/ingress/kube/annotations/mirror_test.go (1 💬)
- 测试用例中使用了错误的注解键 (L47)
🚀 架构设计建议
以下是对代码架构和设计的综合分析,聚焦于跨文件交互、系统一致性和潜在优化空间。
🔍1. FQDN解析逻辑与服务发现逻辑存在重复代码风险
在mirror.go中,FQDN和Service的解析逻辑分别独立实现,但两者在构建MirrorConfig时结构相似。建议将共用逻辑抽象为统一的解析函数,以减少重复代码并提升可维护性。
📌 关键代码
if fadn, err := annotations.ParseStringASAP(mirrorTargetFQDN); err == nil {
// default is 80
var port uint32
port = 80
if p, err := annotations.ParseInt32ASAP(mirrorTargetFQDNPort); err == nil {
port = uint32(p)
}
config.Mirror = &MirrorConfig{
Percentage: parsePercentage(annotations),
FQDN: fadn,
FPort: port,
}
return nil
}config.Mirror = &MirrorConfig{
ServiceInfo: serviceInfo,
Percentage: parsePercentage(annotations),
}未来如果需要修改MirrorConfig的构造方式,可能需要同时修改两处逻辑,增加维护成本和出错风险。
🔍2. MirrorConfig结构体设计可能导致扩展性问题
当前MirrorConfig结构体中同时包含ServiceInfo和FQDN相关字段,这种混合使用方式可能会导致结构体职责不清。建议将FQDN相关的配置单独封装成一个子结构体,以提高结构体的清晰度和可扩展性。
📌 关键代码
type MirrorConfig struct {
util.ServiceInfo
Percentage *wrappers.DoubleValue
FQDN string
FPort uint32 // Port for FQDN
}随着功能的扩展,MirrorConfig可能会变得越来越复杂,难以维护和理解。
🔍3. 测试用例未覆盖FQDN和Service同时配置的情况
当前测试用例只单独测试了FQDN或Service的配置情况,没有测试当两者同时配置时的行为是否符合预期。这可能导致在实际使用中出现不可预知的问题。
📌 关键代码
{
input: []map[string]string{
{buildHigressAnnotationKey(mirrorTargetFQDN): "www.example.com"},
{buildNginxAnnotationKey(mirrorTargetFQDN): "www.example.com"},
},
expect: &MirrorConfig{
ServiceInfo: util.ServiceInfo{},
FQDN: "www.example.com",
FPort: 80,
},
},在生产环境中,用户可能会同时配置FQDN和服务名称,若系统行为不符合预期,可能会导致流量镜像失败或错误地路由到不正确的服务。
🔍4. FQDN端口默认值硬编码可能引发安全或兼容性问题
在FQDN解析逻辑中,默认端口被硬编码为80。虽然这是一个常见的HTTP端口,但在某些场景下(如HTTPS服务),默认端口应为443。建议通过配置或注解支持默认端口的自定义,以增强灵活性和安全性。
📌 关键代码
// default is 80
var port uint32
port = 80如果目标服务运行在非80端口上,而用户未显式指定端口,则流量可能无法正确到达目标,导致服务不可用或数据泄露。
审查详情
📒 文件清单 (2 个文件)
📝 变更: 2 个文件
📝 变更文件:
pkg/ingress/kube/annotations/mirror.gopkg/ingress/kube/annotations/mirror_test.go
💡 小贴士
与 lingma-agents 交流的方式
📜 直接回复评论
直接回复本条评论,lingma-agents 将自动处理您的请求。例如:
-
在当前代码中添加详细的注释说明。
-
请详细介绍一下你说的 LRU 改造方案,并使用伪代码加以说明。
📜 在代码行处标记
在文件的特定位置创建评论并 @lingma-agents。例如:
-
@lingma-agents 分析这个方法的性能瓶颈并提供优化建议。
-
@lingma-agents 对这个方法生成优化代码。
📜 在讨论中提问
在任何讨论中 @lingma-agents 来获取帮助。例如:
-
@lingma-agents 请总结上述讨论并提出解决方案。
-
@lingma-agents 请根据讨论内容生成优化代码。
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2679 +/- ##
===========================================
+ Coverage 35.91% 46.16% +10.25%
===========================================
Files 69 81 +12
Lines 11576 13047 +1471
===========================================
+ Hits 4157 6023 +1866
+ Misses 7104 6678 -426
- Partials 315 346 +31
🚀 New features to boost your workflow:
|
johnlanni
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Ⅰ. Describe what this PR did
fix #2626
Support external FQDN in mirror annotation and add test.
Ⅱ. Does this pull request fix one issue?
Ⅲ. Why don't you add test cases (unit test/integration test)?
Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews