Skip to content

Commit

Permalink
Merge branch 'k8snetworkplumbingwg:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
nvidia-ci-cd authored Jan 14, 2025
2 parents 11ea4dc + f891498 commit f77f9b7
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 19 deletions.
4 changes: 4 additions & 0 deletions api/v1/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,10 @@ func (p *SriovNetworkNodePolicy) ApplyBridgeConfig(state *SriovNetworkNodeState)
Interface: p.Spec.Bridge.OVS.Uplink.Interface,
}},
}
if p.Spec.Mtu > 0 {
mtu := p.Spec.Mtu
ovsBridge.Uplinks[0].Interface.MTURequest = &mtu
}
log.Info("Update bridge for interface", "name", iface.Name, "bridge", ovsBridge.Name)

// We need to keep slices with bridges ordered to avoid unnecessary updates in the K8S API.
Expand Down
2 changes: 2 additions & 0 deletions api/v1/sriovnetworknodepolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ type OVSInterfaceConfig struct {
ExternalIDs map[string]string `json:"externalIDs,omitempty"`
// other_config field in the Interface table in OVSDB
OtherConfig map[string]string `json:"otherConfig,omitempty"`
// mtu_request field in the Interface table in OVSDB
MTURequest *int `json:"mtuRequest,omitempty"`
}

// SriovNetworkNodePolicyStatus defines the observed state of SriovNetworkNodePolicy
Expand Down
5 changes: 5 additions & 0 deletions api/v1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ spec:
description: external_ids field in the Interface table
in OVSDB
type: object
mtuRequest:
description: mtu_request field in the Interface table
in OVSDB
type: integer
options:
additionalProperties:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ spec:
description: external_ids field in the Interface
table in OVSDB
type: object
mtuRequest:
description: mtu_request field in the Interface
table in OVSDB
type: integer
options:
additionalProperties:
type: string
Expand Down Expand Up @@ -237,6 +241,10 @@ spec:
description: external_ids field in the Interface
table in OVSDB
type: object
mtuRequest:
description: mtu_request field in the Interface
table in OVSDB
type: integer
options:
additionalProperties:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ spec:
description: external_ids field in the Interface table
in OVSDB
type: object
mtuRequest:
description: mtu_request field in the Interface table
in OVSDB
type: integer
options:
additionalProperties:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ spec:
description: external_ids field in the Interface
table in OVSDB
type: object
mtuRequest:
description: mtu_request field in the Interface
table in OVSDB
type: integer
options:
additionalProperties:
type: string
Expand Down Expand Up @@ -237,6 +241,10 @@ spec:
description: external_ids field in the Interface
table in OVSDB
type: object
mtuRequest:
description: mtu_request field in the Interface
table in OVSDB
type: integer
options:
additionalProperties:
type: string
Expand Down
31 changes: 18 additions & 13 deletions hack/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,27 @@ if [ -z $SKIP_VAR_SET ]; then
export METRICS_EXPORTER_IMAGE=${METRICS_EXPORTER_IMAGE:-ghcr.io/k8snetworkplumbingwg/sriov-network-metrics-exporter}
export SRIOV_NETWORK_OPERATOR_IMAGE=${SRIOV_NETWORK_OPERATOR_IMAGE:-ghcr.io/k8snetworkplumbingwg/sriov-network-operator}
export METRICS_EXPORTER_KUBE_RBAC_PROXY_IMAGE=${METRICS_EXPORTER_KUBE_RBAC_PROXY_IMAGE:-gcr.io/kubebuilder/kube-rbac-proxy:v0.15.0}
fail_msg_detect="is empty and failed to detect"
else
# ensure that OVS_CNI_IMAGE is set, empty string is a valid value
OVS_CNI_IMAGE=${OVS_CNI_IMAGE:-}
# ensure that RDMA_CNI_IMAGE is set, empty string is a valid value
RDMA_CNI_IMAGE=${RDMA_CNI_IMAGE:-}
METRICS_EXPORTER_KUBE_RBAC_PROXY_IMAGE=${METRICS_EXPORTER_KUBE_RBAC_PROXY_IMAGE:-}
[ -z $SRIOV_CNI_IMAGE ] && echo "SRIOV_CNI_IMAGE is empty but SKIP_VAR_SET is set" && exit 1
[ -z $SRIOV_INFINIBAND_CNI_IMAGE ] && echo "SRIOV_INFINIBAND_CNI_IMAGE is empty but SKIP_VAR_SET is set" && exit 1
[ -z $SRIOV_DEVICE_PLUGIN_IMAGE ] && echo "SRIOV_DEVICE_PLUGIN_IMAGE is empty but SKIP_VAR_SET is set" && exit 1
[ -z $NETWORK_RESOURCES_INJECTOR_IMAGE ] && echo "NETWORK_RESOURCES_INJECTOR_IMAGE is empty but SKIP_VAR_SET is set" && exit 1
[ -z $SRIOV_NETWORK_CONFIG_DAEMON_IMAGE ] && echo "SRIOV_NETWORK_CONFIG_DAEMON_IMAGE is empty but SKIP_VAR_SET is set" && exit 1
[ -z $SRIOV_NETWORK_WEBHOOK_IMAGE ] && echo "SRIOV_NETWORK_WEBHOOK_IMAGE is empty but SKIP_VAR_SET is set" && exit 1
[ -z $METRICS_EXPORTER_IMAGE ] && echo "METRICS_EXPORTER_IMAGE is empty but SKIP_VAR_SET is set" && exit 1
[ -z $SRIOV_NETWORK_OPERATOR_IMAGE ] && echo "SRIOV_NETWORK_OPERATOR_IMAGE is empty but SKIP_VAR_SET is set" && exit 1
fail_msg_detect="is empty but SKIP_VAR_SET is set"
fi

