diff --git a/pkg/utils/mock/mock_store.go b/pkg/utils/mock/mock_store.go index 1527f611e..d6ff6b8fd 100644 --- a/pkg/utils/mock/mock_store.go +++ b/pkg/utils/mock/mock_store.go @@ -65,15 +65,15 @@ func (mr *MockStoreManagerInterfaceMockRecorder) LoadPfsStatus(pciAddress interf } // SaveLastPfAppliedStatus mocks base method. -func (m *MockStoreManagerInterface) SaveLastPfAppliedStatus(pciAddress string, PfInfo *v1.Interface) error { +func (m *MockStoreManagerInterface) SaveLastPfAppliedStatus(PfInfo *v1.Interface) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SaveLastPfAppliedStatus", pciAddress, PfInfo) + ret := m.ctrl.Call(m, "SaveLastPfAppliedStatus", PfInfo) ret0, _ := ret[0].(error) return ret0 } // SaveLastPfAppliedStatus indicates an expected call of SaveLastPfAppliedStatus. -func (mr *MockStoreManagerInterfaceMockRecorder) SaveLastPfAppliedStatus(pciAddress, PfInfo interface{}) *gomock.Call { +func (mr *MockStoreManagerInterfaceMockRecorder) SaveLastPfAppliedStatus(PfInfo interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SaveLastPfAppliedStatus", reflect.TypeOf((*MockStoreManagerInterface)(nil).SaveLastPfAppliedStatus), pciAddress, PfInfo) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SaveLastPfAppliedStatus", reflect.TypeOf((*MockStoreManagerInterface)(nil).SaveLastPfAppliedStatus), PfInfo) } diff --git a/pkg/utils/store.go b/pkg/utils/store.go index 4db7b86ce..2356db137 100644 --- a/pkg/utils/store.go +++ b/pkg/utils/store.go @@ -22,7 +22,7 @@ const ( //go:generate ../../bin/mockgen -destination mock/mock_store.go -source store.go type StoreManagerInterface interface { ClearPCIAddressFolder() error - SaveLastPfAppliedStatus(pciAddress string, PfInfo *sriovnetworkv1.Interface) error + SaveLastPfAppliedStatus(PfInfo *sriovnetworkv1.Interface) error LoadPfsStatus(pciAddress string) (*sriovnetworkv1.Interface, bool, error) } @@ -82,7 +82,7 @@ func (s *StoreManager) ClearPCIAddressFolder() error { if os.IsNotExist(err) { return nil } - return fmt.Errorf("failed to check the pci address folder path %s", PfAppliedConfigUse) + return fmt.Errorf("failed to check the pci address folder path %s: %v", PfAppliedConfigUse, err) } err = os.RemoveAll(PfAppliedConfigUse) @@ -100,7 +100,7 @@ func (s *StoreManager) ClearPCIAddressFolder() error { // SaveLastPfAppliedStatus will save the PF object as a json into the /etc/sriov-operator/pci/ // this function must be called after running the chroot function -func (s *StoreManager) SaveLastPfAppliedStatus(pciAddress string, PfInfo *sriovnetworkv1.Interface) error { +func (s *StoreManager) SaveLastPfAppliedStatus(PfInfo *sriovnetworkv1.Interface) error { data, err := json.Marshal(PfInfo) if err != nil { glog.Errorf("failed to marshal PF status %+v: %v", *PfInfo, err) @@ -108,7 +108,7 @@ func (s *StoreManager) SaveLastPfAppliedStatus(pciAddress string, PfInfo *sriovn } hostExtension := getHostExtension(s.RunOnHost) - pathFile := filepath.Join(hostExtension, PfAppliedConfig, pciAddress) + pathFile := filepath.Join(hostExtension, PfAppliedConfig, PfInfo.PciAddress) err = os.WriteFile(pathFile, data, 0644) return err } diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 0050725d9..c9aecd7ed 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -45,6 +45,7 @@ const ( udevFolder = "/etc/udev" udevRulesFolder = udevFolder + "/rules.d" udevDisableNM = "/bindata/scripts/udev-find-sriov-pf.sh" + nmUdevRule = "SUBSYSTEM==\"net\", ACTION==\"add|change|move\", ATTRS{device}==\"%s\", IMPORT{program}=\"/etc/udev/disable-nm-sriov.sh $env{INTERFACE} %s\"" ) var InitialState sriovnetworkv1.SriovNetworkNodeState @@ -135,10 +136,10 @@ func DiscoverSriovDevices(withUnsupported bool, storeManager StoreManagerInterfa pfStatus, exist, err := storeManager.LoadPfsStatus(iface.PciAddress) if err != nil { glog.Warningf("DiscoverSriovDevices(): failed to load PF status from disk: %v", err) - } - - if exist { - iface.ExternallyManaged = pfStatus.ExternallyManaged + } else { + if exist { + iface.ExternallyManaged = pfStatus.ExternallyManaged + } } if dputils.IsSriovPF(device.Address) { @@ -196,7 +197,7 @@ func ConfigSriovInterfaces(interfaces []sriovnetworkv1.Interface, ifaceStatuses glog.V(2).Infof("syncNodeState(): no need update interface %s", iface.PciAddress) // Save the PF status to the host - err = storeManager.SaveLastPfAppliedStatus(iface.PciAddress, &iface) + err = storeManager.SaveLastPfAppliedStatus(&iface) if err != nil { glog.Errorf("SyncNodeState(): failed to save PF applied config to host: %v", err) return err @@ -217,7 +218,7 @@ func ConfigSriovInterfaces(interfaces []sriovnetworkv1.Interface, ifaceStatuses } // Save the PF status to the host - err = storeManager.SaveLastPfAppliedStatus(iface.PciAddress, &iface) + err = storeManager.SaveLastPfAppliedStatus(&iface) if err != nil { glog.Errorf("SyncNodeState(): failed to save PF applied config to host: %v", err) return err @@ -930,9 +931,10 @@ func PrepareNMUdevRule(supportedVfIds []string) error { cmd.Stdout = &stdout cmd.Stderr = &stderr if err := cmd.Run(); err != nil { + glog.Errorf("PrepareNMUdevRule(): failed to prepare nmUdevRule, stderr %s: %v", stderr.String(), err) return err } - glog.V(2).Infof("PrepareNMUdevRule(): %v", cmd.Stdout) + glog.V(2).Infof("PrepareNMUdevRule(): %v", stdout.String()) //save the device list to use for udev rules SupportedVfIds = supportedVfIds @@ -942,7 +944,7 @@ func PrepareNMUdevRule(supportedVfIds []string) error { func AddUdevRule(pfPciAddress string) error { glog.V(2).Infof("AddUdevRule(): %s", pfPciAddress) pathFile := udevRulesFolder - udevRuleContent := fmt.Sprintf("SUBSYSTEM==\"net\", ACTION==\"add|change|move\", ATTRS{device}==\"%s\", IMPORT{program}=\"/etc/udev/disable-nm-sriov.sh $env{INTERFACE} %s\"", strings.Join(SupportedVfIds, "|"), pfPciAddress) + udevRuleContent := fmt.Sprintf(nmUdevRule, strings.Join(SupportedVfIds, "|"), pfPciAddress) err := os.MkdirAll(pathFile, os.ModePerm) if err != nil && !os.IsExist(err) { diff --git a/pkg/webhook/validate.go b/pkg/webhook/validate.go index 624577df2..826b44516 100644 --- a/pkg/webhook/validate.go +++ b/pkg/webhook/validate.go @@ -304,7 +304,7 @@ func validatePolicyForNodeState(policy *sriovnetworkv1.SriovNetworkNodePolicy, s } if policy.Spec.LinkType != "" && strings.ToLower(policy.Spec.LinkType) != strings.ToLower(iface.LinkType) { - return fmt.Errorf("LinkType(%d) in CR %s is not equal to the LinkType for the PF externally value(%d)", policy.Spec.Mtu, policy.GetName(), iface.Mtu) + return fmt.Errorf("LinkType(%s) in CR %s is not equal to the LinkType for the PF externally value(%s)", policy.Spec.LinkType, policy.GetName(), iface.LinkType) } } // vdpa: only mellanox cards are supported