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

0 stars 2 forks source link

[WIP]SKS-1825: Use the default IPPool as the global IPPool #37

Closed haijianyang closed 3 months ago

haijianyang commented 3 months ago

Issue

CAPE 增加了网卡级别的网络配置后:按照 CAPI IPAM 社区现在的规范,IPAM 需要提供两种作用域的 IPPool:

  1. 一种需要指定 namespace,只能给同样命名空间的 ElfMachine 使用。
    
    type NetworkDeviceSpec struct {
    IPAddrs []string `json:"ipAddrs,omitempty"`
    AddressesFromPools []corev1.TypedLocalObjectReference `json:"addressesFromPools,omitempty"`
    }

type TypedLocalObjectReference struct { // APIGroup is the group for the resource being referenced. // If APIGroup is not specified, the specified Kind must be in the core API group. // For any other third-party types, APIGroup is required. // +optional APIGroup *string json:"apiGroup" protobuf:"bytes,1,opt,name=apiGroup" // Kind is the type of resource being referenced Kind string json:"kind" protobuf:"bytes,2,opt,name=kind" // Name is the name of resource being referenced Name string json:"name" protobuf:"bytes,3,opt,name=name" }


2. 另一种不需要 namespace,可以给所有的命名空间的 ElfMachine 共享使用。

当前 Metal3 只提供了 namespace 作用域的 IPPool。

目前 SKS 的集群只使用了 default 命名空间,所以这种情况下,所有的 Machine 都在 default 命名空间,所以都可以使用到 default 命名空间的 IPPool。

但 SKS E2E 每个 case 都使用了不同的 namespace,例如 sks-e2e-main-43-k8s-mhc、sks-e2e-main-43-k8s-scale-groups。这样导致 E2E 创建的 IPPool 不能被所有的 cases 的 Machine 使用。

```go
type ObjectKey struct {
    // name is unique within a namespace to reference a object resource.
    // +kubebuilder:validation:MinLength=1
    Name string `json:"name"`
    // namespace defines the space within which the object name must be unique.
    // +optional
    Namespace string `json:"namespace,omitempty"`
}

Change

选择 IPPool 的流程调整: (1)如果设置了 ip-pool-name:

  1. 如果 elfMachine 设置了 AddressesFromPool,会使用 AddressesFromPool.name 作为 cluster.x-k8s.io/ip-pool-name,对应的 elfMachine.namespace 作为 cluster.x-k8s.io/ip-pool-namespace(这部分为了支持在 Device 配置 IPPool 加的,其他的 2-3 部分逻辑是原来的)
  2. 否则会从 elfMachine 对应的 ElfMachineTemplate 获取 cluster.x-k8s.io/ip-pool-namespace 和 cluster.x-k8s.io/ip-pool-name(SKS 从 KSC 取值设置)
  3. 使用 ip-pool-name 和 ip-pool-namespace 获取 IPPool,能获取到直接返回,获取不到下一步
  4. 查询在默认命名空间 default 中的名为 ip-pool-name 的 IPPool

(2)如果没有设置 ip-pool-name:

  1. 从 elfMachine.namespace 查询带有 is-default 标签的 IPPool,如果有多个取第一个。如果没有,下一步
  2. 从默认命名空间查询所有的 查询带有 is-default 标签的 IPPool,如果有多个取第一个。

默认命名空间 cape-system 改成 default

Test

E2E

image
codecov[bot] commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 68.40%. Comparing base (d5d7b1d) to head (7a77cc9).

:exclamation: Current head 7a77cc9 differs from pull request most recent head b66f9b5. Consider uploading reports for the commit b66f9b5 to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #37 +/- ## ======================================= Coverage 68.40% 68.40% ======================================= Files 2 2 Lines 307 307 ======================================= Hits 210 210 Misses 81 81 Partials 16 16 ```

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