# ensure that OVS_CNI_IMAGE is set, empty string is a valid value
OVS_CNI_IMAGE=${OVS_CNI_IMAGE:-}
# ensure that RDMA_CNI_IMAGE is set, empty string is a valid value
RDMA_CNI_IMAGE=${RDMA_CNI_IMAGE:-}
METRICS_EXPORTER_KUBE_RBAC_PROXY_IMAGE=${METRICS_EXPORTER_KUBE_RBAC_PROXY_IMAGE:-}
[ -z $SRIOV_CNI_IMAGE ] && echo "SRIOV_CNI_IMAGE $fail_msg_detect" && exit 1
[ -z $SRIOV_INFINIBAND_CNI_IMAGE ] && echo "SRIOV_INFINIBAND_CNI_IMAGE $fail_msg_detect" && exit 1
[ -z $SRIOV_DEVICE_PLUGIN_IMAGE ] && echo "SRIOV_DEVICE_PLUGIN_IMAGE $fail_msg_detect" && exit 1
[ -z $NETWORK_RESOURCES_INJECTOR_IMAGE ] && echo "NETWORK_RESOURCES_INJECTOR_IMAGE $fail_msg_detect" && exit 1
[ -z $SRIOV_NETWORK_CONFIG_DAEMON_IMAGE ] && echo "SRIOV_NETWORK_CONFIG_DAEMON_IMAGE $fail_msg_detect" && exit 1
[ -z $SRIOV_NETWORK_WEBHOOK_IMAGE ] && echo "SRIOV_NETWORK_WEBHOOK_IMAGE $fail_msg_detect" && exit 1
[ -z $METRICS_EXPORTER_IMAGE ] && echo "METRICS_EXPORTER_IMAGE $fail_msg_detect" && exit 1
[ -z $SRIOV_NETWORK_OPERATOR_IMAGE ] && echo "SRIOV_NETWORK_OPERATOR_IMAGE $fail_msg_detect" && exit 1

unset fail_msg_detect

set -x

export RELEASE_VERSION=4.7.0
Expand Down
1 change: 1 addition & 0 deletions pkg/host/internal/bridge/ovs/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type InterfaceEntry struct {
Options map[string]string `ovsdb:"options"`
ExternalIDs map[string]string `ovsdb:"external_ids"`
OtherConfig map[string]string `ovsdb:"other_config"`
MTURequest *int `ovsdb:"mtu_request"`
}

