Skip to content

Commit 963fed6

Browse files
committed
Squashed Together fork.
Upgrade golangci-lint to work with Go 1.23 Add platform build arg. Comment out Mellanox plugin's draining + rebooting for totalVfs + SRIOV_EN configs, which is buggy. Scan GUIDs (#7) * Squash commits into one * Squash commits into one * Cherry-picked types (build fix) * merge issues fix * read GUID from sysfs * node -> port * args mismatch :( * NAD config fix to include guid * port -> node back * rollback partially * rollback partially * rollback partially * rollback partially * rollback partially * rollback partially * rollback partially * fix * bring back pKey to netAttDef definition * pkey proper location * removed excessive log lines * quotes fix ENG-21048 - KernelArgIommuOn instead of KernelArgIommuPt (to enable ATS & ACS) (#9) KernelArgIommuOn instead of KernelArgIommuPt ENG-19808 mlxfwreset before reboot in SR-IOV operator (#8) * bring reboots back * bring reboots back GUIDSavedInUFM config parameter added camelcase -> snake case
1 parent 35e7319 commit 963fed6

15 files changed

Lines changed: 124 additions & 13 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export OPERATOR_EXEC?=oc
1111

1212
BUILD_GOPATH=$(TARGET_DIR):$(TARGET_DIR)/vendor:$(CURPATH)/cmd
1313
IMAGE_BUILDER?=docker
14-
IMAGE_BUILD_OPTS?=
14+
IMAGE_BUILD_OPTS?=--platform linux/amd64
1515
DOCKERFILE?=Dockerfile
1616
DOCKERFILE_CONFIG_DAEMON?=Dockerfile.sriov-network-config-daemon
1717
DOCKERFILE_WEBHOOK?=Dockerfile.webhook

