当前位置: 首页 > news >正文

83. 由机器池排序引起的非预期的 terraform 配置漂移

Environment 环境

Terraform provisioned RKE2 downstream cluster.
Terraform 配置了 RKE2 下游集群。

Situation 地理位置

When adding a new machine pool to an existing Rancher2 RKE2 cluster, Terraform may plan to modify existing machine pools that were provisioned in previous runs, causing unintended updates to control plane and worker nodes.
在向现有的 Rancher2 RKE2 集群添加新机器池时,Terraform 可能会计划修改之前运行中已配置的机器池,导致控制平面和工作节点出现意外更新。

Resolution 结局

Stable ordering of keys is the simplest and most reliable workaround until a provider-level fix is available.
稳定排序密钥是最简单、最可靠的变通方法,直到提供者层面的修复方案出现。

  • Use ordered keys (prefix keys with numbers) in the map so that lexicographical sorting produces a stable list order. Example:
    在映射中使用有序键(带数字的前缀键),以便字典序排序产生稳定的列表顺序。示例:

<span style="color:#000000"><span style="background-color:#ffffff"><span style="background-color:#efefef"><code>1-control: name: control control_plane_role: true quantity: 3 2-worker: name: worker worker_role: true quantity: 2 3-NEW-POOL: name: NEW-POOL worker_role: true quantity: 1</code></span></span></span>
  • When adding pools: 添加池时:

    • Add the new entry with a key that maintains the intended final alphabetical order (using numeric prefixes as above). Test in a non-production environment before applying to production clusters.
      添加一个保持最终字母顺序的键(使用数字前缀,如上所述)。在应用到生产集群之前,先在非生产环境中测试。

Cause 病因

Terraform maps are unordered collections. When the Rancher provider converts a map into the provider's TypeList, keys are sorted lexicographically. Machine pools are matched by position (index) inside that list — not by name. Adding a new pool changes the alphabetical order, which shifts indexes. Terraform then incorrectly associates existing list positions with different pool configurations and plans in-place updates to the wrong pools.
Terraform 地图是无序集合。当牧场提供者将映射转换为提供者的类型列表时,键按字典序排序。机器池是根据列表中的位置(索引)匹配的,而不是按名称。添加新池会改变字母顺序,从而改变索引。Terraform 随后错误地将现有列表位置与不同的池配置关联,并计划将原地更新到错误的池中。

Impact 影响

  • Unexpected in-place modifications of existing pools.
    对现有泳池进行意外的原地修改。

  • Potential disruption of node roles (control/etcd/worker) and pod scheduling.
    可能扰乱节点角色(控制/etcd/工作者)和舱体调度。

Illustrative Example 示例

Assume a scenario where existing cluster has two machine pools: control and worker.
假设现有集群有两个机器池:控制池和工人池。

Initial Terraform run 最初的 Terraform 运行

<span style="color:#000000"><span style="background-color:#ffffff"><span style="background-color:#efefef"><code>Map input (unordered): control -> control_plane: true, quantity: 3 worker -> worker_role: true, quantity: 2 Lexicographical sort creates ordered list: [0] control -> creates control pool [1] worker -> creates worker pool</code></span></span></span>

Adding new pool NEW-POOL
新增泳池 NEW-POOL

<span style="color:#000000"><span style="background-color:#ffffff"><span style="background-color:#efefef"><code>Map input (unordered): control -> control_plane: true, quantity: 3 worker -> worker_role: true, quantity: 2 NEW-POOL -> worker_role: true, quantity: 1 Lexicographical sort creates new ordered list: [0] NEW-POOL -> (index 0 already exists) [1] control -> (index 1 already exists) [2] worker -> new</code></span></span></span>

Result (incorrect): 结果(错误):

  • Terraform sees index mismatches and plans to:
    Terraform 发现指数不匹配,计划:

    • Modify existing pool at index 0 (previously control) to NEW-POOL configuration.
      将索引为 0 的现有池(之前为控制)修改为 NEW-POOL 配置。

    • Modify existing pool at index 1 (previously worker) to control configuration.
      修改索引 1 的现有池(之前是 worker)以控制配置。

    • Create a new worker pool at index 2.
      在指数2创建一个新的劳动力池。

Expected: Create one new NEW-POOL pool without modifying control or worker.
预期:创建一个新的 NEW-POOL 池,但不修改控制权或工人。

Example Terraform plan snippet (illustrative)
Terraform 平面图示例(示例)