// PortEntry represents some fields of the object in the Port table
Expand Down
15 changes: 15 additions & 0 deletions pkg/host/internal/bridge/ovs/ovs.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@ func (o *ovs) CreateOVSBridge(ctx context.Context, conf *sriovnetworkv1.OVSConfi
funcLog.Error(err, "CreateOVSBridge(): failed to get bridge after creation")
return err
}
funcLog.V(2).Info("CreateOVSBridge(): add internal interface to the bridge")
if err := o.addInterface(ctx, dbClient, bridge, &InterfaceEntry{
Name: bridge.Name,
UUID: uuid.NewString(),
Type: "internal",
}); err != nil {
funcLog.Error(err, "CreateOVSBridge(): failed to add internal interface to the bridge")
return err
}
funcLog.V(2).Info("CreateOVSBridge(): add uplink interface to the bridge")
if err := o.addInterface(ctx, dbClient, bridge, &InterfaceEntry{
Name: conf.Uplinks[0].Name,
Expand All @@ -156,6 +165,7 @@ func (o *ovs) CreateOVSBridge(ctx context.Context, conf *sriovnetworkv1.OVSConfi
Options: conf.Uplinks[0].Interface.Options,
ExternalIDs: conf.Uplinks[0].Interface.ExternalIDs,
OtherConfig: conf.Uplinks[0].Interface.OtherConfig,
MTURequest: conf.Uplinks[0].Interface.MTURequest,
}); err != nil {
funcLog.Error(err, "CreateOVSBridge(): failed to add uplink interface to the bridge")
return err
Expand Down Expand Up @@ -592,6 +602,10 @@ func (o *ovs) getCurrentBridgeState(ctx context.Context, dbClient client.Client,
OtherConfig: updateMap(knownConfigUplink.Interface.OtherConfig, iface.OtherConfig),
},
}}
if iface.MTURequest != nil {
mtu := *iface.MTURequest
currentConfig.Uplinks[0].Interface.MTURequest = &mtu
}
return currentConfig, nil
}

Expand Down Expand Up @@ -707,6 +721,7 @@ func getClient(ctx context.Context) (client.Client, error) {
&interfaceEntry.Options,
&interfaceEntry.ExternalIDs,
&interfaceEntry.OtherConfig,
&interfaceEntry.MTURequest,
),
client.WithTable(portEntry,
&portEntry.UUID,
Expand Down
36 changes: 30 additions & 6 deletions pkg/host/internal/bridge/ovs/ovs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
)

func getManagedBridges() map[string]*sriovnetworkv1.OVSConfigExt {
mtu := 5000
return map[string]*sriovnetworkv1.OVSConfigExt{
"br-0000_d8_00.0": {
Name: "br-0000_d8_00.0",
Expand All @@ -43,6 +44,7 @@ func getManagedBridges() map[string]*sriovnetworkv1.OVSConfigExt {
ExternalIDs: map[string]string{"iface_externalID_key": "iface_externalID_value"},
OtherConfig: map[string]string{"iface_otherConfig_key": "iface_otherConfig_value"},
Options: map[string]string{"iface_options_key": "iface_options_value"},
MTURequest: &mtu,
},
}},
},
Expand Down Expand Up @@ -83,13 +85,15 @@ func (t *testDBEntries) GetCreateOperations(c client.Client) []ovsdb.Operation {
}

