Skip to content

Commit

Permalink
spidermultusconfig: ovs cni config supported (spidernet-io#2199)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyclinder authored Aug 23, 2023
1 parent 93677f1 commit 830ceca
Show file tree
Hide file tree
Showing 13 changed files with 328 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ spec:
- macvlan
- ipvlan
- sriov
- ovs
- custom
type: string
coordinator:
Expand Down Expand Up @@ -176,6 +177,49 @@ spec:
required:
- master
type: object
ovs:
properties:
bridge:
type: string
deviceID:
description: PCI address of a VF in valid sysfs format
type: string
ippools:
description: SpiderpoolPools could specify the IPAM spiderpool
CNI configuration default IPv4&IPv6 pools.
properties:
ipv4:
items:
type: string
type: array
ipv6:
items:
type: string
type: array
type: object
trunk:
items:
properties:
id:
maximum: 4094
minimum: 0
type: integer
maxID:
maximum: 4094
minimum: 0
type: integer
minID:
maximum: 4094
minimum: 0
type: integer
type: object
type: array
vlan:
format: int32
type: integer
required:
- bridge
type: object
sriov:
properties:
ippools:
Expand Down
2 changes: 1 addition & 1 deletion cmd/ifacer/cmd/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func ParseConfig(stdin []byte) (*Ifacer, error) {
}

if conf.VlanID < 0 || conf.VlanID > 4094 {
return nil, fmt.Errorf("invalid vlanID %v: vlanID must be in range [0,4094]", conf.VlanID)
return nil, fmt.Errorf("invalid vlan tag %v: vlan tag must be in range [0,4094]", conf.VlanID)
}

if conf.Bond != nil && conf.Bond.Name == "" {
Expand Down
37 changes: 28 additions & 9 deletions docs/reference/crd-spidermultusconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@ And you can also use special annotation `multus.spidernet.io/cr-name` and `multu

This is the SpiderReservedIP spec for users to configure.

| Field | Description | Schema | Validation | Values | Default |
|-------------------|---------------------------------------------------|------------------------------------------------------------------------------|------------|-----------------------------|---------|
| cniType | expected main CNI type | string | require | macvlan,ipvlan,sriov,custom | |
| macvlan | macvlan CNI configuration | [SpiderMacvlanCniConfig](./crd-spidermultusconfig.md#SpiderMacvlanCniConfig) | optional | | |
| ipvlan | ipvlan CNI configuration | [SpiderIPvlanCniConfig](./crd-spidermultusconfig.md#SpiderIPvlanCniConfig) | optional | | |
| sriov | sriov CNI configuration | [SpiderSRIOVCniConfig](./crd-spidermultusconfig.md#SpiderSRIOVCniConfig) | optional | | |
| enableCoordinator | enable coordinator or not | boolean | optional | true,false | true |
| coordinator | coordinator CNI configuration | [CoordinatorSpec](./crd-spidercoordinator.md#Spec) | optional | | |
| customCNI | a string that represents custom CNI configuration | string | optional | | |
| Field | Description | Schema | Validation | Values | Default |
|-------------------|---------------------------------------------------|------------------------------------------------------------------------------|------------|---------------------------------|---------|
| cniType | expected main CNI type | string | require | macvlan,ipvlan,sriov,ovs,custom | |
| macvlan | macvlan CNI configuration | [SpiderMacvlanCniConfig](./crd-spidermultusconfig.md#SpiderMacvlanCniConfig) | optional | | |
| ipvlan | ipvlan CNI configuration | [SpiderIPvlanCniConfig](./crd-spidermultusconfig.md#SpiderIPvlanCniConfig) | optional | | |
| sriov | sriov CNI configuration | [SpiderSRIOVCniConfig](./crd-spidermultusconfig.md#SpiderSRIOVCniConfig) | optional | | |
| ovs | ovs CNI configuration | [SpiderOvsCniConfig](./crd-spidermultusconfig.md#SpiderOvsCniConfig) | optional | | |
| enableCoordinator | enable coordinator or not | boolean | optional | true,false | true |
| coordinator | coordinator CNI configuration | [CoordinatorSpec](./crd-spidercoordinator.md#Spec) | optional | | |
| customCNI | a string that represents custom CNI configuration | string | optional | | |

#### SpiderMacvlanCniConfig

Expand Down Expand Up @@ -85,6 +86,16 @@ This is the SpiderReservedIP spec for users to configure.
| vlanID | vlan ID | int | optional |
| ippools | the default IPPools in your CNI configurations | [SpiderpoolPools](./crd-spidermultusconfig.md#SpiderpoolPools) | optional |

#### SpiderOvsCniConfig

| Field | Description | Schema | Validation |
|--------------|-------------------------------------------------------------------------------------------|----------------------------------------------------------------|------------|
| bridge | name of the bridge to use | string | required |
| vlan | vlan ID of attached port. Trunk port if not specified | int | optional |
| trunk | List of VLAN ID's and/or ranges of accepted VLAN ID's | [Trunk](./crd-spidermultusconfig.md#Trunk) | optional |
| deviceID | PCI address of a VF in valid sysfs format | string | optional |
| ippools | the default IPPools in your CNI configurations | [SpiderpoolPools](./crd-spidermultusconfig.md#SpiderpoolPools) | optional |

#### BondConfig

| Field | Description | Schema | Validation | Values |
Expand All @@ -93,6 +104,14 @@ This is the SpiderReservedIP spec for users to configure.
| Mode | bond interface mode | int | required | [0,6] |
| Options | expected bond Interface configurations | string | optional | |

#### Trunk

| Field | Description | Schema | Validation | Values |
|-----------------------|----------------------------------------|--------|------------|----------|
| minID | the min value of vlan ID | int | optional | [0,4094] |
| maxID | the max value of vlan ID | int | optional | [0,4094] |
| id | the value of vlan ID | int | optional | [0,4094] |

#### SpiderpoolPools

| Field | Description | Schema | Validation |
Expand Down
30 changes: 11 additions & 19 deletions docs/usage/install/underlay/get-started-ovs-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,31 +120,23 @@ ec16d9e1-6187-4b21-9c2f-8b6cb75434b9
~#
```
4. 为 ovs-cni 创建 multus NetworkAttachmentDefinition CR
4. Spiderpool 为简化书写 JSON 格式的 Multus CNI 配置,它提供了 SpiderMultusConfig CR 来自动管理 Multus NetworkAttachmentDefinition CR。如下是创建 Ovs SpiderMultusConfig 配置的示例:
```bash
* 确认 ovs-cni 所需的网桥名称,本例子以 br1 为例:
```shell
BRIDGE_NAME="br1"
cat <<EOF | kubectl apply -f -
apiVersion: k8s.cni.cncf.io/v1
kind: NetworkAttachmentDefinition
apiVersion: spiderpool.spidernet.io/v2beta1
kind: SpiderMultusConfig
metadata:
name: ovs-conf
namespace: kube-system
spec:
config: |-
{
"cniVersion": "0.3.1",
"name": "ovs-conf",
"plugins": [
{
"type": "ovs",
"bridge": "br1",
"ipam": {
"type": "spiderpool",
}
}
]
}
EOF
cniType: ovs
ovs:
bridge: "${BRIDGE_NAME}"
EOF
```
## 创建应用
Expand Down
32 changes: 10 additions & 22 deletions docs/usage/install/underlay/get-started-ovs.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,35 +122,23 @@ ec16d9e1-6187-4b21-9c2f-8b6cb75434b9
~#
```
4. Create a NetworkAttachmentDefinition for ovs-cni.
4. To simplify writing Multus CNI configuration in JSON format, Spiderpool provides SpiderMultusConfig CR to automatically manage Multus NetworkAttachmentDefinition CR. Here is an example of creating an ovs-cni SpiderMultusConfig configuration:
The following parameters need to be confirmed:
* Confirm the required host bridge for ovs-cni, for example based on the command `ovs-vsctl show`, this example takes the host bridge: `br1` as an example.
* Confirm the required host bridge for ovs-cni, for example based on the command `ovs-vsctl show`, this example takes the host bridge: `br1` as an example.
```bash
```shell
BRIDGE_NAME="br1"
cat <<EOF | kubectl apply -f -
apiVersion: k8s.cni.cncf.io/v1
kind: NetworkAttachmentDefinition
apiVersion: spiderpool.spidernet.io/v2beta1
kind: SpiderMultusConfig
metadata:
name: ovs-conf
namespace: kube-system
spec:
config: |-
{
"cniVersion": "0.3.1",
"name": "ovs-conf",
"plugins": [
{
"type": "ovs",
"bridge": "br1",
"ipam": {
"type": "spiderpool",
}
}
]
}
EOF
cniType: ovs
ovs:
bridge: "${BRIDGE_NAME}"
EOF
```
## Create applications
Expand Down
1 change: 1 addition & 0 deletions pkg/constant/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,5 @@ const (
MultusDefaultNetAnnot = "v1.multus-cni.io/default-network"
MultusNetworkAttachmentAnnot = "k8s.v1.cni.cncf.io/networks"
ResourceNameAnnot = "k8s.v1.cni.cncf.io/resourceName"
ResourceNameOvsCniValue = "ovs-cni.network.kubevirt.io"
)
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type SpiderMultusConfigList struct {
// MultusCNIConfigSpec defines the desired state of SpiderMultusConfig.
type MultusCNIConfigSpec struct {
// +kubebuilder:validation:Required
// +kubebuilder:validation:Enum=macvlan;ipvlan;sriov;custom
// +kubebuilder:validation:Enum=macvlan;ipvlan;sriov;ovs;custom
CniType string `json:"cniType"`

// +kubebuilder:validation:Optional
Expand All @@ -40,6 +40,9 @@ type MultusCNIConfigSpec struct {
// +kubebuilder:validation:Optional
SriovConfig *SpiderSRIOVCniConfig `json:"sriov,omitempty"`

// +kubebuilder:validation:Optional
OvsConfig *SpiderOvsCniConfig `json:"ovs,omitempty"`

// +kubebuilder:default=true
// +kubebuilder:validation:Optional
EnableCoordinator *bool `json:"enableCoordinator"`
Expand Down Expand Up @@ -97,6 +100,35 @@ type SpiderSRIOVCniConfig struct {
SpiderpoolConfigPools *SpiderpoolPools `json:"ippools,omitempty"`
}

type SpiderOvsCniConfig struct {
// +kubebuilder:validation:Required
BrName string `json:"bridge"`
// +kubebuilder:validation:Optional
VlanTag *int32 `json:"vlan"`
// +kubebuilder:validation:Optional
Trunk []*Trunk `json:"trunk,omitempty"`
// +kubebuilder:validation:Optional
// PCI address of a VF in valid sysfs format
DeviceID string `json:"deviceID"`
// +kubebuilder:validation:Optional
SpiderpoolConfigPools *SpiderpoolPools `json:"ippools,omitempty"`
}

type Trunk struct {
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=4094
MinID *uint `json:"minID,omitempty"`
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=4094
MaxID *uint `json:"maxID,omitempty"`
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=4094
ID *uint `json:"id,omitempty"`
}

type BondConfig struct {
// +kubebuilder:validation:Required
Name string `json:"name"`
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 830ceca

Please sign in to comment.