Skip to content

Commit

Permalink
Make revisions based on the review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
yanhb-nil committed Dec 27, 2024
1 parent 17f8366 commit a47b079
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/usage/install/overlay/get-started-calico-zh_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ EOF
```

> `spec.macvlan.master` 设置为 `ens192`, `ens192`必须存在于主机上。并且 `spec.macvlan.spiderpoolConfigPools.IPv4IPPool`设置的子网和 `ens192`保持一致。
> 如果需要为Pod添加多张Underlay网卡的可以参考[**Multi-Underlay-NIC**](./multi-underlay-nic-zh_CN.md)。
> 如果需要为 Pod 添加多张 Underlay 网卡的可以参考 [**Multi-Underlay-NIC**](./multi-underlay-nic-zh_CN.md)。

创建成功后, 查看 Multus NAD 是否成功创建:

Expand Down
2 changes: 1 addition & 1 deletion docs/usage/install/overlay/get-started-cilium-zh_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ EOF
Note:

> subnet 应该与节点网卡 ens192 的子网保持一致,并且不与现有任何 IP 冲突。
> 如果需要为Pod添加多张Underlay网卡的可以参考[**Multi-Underlay-NIC**](./multi-underlay-nic-zh_CN.md)。
> 如果需要为 Pod 添加多张 Underlay 网卡的可以参考 [**Multi-Underlay-NIC**](./multi-underlay-nic-zh_CN.md)。

### 创建 SpiderMultusConfig

Expand Down
10 changes: 5 additions & 5 deletions docs/usage/install/overlay/multi-underlay-nic-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[**English**](./multi-underlay-nic.md) | **简体中文**

## 基于 Webhook 自动注入 Multi Underlay 网络资源
## 基于 Webhook 自动为 Pod 附加多张 Underlay 网卡

本文集群节点网卡: `ens192` 所在子网为 `10.6.0.0/16`,`ens193` 所在子网为 `10.7.0.0/16`,以此创建 SpiderIPPool:

Expand Down Expand Up @@ -33,7 +33,7 @@
apiVersion: spiderpool.spidernet.io/v2beta1
kind: SpiderMultusConfig
metadata:
name: macvlan1
name: macvlan-ens192
namespace: spiderpool
annotations:
cni.spidernet.io/network-resource-inject: multi-network
Expand All @@ -50,7 +50,7 @@
apiVersion: spiderpool.spidernet.io/v2beta1
kind: SpiderMultusConfig
metadata:
name: macvlan2
name: macvlan-ens193
namespace: spiderpool
annotations:
cni.spidernet.io/network-resource-inject: multi-network
Expand Down Expand Up @@ -90,7 +90,7 @@
metadata:
annotations:
k8s.v1.cni.cncf.io/networks: |-
[{"name":"macvlan1","namespace":"spiderpool"},
{"name":"macvlan2","namespace":"spiderpool"}]
[{"name":"macvlan-ens192","namespace":"spiderpool"},
{"name":"macvlan-ens193","namespace":"spiderpool"}]
....
```
10 changes: 5 additions & 5 deletions docs/usage/install/overlay/multi-underlay-nic.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

**English** | [**简体中文**](./multi-underlay-nic-zh_CN.md)

## Auto Inject Multi Underlay NIC Resources Based on Webhook
## Auto attach multiple underlay NICs to Pod based on Webhook

The subnet for the interface `ens192` on the cluster nodes here is `10.6.0.0/16`. The subnet for the interface `ens193` on the cluster nodes here is `10.7.0.0/16`. Create SpiderIPPools using these subnets:

