github.com/k8snetworkplumbingwg/sriov-network-operator@v1.2.1-0.20240408194816-2d2e5a45d453/pkg/helper/host.go (about) 1 package helper 2 3 import ( 4 "sigs.k8s.io/controller-runtime/pkg/log" 5 6 "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host" 7 "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/store" 8 "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/utils" 9 mlx "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/vendors/mellanox" 10 ) 11 12 //go:generate ../../bin/mockgen -destination mock/mock_helper.go -source host.go 13 type HostHelpersInterface interface { 14 utils.CmdInterface 15 host.HostManagerInterface 16 store.ManagerInterface 17 mlx.MellanoxInterface 18 } 19 20 type hostHelpers struct { 21 utils.CmdInterface 22 host.HostManagerInterface 23 store.ManagerInterface 24 mlx.MellanoxInterface 25 } 26 27 // Use for unit tests 28 func NewHostHelpers(utilsHelper utils.CmdInterface, 29 hostManager host.HostManagerInterface, 30 storeManager store.ManagerInterface, 31 mlxHelper mlx.MellanoxInterface) HostHelpersInterface { 32 return &hostHelpers{utilsHelper, hostManager, storeManager, mlxHelper} 33 } 34 35 func NewDefaultHostHelpers() (HostHelpersInterface, error) { 36 utilsHelper := utils.New() 37 mlxHelper := mlx.New(utilsHelper) 38 hostManager := host.NewHostManager(utilsHelper) 39 storeManager, err := store.NewManager() 40 if err != nil { 41 log.Log.Error(err, "failed to create store manager") 42 return nil, err 43 } 44 45 return &hostHelpers{ 46 utilsHelper, 47 hostManager, 48 storeManager, 49 mlxHelper}, nil 50 }