diff --git a/pkg/utils/mock/mock_store.go b/pkg/utils/mock/mock_store.go index 1527f611ef..d6ff6b8fdd 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 4db7b86ce8..2356db1377 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 0050725d91..30124cdb00 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -135,10 +135,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 +196,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 +217,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 diff --git a/pkg/webhook/validate.go b/pkg/webhook/validate.go index 624577df23..826b445168 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