smartxworks / cluster-api-provider-elf-static-ip

0 stars 2 forks source link

SKS-2393: Check if the IP from IPPool is already in use #38

Open haijianyang opened 3 months ago

haijianyang commented 3 months ago

Issue

如果 IPPool 中有些 IP 已经被非 ElfMachine 使用了,IP 分配到 ElfMachine 后,创建虚拟机会导致 IP 冲突,且需要花一定的时间排查。

Change

目前从 IPPool 过滤被非 ElfMachine 使用的 IP 实现难道较大。 简单起见,从 IPPool 获取到 IP 后,先 ping 一下 IP 是否已经被使用,如果还没有被使用继续正常的创建流程。如果 IP 已经被使用,给 ElfMachine 设置 WaitingForStaticIPAllocationReason 和相关的错误信息。用户发现该错误后,可以处理已经被使用的 IP,之后 ElfMachine 的创建流程会继续正常进行。

workflow 运行 make test 报错 listen ip4:icmp : socket: operation not permitted,因此改成 sudo -E sh -c 'make test',

Test

  1. 在 IPPool 中配置已经被使用的 IP
  2. 使用该 IPPool 创建集群,观察到 elfMachine 会被设置 WaitingForStaticIPAllocationReason
  3. 释放 IPPool 中已经被使用的 IP,观察到 elfMachine 的创建流程会继续正常进行
codecov[bot] commented 3 months ago

Codecov Report

Attention: Patch coverage is 68.96552% with 9 lines in your changes are missing coverage. Please review.

Project coverage is 68.45%. Comparing base (d5d7b1d) to head (4b1a0fb).

Files Patch % Lines
pkg/util/network.go 66.66% 4 Missing and 2 partials :warning:
controllers/elfmachine_controller.go 72.72% 1 Missing and 2 partials :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #38 +/- ## ========================================== + Coverage 68.40% 68.45% +0.04% ========================================== Files 2 3 +1 Lines 307 336 +29 ========================================== + Hits 210 230 +20 - Misses 81 86 +5 - Partials 16 20 +4 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.