k8s CRD 有无 finalizer 的删除流程是不同的

33 阅读1分钟

好问题!你发现了关键点。 看日志:

  I1208 13:24:25.492714  pod.go:1195] delete ip CR pod3-178740344.vip-7842
  I1208 13:24:25.494865  ip.go:280] deleting ip pod3-178740344.vip-7842    ← handleDelIP
  I1208 13:24:25.494869  subnet.go:569] release v4 10.241.51.7 ... add ip to released list

关键发现:

  • 只有 ip.go:280 的日志(handleDelIP)
  • 没有 ip.go:236 的日志(handleUpdateIP 中的 "handle deleting ip")
  • 没有 ip.go:269 的日志("ip cr xxx release ipam pod key")

这说明什么? handleUpdateIP 根本没有被调用! 为什么 handleUpdateIP 没被调用?

因为 xx IP CR 有|没有 finalizer,Kubernetes 的删除行为不同: 没有 finalizer 的资源:

  1. 调用 Delete() → 直接从 etcd 删除
  2. 只触发 DELETE 事件
  3. 只调用 handleDelIP

有 finalizer 的资源:

  1. 调用 Delete() → 设置 DeletionTimestamp
  2. 触发 UPDATE 事件(带 DeletionTimestamp)
  3. 调用 handleUpdateIP 清理资源
  4. 移除 finalizer
  5. 触发 DELETE 事件
  6. 调用 handleDelIP