-
Notifications
You must be signed in to change notification settings - Fork 0
Route entry add nic support #27
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
📝 WalkthroughWalkthrough本次更改主要集中在腾讯云相关的 Terraform 资源的实现中。对弹性公网 IP(EIP)绑定状态的判断条件进行了扩展,允许更多的绑定状态被视为成功。同时,路由表条目资源的 Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Terraform
participant TencentCloudAPI
User->>Terraform: 配置 route_table_entry (next_hub)
Terraform->>TencentCloudAPI: 查询 next_hub(实例ID或网卡ID+附加ID)
alt next_hub 是网卡+附加ID
TencentCloudAPI->>Terraform: 返回主私有IP
else next_hub 是实例ID
TencentCloudAPI->>Terraform: 返回实例私有IP
end
Terraform->>TencentCloudAPI: 创建路由表条目(使用私有IP)
TencentCloudAPI-->>Terraform: 返回创建结果
Terraform-->>User: 路由表条目创建完成
Poem
Tip ⚡💬 Agentic Chat (Pro Plan, General Availability)
Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 2
🔭 Outside diff range comments (1)
tencentcloud/resource_tc_route_table_entry.go (1)
266-317
:⚠️ Potential issue字段名拼写错误导致编译失败
新增的读取逻辑多次使用了
v.nextBub
字段(276、294、312 行),而此前结构体中应为nextHub
(或其它正确拼写)。若代码中确无nextBub
字段,将直接引发编译错误。请确认并统一字段命名。- filter["private-ip-address"] = v.nextBub + filter["private-ip-address"] = v.nextHub ... - interfaces, errRet = vpcService.DescribeEniByFilters(ctx, &info.vpcId, nil, nil, nil, nil, nil, &v.nextBub, nil) + interfaces, errRet = vpcService.DescribeEniByFilters(ctx, &info.vpcId, nil, nil, nil, nil, nil, &v.nextHub, nil) ... - return resource.NonRetryableError(fmt.Errorf("cannot find exact instance by ip %s in vpc %s", v.nextBub, info.vpcId)) + return resource.NonRetryableError(fmt.Errorf("cannot find exact instance by ip %s in vpc %s", v.nextHub, info.vpcId))
🧹 Nitpick comments (1)
tencentcloud/resource_tc_route_table_entry.go (1)
161-170
:eniUsed
语义不清易读性一般
strings.Cut
返回的第三个布尔值含义是“是否切割成功”,这里代表 存在 “+” 即 ENI 场景。用eniUsed
容易让人误解为 “是否使用 ENI”,但其实际含义恰好相反 ——false
表示实例 ID。建议改名为isEni
或hasAttachment
, 并在后续分支中正向使用,可提升可读性与后期维护。- eniId, _, eniUsed := strings.Cut(nextHub, "+") + eniId, _, isEni := strings.Cut(nextHub, "+") ... - if !eniUsed { + if !isEni {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
tencentcloud/resource_tc_eip_association.go
(1 hunks)tencentcloud/resource_tc_route_table_entry.go
(4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
tencentcloud/resource_tc_eip_association.go (1)
tencentcloud/extension_vpc.go (2)
EIP_STATUS_BIND_ENI
(45-45)EIP_STATUS_BIND
(41-41)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: docs
- GitHub Check: golangci-lint
- GitHub Check: tfprovider-lint
- GitHub Check: unit-tests
if len(instances) == 1 { | ||
nextHub = *(instances[0].PrivateIpAddresses[0]) // 此处为实例主网卡的第一个ip,当前cdk主网卡只有一个内网ip | ||
} else if len(interfaces) == 1 { | ||
for _, ip := range interfaces[0].PrivateIpAddressSet { | ||
if ip.Primary != nil && *ip.Primary && ip.PrivateIpAddress != nil { | ||
nextHub = *ip.PrivateIpAddress | ||
interfaces = nil | ||
break | ||
} | ||
} | ||
if interfaces != nil { | ||
return fmt.Errorf("cannot find primary ip address of interface %s", nextHub) | ||
} | ||
} else { | ||
return fmt.Errorf("cannot find exact instance by id %s", nextHub) | ||
} |
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.
🛠️ Refactor suggestion
通过将 interfaces
置为 nil
标记逻辑不直观
在找到主 IP 后通过 interfaces = nil
来区分是否命中,随后再用 interfaces != nil
判断会产生“写 ‑ 判”耦合,阅读成本高,也容易在后续修改时踩坑。建议改为显式布尔标志:
- for _, ip := range interfaces[0].PrivateIpAddressSet {
- if ip.Primary != nil && *ip.Primary && ip.PrivateIpAddress != nil {
- nextHub = *ip.PrivateIpAddress
- interfaces = nil
- break
- }
- }
- if interfaces != nil {
+ foundPrimary := false
+ for _, ip := range interfaces[0].PrivateIpAddressSet {
+ if ip.Primary != nil && *ip.Primary && ip.PrivateIpAddress != nil {
+ nextHub = *ip.PrivateIpAddress
+ foundPrimary = true
+ break
+ }
+ }
+ if !foundPrimary {
这样既直观又避免对同一变量承担两种含义。
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
if len(instances) == 1 { | |
nextHub = *(instances[0].PrivateIpAddresses[0]) // 此处为实例主网卡的第一个ip,当前cdk主网卡只有一个内网ip | |
} else if len(interfaces) == 1 { | |
for _, ip := range interfaces[0].PrivateIpAddressSet { | |
if ip.Primary != nil && *ip.Primary && ip.PrivateIpAddress != nil { | |
nextHub = *ip.PrivateIpAddress | |
interfaces = nil | |
break | |
} | |
} | |
if interfaces != nil { | |
return fmt.Errorf("cannot find primary ip address of interface %s", nextHub) | |
} | |
} else { | |
return fmt.Errorf("cannot find exact instance by id %s", nextHub) | |
} | |
if len(instances) == 1 { | |
nextHub = *(instances[0].PrivateIpAddresses[0]) // 此处为实例主网卡的第一个ip,当前cdk主网卡只有一个内网ip | |
} else if len(interfaces) == 1 { | |
- for _, ip := range interfaces[0].PrivateIpAddressSet { | |
- if ip.Primary != nil && *ip.Primary && ip.PrivateIpAddress != nil { | |
- nextHub = *ip.PrivateIpAddress | |
- interfaces = nil | |
- break | |
- } | |
- } | |
- if interfaces != nil { | |
- return fmt.Errorf("cannot find primary ip address of interface %s", nextHub) | |
- } | |
+ foundPrimary := false | |
+ for _, ip := range interfaces[0].PrivateIpAddressSet { | |
+ if ip.Primary != nil && *ip.Primary && ip.PrivateIpAddress != nil { | |
+ nextHub = *ip.PrivateIpAddress | |
+ foundPrimary = true | |
+ break | |
+ } | |
+ } | |
+ if !foundPrimary { | |
+ return fmt.Errorf("cannot find primary ip address of interface %s", nextHub) | |
+ } | |
} else { | |
return fmt.Errorf("cannot find exact instance by id %s", nextHub) | |
} |
Summary by CodeRabbit
next_hub
字段现支持填写实例ID或网卡挂载ID,自动解析并关联到对应的主私有IP。