func getDefaultInitialDBContent() *testDBEntries {
mtu := 5000
iface := &InterfaceEntry{
Name: "enp216s0f0np0",
UUID: uuid.NewString(),
Type: "dpdk",
ExternalIDs: map[string]string{"iface_externalID_key": "iface_externalID_value"},
OtherConfig: map[string]string{"iface_otherConfig_key": "iface_otherConfig_value"},
Options: map[string]string{"iface_options_key": "iface_options_value"},
MTURequest: &mtu,
}
port := &PortEntry{
Name: "enp216s0f0np0",
Expand Down Expand Up @@ -137,25 +141,43 @@ func createInitialDBContent(ctx context.Context, c client.Client, expectedState
func validateDBConfig(dbContent *testDBEntries, conf *sriovnetworkv1.OVSConfigExt) {
Expect(dbContent.OpenVSwitch).To(HaveLen(1))
Expect(dbContent.Bridge).To(HaveLen(1))
Expect(dbContent.Interface).To(HaveLen(1))
Expect(dbContent.Port).To(HaveLen(1))
Expect(dbContent.Interface).To(HaveLen(2))
Expect(dbContent.Port).To(HaveLen(2))
ovs := dbContent.OpenVSwitch[0]
br := dbContent.Bridge[0]
port := dbContent.Port[0]
iface := dbContent.Interface[0]
ports := make(map[string]*PortEntry, 0)
interfaces := make(map[string]*InterfaceEntry, 0)
for _, p := range dbContent.Port {
ports[p.Name] = p
}
for _, ifc := range dbContent.Interface {
interfaces[ifc.Name] = ifc
}
Expect(ovs.Bridges).To(ContainElement(br.UUID))
Expect(br.Name).To(Equal(conf.Name))
Expect(br.DatapathType).To(Equal(conf.Bridge.DatapathType))
Expect(br.OtherConfig).To(Equal(conf.Bridge.OtherConfig))
Expect(br.ExternalIDs).To(Equal(conf.Bridge.ExternalIDs))
port, ok := ports[conf.Uplinks[0].Name]
Expect(ok).To(BeTrue())
Expect(br.Ports).To(ContainElement(port.UUID))
Expect(port.Name).To(Equal(conf.Uplinks[0].Name))
iface, ok := interfaces[conf.Uplinks[0].Name]
Expect(ok).To(BeTrue())
Expect(port.Interfaces).To(ContainElement(iface.UUID))
Expect(iface.Name).To(Equal(conf.Uplinks[0].Name))
Expect(iface.Options).To(Equal(conf.Uplinks[0].Interface.Options))
Expect(iface.Type).To(Equal(conf.Uplinks[0].Interface.Type))
Expect(iface.OtherConfig).To(Equal(conf.Uplinks[0].Interface.OtherConfig))
Expect(iface.ExternalIDs).To(Equal(conf.Uplinks[0].Interface.ExternalIDs))
Expect(iface.MTURequest).To(Equal(conf.Uplinks[0].Interface.MTURequest))
internalPort, ok := ports[conf.Name]
Expect(ok).To(BeTrue())
internalIface, ok := interfaces[conf.Name]
Expect(ok).To(BeTrue())
Expect(internalPort.Interfaces).To(ContainElement(internalIface.UUID))
Expect(internalIface.Options).To(BeNil())
Expect(internalIface.Type).To(Equal("internal"))
Expect(internalIface.OtherConfig).To(BeNil())
Expect(internalIface.ExternalIDs).To(BeNil())
}

var _ = Describe("OVS", func() {
Expand Down Expand Up @@ -457,6 +479,7 @@ var _ = Describe("OVS", func() {
initialDBContent := getDefaultInitialDBContent()
initialDBContent.Bridge[0].ExternalIDs = nil
initialDBContent.Bridge[0].OtherConfig = nil
initialDBContent.Interface[0].MTURequest = nil
createInitialDBContent(ctx, ovsClient, initialDBContent)
conf := getManagedBridges()
store.EXPECT().GetManagedOVSBridges().Return(conf, nil)
Expand All @@ -465,6 +488,7 @@ var _ = Describe("OVS", func() {
Expect(ret).To(HaveLen(1))
Expect(ret[0].Bridge.ExternalIDs).To(BeEmpty())
Expect(ret[0].Bridge.OtherConfig).To(BeEmpty())
Expect(ret[0].Uplinks[0].Interface.MTURequest).To(BeNil())
})
})
Context("RemoveOVSBridge", func() {
Expand Down
9 changes: 9 additions & 0 deletions pkg/host/internal/bridge/ovs/test_db.ovsschema
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@
},
"type": {
"type": "string"
},
"mtu_request":{
"type": {
"key": {
"minInteger":1,
"type": "integer"
},
"min": 0
}
}
},
"indexes": [
Expand Down

0 comments on commit f77f9b7

Please sign in to comment.