<span style="color:#000000"><span style="background-color:#ffffff"><span style="background-color:#efefef"><code># rancher2_cluster_v2.cluster_rke2 will be updated in-place ~ resource "rancher2_cluster_v2" "cluster_rke2" { ~ rke_config { # Index [0]: Existing "control" pool → incorrectly changed to "NEW-POOL" ~ machine_pools { ~ name = "control" -> "NEW-POOL" ~ control_plane_role = true -> false ~ etcd_role = true -> false ~ worker_role = false -> true ~ quantity = 3 -> 1 ~ machine_labels = { ~ "nodepool" = "control" -> "worker" } } # Index [1]: Existing "worker" pool → incorrectly changed to "control" ~ machine_pools { ~ name = "worker" -> "control" ~ control_plane_role = false -> true ~ etcd_role = false -> true ~ worker_role = true -> false ~ quantity = 2 -> 3 ~ machine_labels = { ~ "nodepool" = "worker" -> "control" } } # Index [2]: New pool created as "worker" (expected "NEW-POOL") + machine_pools { + name = "worker" + control_plane_role = false + worker_role = true + quantity = 2 } } } Plan: 0 to add, 1 to change, 0 to destroy.</code></span></span></span>
Additional Information 附加信息

Please note that this behaviour is not considered a defect in the provider but rather an edge case resulting from ordering inconsistencies that lead to configuration drift. An enhancement request has been submitted at the provider level to better handle such scenarios, and the improvement is expected to be incorporated in a future release.
请注意,这种行为不被视为提供者的缺陷,而是由于排序不一致导致配置漂移的边缘情况。已在提供者层面提交了增强请求以更好地处理此类情景,预计改进将在未来版本中纳入。

访问Rancher-K8S解决方案博主,企业合作伙伴 :
https://blog.csdn.net/lidw2009

http://www.jsqmd.com/news/533863/

相关文章:

  • godot GridContainer 学习笔记
  • DeepSeek-OCR-2作品展示:多语言混合文档识别效果实测
  • 2026重庆留学机构排名,想去加拿大读高中机构哪家性价比高 - 工业品网
  • 从ControlStrip进程到NVRAM重置:一次搞懂Mac Touch Bar控件管理的底层逻辑
  • LFM2.5-1.2B-Thinking-GGUF镜像免配置:内置模型+运行时+UI,真正零依赖开箱即用
  • 达梦数据库迁移到mysql
  • 行马APP正规靠谱走路赚钱让运动收益方式轻松实现 - 博客万
  • [技术指南] 解决Cython编译错误:从版本冲突到环境配置的完整方案
  • 陕西设备回收哪家靠谱?2026 实力榜单|电缆/变压器/电力/通讯/钨钢回收首选这家 - 深度智识库
  • 2026年内架钢管架租赁有哪些选择?五类常见服务商定位与适配场景解析 - 速递信息
  • 终极指南:3个简单技巧让你的终端颜值翻倍,告别混乱命令提示
  • OpenRocket火箭仿真软件:从零到精通的专业级火箭设计指南 [特殊字符]
  • NeverSink的POE2物品过滤器:从视觉混乱到战利品清晰度的艺术
  • 2026年选型参考,统一数据管理平台公司及靠谱平台推荐 - 品牌2026
  • 漏洞扫描系统毕业设计:基于任务队列与异步调度的效率优化实践
  • 一文看懂推荐系统:特征交叉02:从FM到DeepFM,看高阶特征交叉的演进之路
  • 从像素到概念:如何用Python+OpenCV一步步提取图像的底层和高层特征
  • 告别传统验证码!手把手教你为若依(RuoYi)系统换上AJ-Captcha滑块验证码(Spring Boot 2.x + Vue 3)
  • 告别手动转录烦恼:BiliBiliCCSubtitle智能工具让视频字幕高效提取成为现实
  • 零基础入门《Natural Language Processing with PyTorch》中文翻译项目手把手教程
  • Step3-VL-10B-Base模型量化实战:GPU资源优化指南
  • 2026雅思备考必看:新手必备app哪个好用?亲测有效 - 品牌2025
  • 暴涨后急跌!昆仑万维利好落地变利空?资金博弈真相全解析
  • postgresql QueryWrapper left join
  • 2026年主数据厂商与数据拉通公司,优质服务实力推荐汇总 - 品牌2026
  • nli-distilroberta-base惊艳效果:中英文混合句子对推理准确率超89.2%
  • 批量分别压缩工具:支持随机密码、并行压缩和排除规则的批量打包方案
  • 【实战】Python+Bluez BLE广播开发:从零构建可被发现的自定义设备
  • Unity游戏毕业设计论文实战指南:从原型开发到技术文档撰写
  • 如何用TileLang实现高性能GPU算子:从入门到精通的完整指南