Skip to content

Commit

Permalink
rollback partially
Browse files Browse the repository at this point in the history
  • Loading branch information
punkerpunker committed Jan 31, 2025
1 parent 55224df commit 41e516f
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 114 deletions.
98 changes: 0 additions & 98 deletions api/v1/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -724,104 +724,6 @@ func (s *SriovNetworkNodeState) GetDriverByPciAddress(addr string) string {
return ""
}

// RenderNetAttDefWithGUID renders a net-att-def with GUID for ib-sriov CNI
func (cr *SriovIBNetwork) RenderNetAttDefWithGUID(status SriovNetworkNodeStateStatus) (*uns.Unstructured, error) {
logger := log.WithName("RenderNetAttDefWithGUID")
logger.Info("Start to render IB SRIOV CNI NetworkAttachmentDefinition")

// Extract index from network name, tt usually comes with a digit at the end
// We're using this digit to distinguish between them and map a proper VF GUID in the NetAttachDef
re := regexp.MustCompile(`(\d+)$`)
matches := re.FindStringSubmatch(cr.Name)
interfaceIndex := 0 // default to first interface if no number found
if len(matches) > 1 {
if idx, err := strconv.Atoi(matches[1]); err == nil {
interfaceIndex = idx
}
}

// render RawCNIConfig manifests

data := render.MakeRenderData()
data.Data["CniType"] = CniType

data.Data["pKeyConfigured"] = true
data.Data["pKey"] = cr.Spec.PKey
data.Data["SriovNetworkName"] = cr.Name
if cr.Spec.NetworkNamespace == "" {
data.Data["SriovNetworkNamespace"] = cr.Namespace
} else {
data.Data["SriovNetworkNamespace"] = cr.Spec.NetworkNamespace
}

data.Data["SriovCniResourceName"] = os.Getenv("RESOURCE_PREFIX") + "/" + cr.Spec.ResourceName
data.Data["GUIDConfigured"] = false
if cr.Spec.ScanGUIDs {
data.Data["GUIDConfigured"] = true
logger.Info("Getting GUID from SriovNetworkNodeState")
if guid := GetGUIDFromSriovNetworkNodeStateStatus(status, interfaceIndex-1); guid != "" {
data.Data["GUID"] = guid
logger.Info(fmt.Sprintf("Found GUID in SriovNetworkNodeState: %s", guid))
}
}

data.Data["StateConfigured"] = true
switch cr.Spec.LinkState {
case SriovCniStateEnable:
data.Data["SriovCniState"] = SriovCniStateEnable
case SriovCniStateDisable:
data.Data["SriovCniState"] = SriovCniStateDisable
case SriovCniStateAuto:
data.Data["SriovCniState"] = SriovCniStateAuto
default:
data.Data["StateConfigured"] = false
}

if cr.Spec.Capabilities == "" {
data.Data["CapabilitiesConfigured"] = false
} else {
data.Data["CapabilitiesConfigured"] = true
data.Data["SriovCniCapabilities"] = cr.Spec.Capabilities
}

if cr.Spec.IPAM != "" {
data.Data["SriovCniIpam"] = SriovCniIpam + ":" + strings.Join(strings.Fields(cr.Spec.IPAM), "")
} else {
data.Data["SriovCniIpam"] = SriovCniIpamEmpty
}

// metaplugins for the infiniband cni
data.Data["MetaPluginsConfigured"] = false
if cr.Spec.MetaPluginsConfig != "" {
data.Data["MetaPluginsConfigured"] = true
data.Data["MetaPlugins"] = cr.Spec.MetaPluginsConfig
}

// logLevel and logFile are currently not supported by the ib-sriov-cni
data.Data["LogLevelConfigured"] = false
data.Data["LogFileConfigured"] = false

objs, err := render.RenderDir(filepath.Join(ManifestsPath, "sriov"), &data)
if err != nil {
return nil, err
}
for _, obj := range objs {
raw, _ := json.Marshal(obj)
logger.Info("render NetworkAttachmentDefinition output", "raw", string(raw))
}
return objs[0], nil
}

func (cr *SriovNetwork) RenderNetAttDefWithGUID(status SriovNetworkNodeStateStatus) (*uns.Unstructured, error) {
// Not implemented
return cr.RenderNetAttDef()
}

func (cr *OVSNetwork) RenderNetAttDefWithGUID(status SriovNetworkNodeStateStatus) (*uns.Unstructured, error) {
// Not implemented
return cr.RenderNetAttDef()
}

// RenderNetAttDef renders a net-att-def for ib-sriov CNI
func (cr *SriovIBNetwork) RenderNetAttDef() (*uns.Unstructured, error) {
logger := log.WithName("RenderNetAttDef")
Expand Down
1 change: 0 additions & 1 deletion api/v1/sriovibnetwork_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ type SriovIBNetworkSpec struct {
// by the operator.
MetaPluginsConfig string `json:"metaPlugins,omitempty"`
PKey string `json:"pKey,omitempty"`
ScanGUIDs bool `json:"scanGuids,omitempty"`
}

// SriovIBNetworkStatus defines the observed state of SriovIBNetwork
Expand Down
6 changes: 0 additions & 6 deletions bindata/manifests/cni-config/sriov/sriov-cni-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ spec:
"max_tx_rate":{{.SriovCniMaxTxRate}},
{{- end -}}
{{- end -}}
{{- if .pKeyConfigured -}}
"pkey":"{{.pKey}}",
{{- end -}}
{{- if .GUIDConfigured -}}
"guid":"{{.GUID}}",
{{- end -}}
{{- if .CapabilitiesConfigured -}}
"capabilities":{{.SriovCniCapabilities}},
{{- end -}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ spec:
resourceName:
description: SRIOV Network device plugin endpoint resource name
type: string
scanGuids:
type: boolean
required:
- resourceName
type: object
Expand Down
6 changes: 1 addition & 5 deletions controllers/generic_network_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ type networkCRInstance interface {
client.Object
// renders NetAttDef from the network instance
RenderNetAttDef() (*uns.Unstructured, error)
// RenderNetAttDefWithGUID renders NetAttDef with GUID (if available)
RenderNetAttDefWithGUID(status sriovnetworkv1.SriovNetworkNodeStateStatus) (*uns.Unstructured, error)
// return name of the target namespace for the network
NetworkNamespace() string
}
Expand Down Expand Up @@ -141,9 +139,7 @@ func (r *genericNetworkReconciler) Reconcile(ctx context.Context, req ctrl.Reque
return ctrl.Result{RequeueAfter: time.Second * 5}, nil
}

nodeState := nodeStateList.Items[0]
reqLogger.Info("Starting RenderNetAttDefWithGUID")
raw, err := instance.RenderNetAttDefWithGUID(nodeState.Status)
raw, err := instance.RenderNetAttDef()

if err != nil {
reqLogger.Error(err, "Failed to render NetworkAttachmentDefinition")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ spec:
resourceName:
description: SRIOV Network device plugin endpoint resource name
type: string
scanGuids:
type: boolean
required:
- resourceName
type: object
Expand Down
1 change: 1 addition & 0 deletions pkg/host/internal/infiniband/infiniband.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func (i *infiniband) GetVfGUID(vfAddr string, pfAddr string, vfID int) (net.Hard
if err != nil {
return nil, fmt.Errorf("failed to parse GUID %s: %v", guidStr, err)
}
log.Log.Info("GetVfGUID(): found guid", "guid", guid)
return guid, nil
}

Expand Down

0 comments on commit 41e516f

Please sign in to comment.