From 02704ada467524c10bf16a7ca43d525c15c9b838 Mon Sep 17 00:00:00 2001 From: shibaPuppy Date: Wed, 26 Apr 2023 01:04:21 +0900 Subject: [PATCH] Add bond hash policy https://github.com/openstack/ironic/blob/master/ironic/tests/unit/drivers/modules/network/json_samples/network_data.json#L31 Adds the bond hash policy feature added to Ironic. --- api/v1beta1/metal3datatemplate_types.go | 6 ++++++ baremetal/metal3data_manager.go | 13 ++++++------ baremetal/metal3data_manager_test.go | 20 ++++++++++--------- ....cluster.x-k8s.io_metal3datatemplates.yaml | 9 ++++++++- 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/api/v1beta1/metal3datatemplate_types.go b/api/v1beta1/metal3datatemplate_types.go index ebcd8b0aba..31f769f3ab 100644 --- a/api/v1beta1/metal3datatemplate_types.go +++ b/api/v1beta1/metal3datatemplate_types.go @@ -224,6 +224,11 @@ type NetworkDataLinkBond struct { // balance-rr, active-backup, balance-xor, broadcast, balance-tlb, balance-alb, 802.3ad BondMode string `json:"bondMode"` + // +kubebuilder:validation:Enum="layer2";"layer3+4";"layer2+3" + // Selects the transmit hash policy used for port selection in balance-xor and 802.3ad modes + // +optional + BondHashPolicy string `json:"bond_xmit_hash_policy"` + // Id is the ID of the interface (used for naming) Id string `json:"id"` //nolint:revive,stylecheck @@ -238,6 +243,7 @@ type NetworkDataLinkBond struct { MACAddress *NetworkLinkEthernetMac `json:"macAddress"` // BondLinks is the list of links that are part of the bond. + // +optional BondLinks []string `json:"bondLinks"` } diff --git a/baremetal/metal3data_manager.go b/baremetal/metal3data_manager.go index 776ebce1e6..5a624d2745 100644 --- a/baremetal/metal3data_manager.go +++ b/baremetal/metal3data_manager.go @@ -727,12 +727,13 @@ func renderNetworkLinks(networkLinks infrav1.NetworkDataLink, bmh *bmov1alpha1.B return nil, err } data = append(data, map[string]interface{}{ - "type": "bond", - "id": link.Id, - "mtu": link.MTU, - "ethernet_mac_address": macAddress, - "bond_mode": link.BondMode, - "bond_links": link.BondLinks, + "type": "bond", + "id": link.Id, + "mtu": link.MTU, + "ethernet_mac_address": macAddress, + "bond_mode": link.BondMode, + "bond_xmit_hash_policy": link.BondHashPolicy, + "bond_links": link.BondLinks, }) } diff --git a/baremetal/metal3data_manager_test.go b/baremetal/metal3data_manager_test.go index f7c4ab9a5e..7d23acb5fa 100644 --- a/baremetal/metal3data_manager_test.go +++ b/baremetal/metal3data_manager_test.go @@ -1753,9 +1753,10 @@ var _ = Describe("Metal3Data manager", func() { links: infrav1.NetworkDataLink{ Bonds: []infrav1.NetworkDataLinkBond{ { - BondMode: "802.3ad", - Id: "bond0", - MTU: 1500, + BondMode: "802.3ad", + BondHashPolicy: "layer3+4", + Id: "bond0", + MTU: 1500, MACAddress: &infrav1.NetworkLinkEthernetMac{ String: pointer.StringPtr("XX:XX:XX:XX:XX:XX"), }, @@ -1765,12 +1766,13 @@ var _ = Describe("Metal3Data manager", func() { }, expectedOutput: []interface{}{ map[string]interface{}{ - "type": "bond", - "id": "bond0", - "mtu": 1500, - "ethernet_mac_address": "XX:XX:XX:XX:XX:XX", - "bond_mode": "802.3ad", - "bond_links": []string{"eth0"}, + "type": "bond", + "id": "bond0", + "mtu": 1500, + "ethernet_mac_address": "XX:XX:XX:XX:XX:XX", + "bond_mode": "802.3ad", + "bond_xmit_hash_policy": "layer3+4", + "bond_links": []string{"eth0"}, }, }, }), diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_metal3datatemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_metal3datatemplates.yaml index 88170fba01..502a9cd46f 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_metal3datatemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_metal3datatemplates.yaml @@ -1146,6 +1146,14 @@ spec: description: NetworkDataLinkBond represents a bond link object. properties: + bond_xmit_hash_policy: + description: Selects the transmit hash policy used for + port selection in balance-xor and 802.3ad modes + enum: + - layer2 + - layer3+4 + - layer2+3 + type: string bondLinks: description: BondLinks is the list of links that are part of the bond. @@ -1189,7 +1197,6 @@ spec: maximum: 9000 type: integer required: - - bondLinks - bondMode - id - macAddress