-
Notifications
You must be signed in to change notification settings - Fork 0
添加候选机型规格列表支持 #8
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
添加候选机型规格列表支持 #8
Conversation
📝 Walkthrough📝 Walkthrough此次变更在腾讯云CVM构建器中引入了实例类型候选列表,替代原有单一实例类型字段。相关配置结构体、实例创建逻辑及验证流程均做了相应调整,支持按优先级顺序尝试多个实例类型。同时,子网和可用区查询逻辑也进行了优化,文档和测试代码同步更新。 Changes
Sequence Diagram(s)sequenceDiagram
participant Builder
participant StepRunInstance
participant TencentCloudAPI
Builder->>StepRunInstance: 传递InstanceTypeCandidates列表
StepRunInstance->>TencentCloudAPI: 依次尝试每个实例类型+每个子网创建实例
alt 创建成功
TencentCloudAPI-->>StepRunInstance: 返回实例ID
StepRunInstance-->>Builder: 返回成功结果
else 创建失败
TencentCloudAPI-->>StepRunInstance: 返回错误及可能的实例ID
StepRunInstance->>TencentCloudAPI: 尝试终止已创建实例
StepRunInstance-->>Builder: 返回错误
end
Poem
Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
🧰 Additional context used🪛 GitHub Actions: Go Test Linuxbuilder/tencentcloud/cvm/step_config_subnet.go[error] 9-9: Go compiler error: imported and not used: "strings" ⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
🔇 Additional comments (3)
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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)
builder/tencentcloud/cvm/step_config_subnet.go (1)
73-90: 可用区顺序不确定可能导致不一致的行为从 map 遍历得到的
zones切片顺序是不确定的,取"最后5个"可能在不同运行时得到不同结果。建议对可用区进行排序以确保一致性。var zones []string for zone := range zonesSet { zones = append(zones, zone) } + // 对可用区进行排序以确保一致性 + sort.Strings(zones) // 如果指定了子网ID或子网名称,则尝试使用已有子网记得在文件顶部导入
sort包。
🧹 Nitpick comments (3)
builder/tencentcloud/cvm/step_config_subnet.go (1)
56-56: 改进日志消息的清晰度当前的日志消息过于简短,建议提供更多上下文信息。
- Say(state, fmt.Sprintf("length:%d", len(resp.Response.InstanceTypeQuotaSet)), "") + Say(state, fmt.Sprintf("找到 %d 个可用区", len(resp.Response.InstanceTypeQuotaSet)), "")builder/tencentcloud/cvm/step_run_instance.go (2)
193-193: 修正注释中的错别字- // instanceId不存在代表之前开机不成功,此处不需要再次删除。若是LAUNCH_FAILED会预到Code=InvalidInstanceId.NotFound,跳过尝试下一个subnet继续尝试开机即可 + // instanceId不存在代表之前开机不成功,此处不需要再次删除。若是LAUNCH_FAILED会遇到Code=InvalidInstanceId.NotFound,跳过尝试下一个subnet继续尝试开机即可
197-202: 简化实例ID列表的构建使用
strings.Join可以更简洁地构建实例ID列表,并避免末尾多余的逗号。- var builder strings.Builder - for _, instanceId := range instanceIds { - builder.WriteString(*instanceId) - builder.WriteString(",") - } - return Halt(state, terminateErr, fmt.Sprintf("Failed to terminate instance %s may need to delete it manually", builder.String())) + instanceIdStrs := make([]string, len(instanceIds)) + for i, instanceId := range instanceIds { + instanceIdStrs[i] = *instanceId + } + return Halt(state, terminateErr, fmt.Sprintf("Failed to terminate instance %s may need to delete it manually", strings.Join(instanceIdStrs, ",")))
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
builder/tencentcloud/cvm/builder.go(1 hunks)builder/tencentcloud/cvm/run_config.go(3 hunks)builder/tencentcloud/cvm/step_config_subnet.go(1 hunks)builder/tencentcloud/cvm/step_run_instance.go(4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
builder/tencentcloud/cvm/step_config_subnet.go (1)
builder/tencentcloud/cvm/common.go (3)
Say(238-249)Retry(199-222)Halt(272-277)
builder/tencentcloud/cvm/step_run_instance.go (1)
builder/tencentcloud/cvm/common.go (2)
Retry(199-222)Halt(272-277)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Lint check
🔇 Additional comments (1)
builder/tencentcloud/cvm/builder.go (1)
126-126: 确认:多候选机型规格支持已正确实现以下关键位置已验证:
- builder/tencentcloud/cvm/run_config.go
instanceTypeCandidates []string字段定义、互斥校验与归一化逻辑已生效- builder/tencentcloud/cvm/step_run_instance.go
stepRunInstance结构体包含InstanceTypeCandidates []stringRun()方法第172行开始已按顺序遍历InstanceTypeCandidates并设置req.InstanceType- builder/tencentcloud/cvm/builder.go
- 已将
b.config.instanceTypeCandidates传递给stepRunInstance.InstanceTypeCandidates变更与“添加候选机型规格列表支持”目标完全一致,且相关配置、结构体与运行逻辑均已正确更新,无需额外修改。
93b9268 to
b4cabe9
Compare
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: 0
🔭 Outside diff range comments (3)
builder/tencentcloud/cvm/run_config_test.go (2)
33-36: 修复过时的测试逻辑此测试期望在
InstanceType为空时出现错误,但由于测试配置现在设置了InstanceTypeCandidates,根据新的验证逻辑(要求InstanceType或InstanceTypeCandidates中恰好设置一个),此测试应该通过而不是失败。应用此差异来修复测试逻辑:
- cf.InstanceType = "" - if err := cf.Prepare(nil); err == nil { - t.Fatal("should have err") - } + cf.InstanceType = "" + cf.InstanceTypeCandidates = nil + if err := cf.Prepare(nil); err == nil { + t.Fatal("should have err") + }
38-42: 确保测试覆盖新的验证逻辑此测试设置了
InstanceType,但没有清除InstanceTypeCandidates。根据新的验证逻辑,这应该会导致错误,因为两个字段都被设置了。请考虑添加测试用例来验证互斥性。建议添加以下测试用例:
+ // Test that both InstanceType and InstanceTypeCandidates cannot be set + cf.InstanceType = "S3.SMALL2" + cf.InstanceTypeCandidates = []string{"S3.SMALL2"} + if err := cf.Prepare(nil); err == nil { + t.Fatal("should have err when both instance_type and instance_type_candidates are set") + }builder/tencentcloud/cvm/builder.hcl2spec.go (1)
132-241: HCL2Spec方法中缺少instance_type_candidates字段定义
FlatConfig结构体中添加了InstanceTypeCandidates字段,但HCL2Spec方法中缺少相应的规范定义。这会导致HCL配置无法识别instance_type_candidates字段。在HCL2Spec方法中添加缺失的字段定义:
"instance_charge_type": &hcldec.AttrSpec{Name: "instance_charge_type", Type: cty.String, Required: false}, + "instance_type_candidates": &hcldec.AttrSpec{Name: "instance_type_candidates", Type: cty.List(cty.String), Required: false}, "instance_type": &hcldec.AttrSpec{Name: "instance_type", Type: cty.String, Required: false},
🧹 Nitpick comments (1)
builder/tencentcloud/cvm/step_check_source_image.go (1)
65-65: 错误消息简化符合新的候选机型支持逻辑将错误消息简化为"No image found"是合理的,因为现在系统支持多个候选机型规格,不再按单一实例类型过滤镜像。这个改动与PR目标保持一致。
不过建议考虑在错误消息中提供更多上下文信息,帮助用户调试:
-return Halt(state, fmt.Errorf("No image found"), "") +return Halt(state, fmt.Errorf("No image found matching the specified criteria"), "")
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
builder/tencentcloud/cvm/builder.go(1 hunks)builder/tencentcloud/cvm/builder.hcl2spec.go(1 hunks)builder/tencentcloud/cvm/run_config.go(3 hunks)builder/tencentcloud/cvm/run_config_test.go(1 hunks)builder/tencentcloud/cvm/step_check_source_image.go(1 hunks)builder/tencentcloud/cvm/step_config_subnet.go(2 hunks)builder/tencentcloud/cvm/step_run_instance.go(4 hunks)docs-partials/builder/tencentcloud/cvm/TencentCloudRunConfig-not-required.mdx(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- docs-partials/builder/tencentcloud/cvm/TencentCloudRunConfig-not-required.mdx
🚧 Files skipped from review as they are similar to previous changes (4)
- builder/tencentcloud/cvm/builder.go
- builder/tencentcloud/cvm/step_run_instance.go
- builder/tencentcloud/cvm/step_config_subnet.go
- builder/tencentcloud/cvm/run_config.go
🧰 Additional context used
🧬 Code Graph Analysis (1)
builder/tencentcloud/cvm/step_check_source_image.go (1)
builder/tencentcloud/cvm/common.go (1)
Halt(272-277)
🪛 GitHub Actions: Go Test Linux
builder/tencentcloud/cvm/run_config_test.go
[error] 35-35: Test failure in TestTencentCloudRunConfig_Prepare: expected an error but did not receive one.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Lint check
🔇 Additional comments (2)
builder/tencentcloud/cvm/run_config_test.go (1)
17-17: 更新测试配置以使用新的候选机型列表字段配置更新正确地反映了新的设计,使用
InstanceTypeCandidates字段而不是单个InstanceType。builder/tencentcloud/cvm/builder.hcl2spec.go (1)
42-43: 正确添加了候选机型字段并调整了实例类型字段的要求结构体更新正确地反映了新设计:
- 添加了
InstanceTypeCandidates字段作为可选的字符串切片- 将
InstanceType字段从必需改为可选
3ed853a to
91d3e92
Compare
2e7c645 to
ce0821e
Compare
Summary by CodeRabbit
新功能
instance_type_candidates,允许用户传入多个实例类型候选列表。修复与优化