Skip to content

Commit

Permalink
Fix api/v1/helper logging
Browse files Browse the repository at this point in the history
  • Loading branch information
e0ne committed Sep 20, 2023
1 parent 7c2116e commit 4c1385b
Showing 1 changed file with 20 additions and 25 deletions.
45 changes: 20 additions & 25 deletions api/v1/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ import (
"strconv"
"strings"

"github.com/golang/glog"

netattdefv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/render"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
uns "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes"
"sigs.k8s.io/controller-runtime/pkg/client"
logf "sigs.k8s.io/controller-runtime/pkg/log"

"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/render"
)

const (
Expand All @@ -41,7 +41,6 @@ const (
const invalidVfIndex = -1

var ManifestsPath = "./bindata/manifests/cni-config"
var log = logf.Log.WithName("sriovnetwork")

// NicIDMap contains supported mapping of IDs with each in the format of:
// Vendor ID, Physical Function Device ID, Virtual Function Device ID
Expand Down Expand Up @@ -121,7 +120,7 @@ func IsSupportedModel(vendorID, deviceID string) bool {
return true
}
}
log.Info("IsSupportedModel():", "Unsupported model:", "vendorId:", vendorID, "deviceId:", deviceID)
glog.Infof("IsSupportedModel(): Unsupported model: vendorId=%s, deviceId=%s", vendorID, deviceID)
return false
}

Expand All @@ -132,7 +131,7 @@ func IsVfSupportedModel(vendorID, deviceID string) bool {
return true
}
}
log.Info("IsVfSupportedModel():", "Unsupported VF model:", "vendorId:", vendorID, "deviceId:", deviceID)
glog.Infof("IsVfSupportedModel(): Unsupported VF model: vendorId=%s, deviceId=%s", vendorID, deviceID)
return false
}