Expand Down Expand Up @@ -33,7 +33,7 @@
apiVersion: spiderpool.spidernet.io/v2beta1
kind: SpiderMultusConfig
metadata:
name: macvlan1
name: macvlan-ens192
namespace: spiderpool
annotations:
cni.spidernet.io/network-resource-inject: multi-network
Expand All @@ -50,7 +50,7 @@
apiVersion: spiderpool.spidernet.io/v2beta1
kind: SpiderMultusConfig
metadata:
name: macvlan2
name: macvlan-ens193
namespace: spiderpool
annotations:
cni.spidernet.io/network-resource-inject: multi-network
Expand Down Expand Up @@ -90,7 +90,7 @@
metadata:
annotations:
k8s.v1.cni.cncf.io/networks: |-
[{"name":"macvlan1","namespace":"spiderpool"},
{"name":"macvlan2","namespace":"spiderpool"}]
[{"name":"macvlan-ens192","namespace":"spiderpool"},
{"name":"macvlan-ens193","namespace":"spiderpool"}]
....
```
39 changes: 35 additions & 4 deletions pkg/multuscniconfig/multusconfig_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func validateCNIConfig(multusConfig *spiderpoolv2beta1.SpiderMultusConfig) *fiel
}

_, injectRdmaResource := multusConfig.Annotations[constant.AnnoPodResourceInject]
_, injectNetworkResource := multusConfig.Annotations[constant.AnnoNetworkResourceInject]
switch *multusConfig.Spec.CniType {
case constant.MacvlanCNI:
if multusConfig.Spec.MacvlanConfig == nil {
Expand All @@ -115,6 +116,12 @@ func validateCNIConfig(multusConfig *spiderpoolv2beta1.SpiderMultusConfig) *fiel
}
}

if injectNetworkResource {
if err := ValidateNetworkResouce(multusConfig.Name, multusConfig.Namespace, multusConfig.Spec.MacvlanConfig.RdmaResourceName, multusConfig.Spec.MacvlanConfig.SpiderpoolConfigPools); err != nil {
return field.Invalid(macvlanConfigField, *multusConfig.Spec.MacvlanConfig, err.Error())
}
}

case constant.IPVlanCNI:
if multusConfig.Spec.IPVlanConfig == nil {
return field.Required(ipvlanConfigField, fmt.Sprintf("no %s specified", ipvlanConfigField.String()))
Expand All @@ -140,6 +147,12 @@ func validateCNIConfig(multusConfig *spiderpoolv2beta1.SpiderMultusConfig) *fiel
}
}

if injectNetworkResource {
if err := ValidateNetworkResouce(multusConfig.Name, multusConfig.Namespace, multusConfig.Spec.IPVlanConfig.RdmaResourceName, multusConfig.Spec.IPVlanConfig.SpiderpoolConfigPools); err != nil {
return field.Invalid(ipvlanConfigField, *multusConfig.Spec.IPVlanConfig, err.Error())
}
}

case constant.SriovCNI:
if multusConfig.Spec.SriovConfig == nil {
return field.Required(sriovConfigField, fmt.Sprintf("no %s specified", sriovConfigField.String()))
Expand Down Expand Up @@ -171,6 +184,12 @@ func validateCNIConfig(multusConfig *spiderpoolv2beta1.SpiderMultusConfig) *fiel
}
}

if injectNetworkResource {
if err := ValidateNetworkResouce(multusConfig.Name, multusConfig.Namespace, multusConfig.Spec.SriovConfig.ResourceName, multusConfig.Spec.SriovConfig.SpiderpoolConfigPools); err != nil {
return field.Invalid(sriovConfigField, *multusConfig.Spec.SriovConfig, err.Error())
}
}

case constant.IBSriovCNI:
if multusConfig.Spec.IbSriovConfig == nil {
return field.Required(ibsriovConfigField, fmt.Sprintf("no %s specified", ibsriovConfigField.String()))
Expand All @@ -190,6 +209,12 @@ func validateCNIConfig(multusConfig *spiderpoolv2beta1.SpiderMultusConfig) *fiel
}
}

if injectNetworkResource {
if err := ValidateNetworkResouce(multusConfig.Name, multusConfig.Namespace, multusConfig.Spec.IbSriovConfig.ResourceName, multusConfig.Spec.IbSriovConfig.SpiderpoolConfigPools); err != nil {
return field.Invalid(ibsriovConfigField, *multusConfig.Spec.IbSriovConfig, err.Error())
}
}

case constant.IPoIBCNI:
if multusConfig.Spec.IpoibConfig == nil {
return field.Required(ipoibConfigField, fmt.Sprintf("no %s specified", ipoibConfigField.String()))
Expand All @@ -209,9 +234,15 @@ func validateCNIConfig(multusConfig *spiderpoolv2beta1.SpiderMultusConfig) *fiel
}
}

if injectNetworkResource {
if err := ValidateNetworkResouce(multusConfig.Name, multusConfig.Namespace, multusConfig.Spec.IpoibConfig.Master, multusConfig.Spec.IpoibConfig.SpiderpoolConfigPools); err != nil {
return field.Invalid(ipoibConfigField, *multusConfig.Spec.IpoibConfig, err.Error())
}
}

case constant.OvsCNI:
if injectRdmaResource {
return field.Forbidden(cniTypeField, fmt.Sprintf("the cniType %s does not support RDMA resource injected", *multusConfig.Spec.CniType))
if injectRdmaResource || injectNetworkResource {
return field.Forbidden(cniTypeField, fmt.Sprintf("the cniType %s does not support RDMA resource or network resource injected", *multusConfig.Spec.CniType))
}
if multusConfig.Spec.OvsConfig == nil {
return field.Required(ovsConfigField, fmt.Sprintf("no %s specified", ovsConfigField.String()))
Expand Down Expand Up @@ -250,8 +281,8 @@ func validateCNIConfig(multusConfig *spiderpoolv2beta1.SpiderMultusConfig) *fiel
}

case constant.CustomCNI:
if injectRdmaResource {
return field.Forbidden(cniTypeField, fmt.Sprintf("the cniType %s does not support RDMA resource injected", *multusConfig.Spec.CniType))
if injectRdmaResource || injectNetworkResource {
return field.Forbidden(cniTypeField, fmt.Sprintf("the cniType %s does not support RDMA resource or network resource injected", *multusConfig.Spec.CniType))
}
// multusConfig.Spec.CustomCNIConfig can be empty
if checkExistedConfig(&(multusConfig.Spec), constant.CustomCNI) {
Expand Down
16 changes: 16 additions & 0 deletions pkg/multuscniconfig/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,19 @@ func ValidateRdmaResouce(enableRdma bool, name, namespace, rdmaResourceName stri

return nil
}

func ValidateNetworkResouce(name, namespace, resourceName string, ippools *v2beta1.SpiderpoolPools) error {
if len(resourceName) == 0 {
return nil
}

if ippools == nil {
return fmt.Errorf("No any ippools configured for spidermultusconfig %s/%s", namespace, name)
}

if len(ippools.IPv4IPPool)+len(ippools.IPv6IPPool) == 0 {
return fmt.Errorf("No any ippools configured for spidermultusconfig %s/%s", namespace, name)
}

return nil
}

0 comments on commit a47b079

Please sign in to comment.