当前位置: 首页 > 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.cnnetsun.cn/news/1473689.html

相关文章:

  • 从源码到免杀:Go语言版Fscan魔改实战(含常见报错解决方案)
  • 3个技巧轻松掌握HidHide:告别游戏设备冲突的智能解决方案
  • 深入解析STM32中SysTick定时器的配置与应用
  • ClickHouse实时数据处理:打破实时与批量数据的协同处理壁垒
  • Notepad Next:三平台通用的文本编辑神器,让你告别重复配置的烦恼
  • 实测Anything V5生成效果:从文字到精美图片的魔法转换
  • CHORD-X系统AI编程辅助实战:基于Claude Code生成集成代码
  • 第一章 NR系统概述
  • 解锁浏览器桌面通知:Web应用中的实时交互体验优化方案
  • 5个实战技巧:构建3D打印机的智能自适应神经系统
  • 3个革新步骤:BitNet轻量级部署与效率优化全指南
  • Springboot网上课程学习考试系统vue3
  • 数据安全分类分级如何落地
  • Figma全中文工作流解决方案:提升团队协作效率的本地化工具
  • OBS Composite Blur插件终极指南:轻松掌握专业级模糊特效
  • wiliwili多平台部署全流程:跨平台B站客户端安装指南
  • LangChain:构建智能应用的LLM开发框架
  • 从YOLOv8到EdgeFormer:Python量化模型在RK3588上突破120TOPS/W能效比的关键7步——错过本轮更新将无法兼容2025年新固件
  • Docker 拉不到国外镜像
  • 我试了阿里悟空和腾讯QClaw,还是建议你养“正版“龙虾
  • 3步解决ComfyUI-Impact-Pack模块缺失问题:完整安装指南
  • KeyboardChatterBlocker:开源键盘防抖工具解决机械键盘连击问题的技术方案
  • Seamly2D:打破服装设计门槛的终极开源解决方案
  • HunyuanVideo-Foley 音效生成效果展示:卷积神经网络驱动的环境音模拟
  • GLM-4v-9b部署案例:教育机构用4090搭建AI作业批改辅助系统
  • 如何在数字时代构建真正的隐私堡垒:Mull浏览器深度解析
  • 告别手动录入!用GLM-OCR搭建自动化文档解析流水线,效率提升10倍
  • 基于OpenCV的Python轮廓识别系统探索
  • 从照片到游戏场景:用Colmap 3.8重建真实建筑,并在Unity中实现PBR材质与光照适配
  • Keynote转PPT全攻略:Mac用户必知的5个高效技巧(含格式保留秘诀)