Expand All @@ -152,32 +151,32 @@ func IsValidPciString(nicIDString string) bool {
ids := strings.Split(nicIDString, " ")

if len(ids) != 3 {
log.Info("IsValidPciString(): ", nicIDString)
glog.Infof("IsValidPciString(): nicIDString=%s", nicIDString)
return false
}

if len(ids[0]) != 4 {
log.Info("IsValidPciString():", "Invalid vendor PciId ", ids[0])
glog.Infof("IsValidPciString(): Invalid vendor PciId=%s", ids[0])
return false
}
if _, err := strconv.ParseInt(ids[0], 16, 32); err != nil {
log.Info("IsValidPciString():", "Invalid vendor PciId ", ids[0])
glog.Infof("IsValidPciString(): Invalid vendor PciId=%s ", ids[0])
}

if len(ids[1]) != 4 {
log.Info("IsValidPciString():", "Invalid PciId of PF ", ids[1])
glog.Infof("IsValidPciString(): Invalid PciId of PF %s", ids[1])
return false
}
if _, err := strconv.ParseInt(ids[1], 16, 32); err != nil {
log.Info("IsValidPciString():", "Invalid PciId of PF ", ids[1])
glog.Infof("IsValidPciString(): Invalid PciId of PF %s", ids[1])
}

if len(ids[2]) != 4 {
log.Info("IsValidPciString():", "Invalid PciId of VF ", ids[2])
glog.Infof("IsValidPciString(): Invalid PciId of VF %s", ids[2])
return false
}
if _, err := strconv.ParseInt(ids[2], 16, 32); err != nil {
log.Info("IsValidPciString():", "Invalid PciId of VF ", ids[2])
glog.Infof("IsValidPciString(): Invalid PciId of VF %s", ids[2])
}

return true
Expand Down Expand Up @@ -280,7 +279,7 @@ func (p *SriovNetworkNodePolicy) Apply(state *SriovNetworkNodeState, equalPriori
}
for _, iface := range state.Status.Interfaces {
if s.Selected(&iface) {
log.Info("Update interface", "name:", iface.Name)
glog.Infof("Update interface name: %s", iface.Name)
result := Interface{
PciAddress: iface.PciAddress,
Mtu: p.Spec.Mtu,
Expand Down Expand Up @@ -367,7 +366,7 @@ func (p *SriovNetworkNodePolicy) generateVfGroup(iface *InterfaceExt) (*VfGroup,
for _, selector := range p.Spec.NicSelector.PfNames {
pfName, rngStart, rngEnd, err = ParsePFName(selector)
if err != nil {
log.Error(err, "Unable to parse PF Name.")
glog.Error(err, "Unable to parse PF Name.")
return nil, err
}
if pfName == iface.Name {
Expand Down Expand Up @@ -482,8 +481,7 @@ func (s *SriovNetworkNodeState) GetDriverByPciAddress(addr string) string {

// RenderNetAttDef renders a net-att-def for ib-sriov CNI
func (cr *SriovIBNetwork) RenderNetAttDef() (*uns.Unstructured, error) {
logger := log.WithName("renderNetAttDef")
logger.Info("Start to render IB SRIOV CNI NetworkAttachementDefinition")
glog.Info("RenderNetAttDef(): Start to render IB SRIOV CNI NetworkAttachementDefinition")

// render RawCNIConfig manifests
data := render.MakeRenderData()
Expand Down Expand Up @@ -534,7 +532,7 @@ func (cr *SriovIBNetwork) RenderNetAttDef() (*uns.Unstructured, error) {
}
for _, obj := range objs {
raw, _ := json.Marshal(obj)
logger.Info("render NetworkAttachementDefinition output", "raw", string(raw))
glog.Infof("RenderNetAttDef(): render NetworkAttachementDefinition output: %s", string(raw))
}
return objs[0], nil
}
Expand Down Expand Up @@ -563,8 +561,7 @@ func (cr *SriovIBNetwork) DeleteNetAttDef(c client.Client) error {

// RenderNetAttDef renders a net-att-def for sriov CNI
func (cr *SriovNetwork) RenderNetAttDef() (*uns.Unstructured, error) {
logger := log.WithName("renderNetAttDef")
logger.Info("Start to render SRIOV CNI NetworkAttachementDefinition")
glog.Info("RenderNetAttDef(): Start to render SRIOV CNI NetworkAttachementDefinition")

// render RawCNIConfig manifests
data := render.MakeRenderData()
Expand Down Expand Up @@ -658,7 +655,7 @@ func (cr *SriovNetwork) RenderNetAttDef() (*uns.Unstructured, error) {
}
for _, obj := range objs {
raw, _ := json.Marshal(obj)
logger.Info("render NetworkAttachementDefinition output", "raw", string(raw))
glog.Infof("RenderNetAttDef(): render NetworkAttachementDefinition output: %s", string(raw))
}
return objs[0], nil
}
Expand Down Expand Up @@ -687,21 +684,19 @@ func (cr *SriovNetwork) DeleteNetAttDef(c client.Client) error {

// NetFilterMatch -- parse netFilter and check for a match
func NetFilterMatch(netFilter string, netValue string) (isMatch bool) {
logger := log.WithName("NetFilterMatch")

var re = regexp.MustCompile(`(?m)^\s*([^\s]+)\s*:\s*([^\s]+)`)

netFilterResult := re.FindAllStringSubmatch(netFilter, -1)

if netFilterResult == nil {
logger.Info("Invalid NetFilter spec...", "netFilter", netFilter)
glog.Infof("NetFilterMatch(): Invalid NetFilter spec: %s", netFilter)
return false
}

netValueResult := re.FindAllStringSubmatch(netValue, -1)

if netValueResult == nil {
logger.Info("Invalid netValue...", "netValue", netValue)
glog.Infof("Invalid netValue: %s", netValue)
return false
}

Expand Down

0 comments on commit 4c1385b

Please sign in to comment.