api/v1/helper.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,13 @@ func (cr *SriovIBNetwork) RenderNetAttDef() (*uns.Unstructured, error) {
671671
data.Data["CapabilitiesConfigured"] = true
672672
data.Data["SriovCniCapabilities"] = cr.Spec.Capabilities
673673
}
674-
674+
if cr.Spec.PKey == "" {
675+
data.Data["pKeyConfigured"] = false
676+
} else {
677+
data.Data["pKeyConfigured"] = true
678+
data.Data["pKey"] = cr.Spec.PKey
679+
data.Data["GUIDSavedInUFM"] = false
680+
}
675681
if cr.Spec.IPAM != "" {
676682
data.Data["SriovCniIpam"] = SriovCniIpam + ":" + strings.Join(strings.Fields(cr.Spec.IPAM), "")
677683
} else {
@@ -714,6 +720,7 @@ func (cr *SriovNetwork) RenderNetAttDef() (*uns.Unstructured, error) {
714720
data := render.MakeRenderData()
715721
data.Data["CniType"] = "sriov"
716722
data.Data["SriovNetworkName"] = cr.Name
723+
data.Data["pKeyConfigured"] = false
717724
if cr.Spec.NetworkNamespace == "" {
718725
data.Data["SriovNetworkNamespace"] = cr.Namespace
719726
} else {
@@ -734,7 +741,6 @@ func (cr *SriovNetwork) RenderNetAttDef() (*uns.Unstructured, error) {
734741
data.Data["VlanProtoConfigured"] = true
735742
data.Data["SriovCniVlanProto"] = cr.Spec.VlanProto
736743
}
737-
738744
if cr.Spec.Capabilities == "" {
739745
data.Data["CapabilitiesConfigured"] = false
740746
} else {
@@ -832,6 +838,7 @@ func (cr *OVSNetwork) RenderNetAttDef() (*uns.Unstructured, error) {
832838
data := render.MakeRenderData()
833839
data.Data["CniType"] = "ovs"
834840
data.Data["NetworkName"] = cr.Name
841+
data.Data["pKeyConfigured"] = false
835842
if cr.Spec.NetworkNamespace == "" {
836843
data.Data["NetworkNamespace"] = cr.Namespace
837844
} else {

api/v1/sriovibnetwork_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type SriovIBNetworkSpec struct {
4343
// MetaPluginsConfig configuration to be used in order to chain metaplugins to the sriov interface returned
4444
// by the operator.
4545
MetaPluginsConfig string `json:"metaPlugins,omitempty"`
46+
PKey string `json:"pKey,omitempty"`
4647
}
4748

4849
// SriovIBNetworkStatus defines the observed state of SriovIBNetwork

bindata/manifests/cni-config/sriov/sriov-cni-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ spec:
3838
{{- if .CapabilitiesConfigured -}}
3939
"capabilities":{{.SriovCniCapabilities}},
4040
{{- end -}}
41+
{{- if .pKeyConfigured -}}
42+
"pkey":"{{.pKey}}",
43+
"guid_saved_in_ufm": "{{.GUIDSavedInUFM}}",
44+
{{- end -}}
4145
{{- if .StateConfigured -}}
4246
"link_state":"{{.SriovCniState}}",
4347
{{- end -}}

config/crd/bases/sriovnetwork.openshift.io_sriovibnetworks.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ spec:
6262
networkNamespace:
6363
description: Namespace of the NetworkAttachmentDefinition custom resource
6464
type: string
65+
pKey:
66+
type: string
6567
resourceName:
6668
description: SRIOV Network device plugin endpoint resource name
6769
type: string

controllers/generic_network_controller.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package controllers
1919
import (
2020
"context"
2121
"fmt"
22+
"strings"
2223

2324
netattdefv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
2425
corev1 "k8s.io/api/core/v1"
@@ -278,8 +279,32 @@ func (r *genericNetworkReconciler) deleteNetAttDef(ctx context.Context, cr Netwo
278279
if namespace == "" {
279280
namespace = cr.GetNamespace()
280281
}
281-
instance := &netattdefv1.NetworkAttachmentDefinition{ObjectMeta: metav1.ObjectMeta{Name: cr.GetName(), Namespace: namespace}}
282-
err := r.Delete(ctx, instance)
282+
283+
// First get the NetworkAttachmentDefinition to check if GUIDSavedInUFM is True
284+
instance := &netattdefv1.NetworkAttachmentDefinition{}
285+
err := r.Get(ctx, types.NamespacedName{Name: cr.GetName(), Namespace: namespace}, instance)
286+
if err != nil {
287+
if errors.IsNotFound(err) {
288+
return nil
289+
}
290+
return err
291+
}
292+
293+
// Check the GUIDSavedInUFM in the spec's config JSON
294+
// The CNI config is a JSON string in the spec
295+
if instance.Spec.Config != "" {
296+
// Check if the config contains "GUIDSavedInUFM": "true"
297+
if strings.Contains(instance.Spec.Config, `"GUIDSavedInUFM": "true"`) {
298+
// Skip deletion because GUIDSavedInUFM is True
299+
logger := log.Log.WithName("deleteNetAttDef")
300+
logger.Info("Skipping NetworkAttachmentDefinition deletion because GUIDSavedInUFM is true in spec",
301+
"Namespace", namespace, "Name", cr.GetName())
302+
return nil
303+
}
304+
}
305+
306+
// Proceed with deletion since GUIDSavedInUFM is not True
307+
err = r.Delete(ctx, instance)
283308
if err != nil {
284309
if errors.IsNotFound(err) {
285310
return nil

deployment/sriov-network-operator-chart/crds/sriovnetwork.openshift.io_sriovibnetworks.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ spec:
6262
networkNamespace:
6363
description: Namespace of the NetworkAttachmentDefinition custom resource
6464
type: string
65+
pKey:
66+
type: string
6567
resourceName:
6668
description: SRIOV Network device plugin endpoint resource name
6769
type: string

pkg/consts/constants.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ const (
143143
KernelArgPciRealloc = "pci=realloc"
144144
KernelArgIntelIommu = "intel_iommu=on"
145145
KernelArgIommuPt = "iommu=pt"
146+
KernelArgIommuOn = "iommu=on"
146147
KernelArgRdmaShared = "ib_core.netns_mode=1"
147148
KernelArgRdmaExclusive = "ib_core.netns_mode=0"
148149

pkg/helper/mock/mock_helper.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/host/internal/infiniband/infiniband.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import (
55
"fmt"
66
"io/fs"
77
"net"
8+
"os"
9+
"path/filepath"
10+
"strconv"
11+
"strings"
812

913
"github.com/vishvananda/netlink"
1014
"sigs.k8s.io/controller-runtime/pkg/log"
@@ -55,6 +59,29 @@ func (i *infiniband) ConfigureVfGUID(vfAddr string, pfAddr string, vfID int, pfL
5559
return i.applyVfGUIDToInterface(guid, vfAddr, vfID, pfLink)
5660
}
5761

62+
// GetVfGUID gets a GUID from sysfs for an IB VF device
63+
func (i *infiniband) GetVfGUID(vfAddr string, pfAddr string, vfID int) (net.HardwareAddr, error) {
64+
guidPath := filepath.Join(consts.SysBusPciDevices, pfAddr, "sriov", strconv.Itoa(vfID), "node")
65+
data, err := os.ReadFile(guidPath)
66+
if err != nil {
67+
if os.IsNotExist(err) {
68+
log.Log.Info("GetVfGUID(): GUID file doesn't exist", "path", guidPath)
69+
return nil, nil
70+
}
71+
return nil, fmt.Errorf("failed to read GUID file %s: %v", guidPath, err)
72+
}
73+
guidStr := strings.TrimSpace(string(data))
74+
if guidStr == "" {
75+
return nil, nil
76+
}
77+
guid, err := net.ParseMAC(guidStr)
78+
if err != nil {
79+
return nil, fmt.Errorf("failed to parse GUID %s: %v", guidStr, err)
80+
}
81+
log.Log.Info("GetVfGUID(): found guid", "guid", guid)
82+
return guid, nil
83+
}
84+
5885
func (i *infiniband) applyVfGUIDToInterface(guid net.HardwareAddr, vfAddr string, vfID int, pfLink netlink.Link) error {
5986
if err := i.netlinkLib.LinkSetVfNodeGUID(pfLink, vfID, guid); err != nil {
6087
return err

0 commit comments

Comments
 (0)