Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update fec scheme for v2 api #873

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/sync/configs/fec-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
sync: true
repo_link: "https://github.com/intel/sriov-fec-operator"
branch: main
remote_api_directory: api/sriovfec/v1
remote_api_directory: api/sriovfec/v2
local_api_directory: schemes/fec/fectypes
...
19 changes: 2 additions & 17 deletions pkg/schemes/fec/fectypes/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2020-2024 Intel Corporation

/*

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1 contains API Schema definitions for the sriovfec v1 API group
// Package v2 contains API Schema definitions for the sriovfec v2 API group
// +kubebuilder:object:generate=true
// +groupName=sriovfec.intel.com
package fectypes
Expand All @@ -28,7 +13,7 @@ import (

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "sriovfec.intel.com", Version: "v1"}
GroupVersion = schema.GroupVersion{Group: "sriovfec.intel.com", Version: "v2"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
Expand Down
60 changes: 60 additions & 0 deletions pkg/schemes/fec/fectypes/helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2020-2024 Intel Corporation

package fectypes

import (
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"reflect"
)

type ByPriority []SriovFecClusterConfig

func (a ByPriority) Len() int {
return len(a)
}

func (a ByPriority) Less(i, j int) bool {
if a[i].Spec.Priority != a[j].Spec.Priority {
return a[i].Spec.Priority > a[j].Spec.Priority
}
return a[i].GetName() < a[j].GetName()
}

func (a ByPriority) Swap(i, j int) {
a[i], a[j] = a[j], a[i]
}

func (s AcceleratorSelector) Matches(a SriovAccelerator) bool {
return s.isVendorMatching(a) && s.isPciAddressMatching(a) &&
s.isPFDriverMatching(a) && s.isMaxVFsMatching(a) && s.isDeviceIDMatching(a)
}

func (s AcceleratorSelector) isVendorMatching(a SriovAccelerator) bool {
return s.VendorID == "" || s.VendorID == a.VendorID
}

func (s AcceleratorSelector) isPciAddressMatching(a SriovAccelerator) bool {
return s.PCIAddress == "" || s.PCIAddress == a.PCIAddress
}

func (s AcceleratorSelector) isPFDriverMatching(a SriovAccelerator) bool {
return s.PFDriver == "" || s.PFDriver == a.PFDriver
}

func (s AcceleratorSelector) isMaxVFsMatching(a SriovAccelerator) bool {
return s.MaxVFs == 0 || s.MaxVFs == a.MaxVFs
}

func (s AcceleratorSelector) isDeviceIDMatching(a SriovAccelerator) bool {
return s.DeviceID == "" || s.DeviceID == a.DeviceID
}

func (in *SriovFecNodeConfig) FindCondition(conditionType string) *metav1.Condition {
return meta.FindStatusCondition(in.Status.Conditions, conditionType)
}

func isNil(v interface{}) bool {
return v == nil || (reflect.ValueOf(v).Kind() == reflect.Ptr && reflect.ValueOf(v).IsNil())
}
146 changes: 124 additions & 22 deletions pkg/schemes/fec/fectypes/sriovfecclusterconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import (

type SyncStatus string

const (
acc100maxQueueGroups = 8
acc200maxQueueGroups = 16
)

var (
// InProgressSync indicates that the synchronization of the CR is in progress
InProgressSync SyncStatus = "InProgress"
Expand Down Expand Up @@ -66,7 +71,10 @@ type UplinkDownlink struct {
type N3000BBDevConfig struct {
// +kubebuilder:validation:Enum=FPGA_5GNR;FPGA_LTE
NetworkType string `json:"networkType"`
PFMode bool `json:"pfMode"`
// +kubebuilder:validation:Optional
// +kubebuilder:default:false
// +kubebuilder:validation:Enum=false
PFMode bool `json:"pfMode,omitempty"`
// +kubebuilder:validation:Minimum=0
FLRTimeOut int `json:"flrTimeout"`
Downlink UplinkDownlink `json:"downlink"`
Expand All @@ -75,67 +83,160 @@ type N3000BBDevConfig struct {

type QueueGroupConfig struct {
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=8
// +kubebuilder:validation:Maximum=16
NumQueueGroups int `json:"numQueueGroups"`
// +kubebuilder:validation:Minimum=16
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=16
NumAqsPerGroups int `json:"numAqsPerGroups"`
// +kubebuilder:validation:Minimum=4
// +kubebuilder:validation:Maximum=4
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=12
AqDepthLog2 int `json:"aqDepthLog2"`
}

// ACC100BBDevConfig specifies variables to configure ACC100 with
type ACC100BBDevConfig struct {
PFMode bool `json:"pfMode"`
// +kubebuilder:validation:Minimum=16
// +kubebuilder:validation:Optional
// +kubebuilder:default:false
// +kubebuilder:validation:Enum=false
PFMode bool `json:"pfMode,omitempty"`
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=16
NumVfBundles int `json:"numVfBundles"`
// +kubebuilder:validation:Minimum=1024
// +kubebuilder:validation:Maximum=1024
MaxQueueSize int `json:"maxQueueSize"`
// +kubebuilder:default:1024
// +kubebuilder:validation:Optional
MaxQueueSize int `json:"maxQueueSize,omitempty"`
Uplink4G QueueGroupConfig `json:"uplink4G"`
Downlink4G QueueGroupConfig `json:"downlink4G"`
Uplink5G QueueGroupConfig `json:"uplink5G"`
Downlink5G QueueGroupConfig `json:"downlink5G"`
}

func (in *ACC100BBDevConfig) Validate() error {
totalQueueGroups := in.Uplink4G.NumQueueGroups + in.Downlink4G.NumQueueGroups + in.Uplink5G.NumQueueGroups + in.Downlink5G.NumQueueGroups
if totalQueueGroups > acc100maxQueueGroups {
return fmt.Errorf("total number of requested queue groups (4G/5G) %v exceeds the maximum (%d)", totalQueueGroups, acc100maxQueueGroups)
}
return nil
}

// FFTLutParam specifies variables required to use custom fft bin file
type FFTLutParam struct {
// Path to .tar.gz SRS-FFT file
// +kubebuilder:validation:Pattern=`^((http|https)://.*\.tar\.gz)?$`
FftUrl string `json:"fftUrl"`
// SHA-1 checksum of .tar.gz SRS-FFT File
// +kubebuilder:validation:Pattern=`^([a-fA-F0-9]{40})?$`
FftChecksum string `json:"fftChecksum"`
}

// ACC200BBDevConfig specifies variables to configure ACC200 with
type ACC200BBDevConfig struct {
ACC100BBDevConfig `json:",inline"`
QFFT QueueGroupConfig `json:"qfft"`
FFTLut FFTLutParam `json:"fftLut,omitempty"`
}

func (in *ACC200BBDevConfig) Validate() error {
totalQueueGroups := in.Uplink4G.NumQueueGroups + in.Downlink4G.NumQueueGroups + in.Uplink5G.NumQueueGroups + in.Downlink5G.NumQueueGroups + in.QFFT.NumQueueGroups
if totalQueueGroups > acc200maxQueueGroups {
return fmt.Errorf("total number of requested queue groups (4G/5G/QFFT) %v exceeds the maximum (%d)", totalQueueGroups, acc200maxQueueGroups)
}
return nil
}

// BBDevConfig is a struct containing configuration for various FEC cards
type BBDevConfig struct {
N3000 *N3000BBDevConfig `json:"n3000,omitempty"`
ACC100 *ACC100BBDevConfig `json:"acc100,omitempty"`
ACC200 *ACC200BBDevConfig `json:"acc200,omitempty"`
}

type validator interface {
Validate() error
}

func (in *BBDevConfig) Validate() error {

for _, config := range []interface{}{in.ACC200, in.ACC100, in.N3000} {
if !isNil(config) {
if validator, ok := config.(validator); ok {
return validator.Validate()
}
}
}

return nil
}

// PhysicalFunctionConfig defines a possible configuration of a single Physical Function (PF), i.e. card
type PhysicalFunctionConfig struct {
// PFDriver to bound the PFs to
//+kubebuilder:validation:Pattern=`(pci-pf-stub|pci_pf_stub|igb_uio|vfio-pci)`
PFDriver string `json:"pfDriver"`
// VFDriver to bound the VFs to
VFDriver string `json:"vfDriver"`
// VFAmount is an amount of VFs to be created
// +kubebuilder:validation:Minimum=1
VFAmount int `json:"vfAmount"`
// BBDevConfig is a config for PF's queues
BBDevConfig BBDevConfig `json:"bbDevConfig"`
}

type PhysicalFunctionConfigExt struct {
// PCIAdress is a Physical Functions's PCI address that will be configured according to this spec
// +kubebuilder:validation:Pattern=`^[a-fA-F0-9]{4}:[a-fA-F0-9]{2}:[01][a-fA-F0-9]\.[0-7]$`
PCIAddress string `json:"pciAddress"`

// PFDriver to bound the PFs to
//+kubebuilder:validation:Pattern=`(pci-pf-stub|pci_pf_stub|igb_uio|vfio-pci)`
PFDriver string `json:"pfDriver"`

// VFDriver to bound the VFs to
VFDriver string `json:"vfDriver"`

// VFAmount is an amount of VFs to be created
// +kubebuilder:validation:Minimum=0
VFAmount int `json:"vfAmount"`

// BBDevConfig is a config for PF's queues
BBDevConfig BBDevConfig `json:"bbDevConfig"`
}

type NodeConfig struct {
// Name of the node
NodeName string `json:"nodeName"`
// List of physical functions (cards) configs
// +operator-sdk:csv:customresourcedefinitions:type=spec
PhysicalFunctions []PhysicalFunctionConfig `json:"physicalFunctions"`
}

// SriovFecClusterConfigSpec defines the desired state of SriovFecClusterConfig
type SriovFecClusterConfigSpec struct {
// List of node configurations

// +operator-sdk:csv:customresourcedefinitions:type=spec
Nodes []NodeConfig `json:"nodes"`
DrainSkip bool `json:"drainSkip,omitempty"`
// Selector describes target node for this spec
NodeSelector map[string]string `json:"nodeSelector,omitempty"`

// +operator-sdk:csv:customresourcedefinitions:type=spec
// Selector describes target accelerator for this spec
AcceleratorSelector AcceleratorSelector `json:"acceleratorSelector,omitempty"`

// +operator-sdk:csv:customresourcedefinitions:type=spec
// Physical function (card) config
PhysicalFunction PhysicalFunctionConfig `json:"physicalFunction"`

// +operator-sdk:csv:customresourcedefinitions:type=spec
// Higher priority policies can override lower ones.
Priority int `json:"priority,omitempty"`

// +operator-sdk:csv:customresourcedefinitions:type=spec
// Skips drain process when true; default false. Should be true if operator is running on SNO
DrainSkip *bool `json:"drainSkip,omitempty"`
}

type AcceleratorSelector struct {
VendorID string `json:"vendorID,omitempty"`
DeviceID string `json:"deviceID,omitempty"`
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Pattern=`^[a-fA-F0-9]{4}:[a-fA-F0-9]{2}:[01][a-fA-F0-9]\.[0-7]$`
PCIAddress string `json:"pciAddress,omitempty"`
//+kubebuilder:validation:Pattern=`(pci-pf-stub|pci_pf_stub|igb_uio|vfio-pci)`
PFDriver string `json:"driver,omitempty"`
MaxVFs int `json:"maxVirtualFunctions,omitempty"`
}

// SriovFecClusterConfigStatus defines the observed state of SriovFecClusterConfig
Expand All @@ -148,10 +249,11 @@ type SriovFecClusterConfigStatus struct {

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="SyncStatus",type=string,JSONPath=`.status.syncStatus`
// +kubebuilder:unservedversion
// +kubebuilder:storageversion
// +kubebuilder:resource:shortName=sfcc

// SriovFecClusterConfig is the Schema for the sriovfecclusterconfigs API
// +operator-sdk:csv:customresourcedefinitions:displayName="SriovFecClusterConfig",resources={{SriovFecNodeConfig,v1,node}}
// +operator-sdk:csv:customresourcedefinitions:displayName="SriovFecClusterConfig",resources={{SriovFecNodeConfig,v2,node}}
type SriovFecClusterConfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
14 changes: 10 additions & 4 deletions pkg/schemes/fec/fectypes/sriovfecnodeconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type SriovAccelerator struct {
VendorID string `json:"vendorID"`
DeviceID string `json:"deviceID"`
PCIAddress string `json:"pciAddress"`
Driver string `json:"driver"`
PFDriver string `json:"driver"`
MaxVFs int `json:"maxVirtualFunctions"`
VFs []VF `json:"virtualFunctions"`
}
Expand All @@ -30,12 +30,16 @@ type NodeInventory struct {
type SriovFecNodeConfigSpec struct {
// List of PhysicalFunctions configs
// +operator-sdk:csv:customresourcedefinitions:type=spec
PhysicalFunctions []PhysicalFunctionConfig `json:"physicalFunctions"`
DrainSkip bool `json:"drainSkip,omitempty"`
PhysicalFunctions []PhysicalFunctionConfigExt `json:"physicalFunctions"`

// +operator-sdk:csv:customresourcedefinitions:type=spec
// Skips drain process when true; default false. Should be true if operator is running on SNO
DrainSkip bool `json:"drainSkip,omitempty"`
}

// SriovFecNodeConfigStatus defines the observed state of SriovFecNodeConfig
type SriovFecNodeConfigStatus struct {
PfBbConfVersion string `json:"pfBbConfVersion,omitempty"`
// Provides information about device update status
Conditions []metav1.Condition `json:"conditions,omitempty"`
// Provides information about FPGA inventory on the node
Expand All @@ -46,7 +50,9 @@ type SriovFecNodeConfigStatus struct {
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Configured",type=string,JSONPath=`.status.conditions[?(@.type=="Configured")].reason`
// +kubebuilder:unservedversion
// +kubebuilder:storageversion
// +kubebuilder:resource:shortName=sfnc

// SriovFecNodeConfig is the Schema for the sriovfecnodeconfigs API
// +operator-sdk:csv:customresourcedefinitions:displayName="SriovFecNodeConfig",resources={{SriovFecNodeConfig,v1,node}}
type SriovFecNodeConfig struct {
Expand Down
Loading
Loading