Skip to content

Commit

Permalink
add flag --kubelet-root-dir
Browse files Browse the repository at this point in the history
  • Loading branch information
cyclinder committed Jan 8, 2025
1 parent 1536406 commit 686a578
Show file tree
Hide file tree
Showing 17 changed files with 96 additions and 82 deletions.
5 changes: 4 additions & 1 deletion cmd/sriovdp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ import (
)

const (
defaultConfig = "/etc/pcidp/config.json"
defaultConfig = "/etc/pcidp/config.json"
defaultKubeletDir = "/var/lib/kubelet"
)

// flagInit parse command line flags
func flagInit(cp *cliParams) {
flag.StringVar(&cp.kubeletRootDir, "kubelet-root-dir", defaultKubeletDir,
"kubelet root dir")
flag.StringVar(&cp.configFile, "config-file", defaultConfig,
"JSON device pool config file location")
flag.StringVar(&cp.resourcePrefix, "resource-prefix", "intel.com",
Expand Down
6 changes: 4 additions & 2 deletions cmd/sriovdp/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"encoding/json"
"fmt"
"os"
"path"

"github.com/golang/glog"
"github.com/jaypipes/ghw"
Expand All @@ -34,6 +35,7 @@ const (

// cliParams presents CLI parameters for SR-IOV Network Device Plugin
type cliParams struct {
kubeletRootDir string
configFile string
resourcePrefix string
useCdi bool
Expand All @@ -52,14 +54,14 @@ type resourceManager struct {

// newResourceManager initiates a new instance of resourceManager
func newResourceManager(cp *cliParams) *resourceManager {
pluginWatchMode := utils.DetectPluginWatchMode(types.SockDir)
pluginWatchMode := utils.DetectPluginWatchMode(path.Join(cp.kubeletRootDir, types.PluginRegistry))
if pluginWatchMode {
glog.Infof("Using Kubelet Plugin Registry Mode")
} else {
glog.Infof("Using Deprecated Device Plugin Registry Path")
}

rf := factory.NewResourceFactory(cp.resourcePrefix, socketSuffix, pluginWatchMode, cp.useCdi)
rf := factory.NewResourceFactory(cp.resourcePrefix, socketSuffix, cp.kubeletRootDir, pluginWatchMode, cp.useCdi)
dp := make(map[types.DeviceType]types.DeviceProvider)
for k := range types.SupportedDevices {
dp[k] = rf.GetDeviceProvider(k)
Expand Down
2 changes: 1 addition & 1 deletion cmd/sriovdp/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ var _ = Describe("Resource manager", func() {
_ = os.Unsetenv("GHW_CHROOT")
}()

rf := factory.NewResourceFactory("fake", "fake", true, false)
rf := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", true, false)

rm := &resourceManager{
rFactory: rf,
Expand Down
6 changes: 3 additions & 3 deletions pkg/accelerator/accelDeviceProvider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ var _ = Describe("AcceleratorProvider", func() {

defer fs.Use()()

rf := factory.NewResourceFactory("fake", "fake", true, false)
rf := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", true, false)
p := accelerator.NewAccelDeviceProvider(rf)
config := &types.ResourceConfig{
DeviceType: types.AcceleratorType,
Expand Down Expand Up @@ -148,7 +148,7 @@ var _ = Describe("AcceleratorProvider", func() {
Describe("getting Filtered devices", func() {
Context("using selectors", func() {
It("should correctly filter devices", func() {
rf := factory.NewResourceFactory("fake", "fake", false, false)
rf := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", false, false)
p := accelerator.NewAccelDeviceProvider(rf)
all := make([]types.HostDevice, 5)
mocked := make([]mocks.AccelDevice, 5)
Expand Down Expand Up @@ -218,7 +218,7 @@ var _ = Describe("AcceleratorProvider", func() {
Expect(actual).To(ConsistOf(matchingDevices))
})
It("should error if the selector index is out of bounds", func() {
rf := factory.NewResourceFactory("fake", "fake", false, false)
rf := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", false, false)
p := accelerator.NewAccelDeviceProvider(rf)
devs := make([]types.HostDevice, 0)

Expand Down
12 changes: 6 additions & 6 deletions pkg/accelerator/accelDevice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var _ = Describe("Accelerator", func() {
}
defer fs.Use()()

f := factory.NewResourceFactory("fake", "fake", true, false)
f := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", true, false)
in := newPciDeviceFn()
config := &types.ResourceConfig{}

Expand Down Expand Up @@ -99,7 +99,7 @@ var _ = Describe("Accelerator", func() {
}
defer fs.Use()()

f := factory.NewResourceFactory("fake", "fake", true, false)
f := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", true, false)
in := newPciDeviceFn()
config := &types.ResourceConfig{}

Expand All @@ -122,7 +122,7 @@ var _ = Describe("Accelerator", func() {
}
defer fs.Use()()

f := factory.NewResourceFactory("fake", "fake", true, false)
f := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", true, false)
in := newPciDeviceFn()
config := &types.ResourceConfig{}

Expand All @@ -146,7 +146,7 @@ var _ = Describe("Accelerator", func() {
}
defer fs.Use()()

f := factory.NewResourceFactory("fake", "fake", true, false)
f := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", true, false)
in := newPciDeviceFn()
config := &types.ResourceConfig{ExcludeTopology: true}

Expand All @@ -164,7 +164,7 @@ var _ = Describe("Accelerator", func() {
}
defer fs.Use()()

f := factory.NewResourceFactory("fake", "fake", true, false)
f := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", true, false)
in := newPciDeviceFn()
config := &types.ResourceConfig{}

Expand All @@ -185,7 +185,7 @@ var _ = Describe("Accelerator", func() {
}
defer fs.Use()()

f := factory.NewResourceFactory("fake", "fake", true, false)
f := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", true, false)
in := newPciDeviceFn()
config := &types.ResourceConfig{}

Expand Down
8 changes: 4 additions & 4 deletions pkg/auxnetdevice/auxNetDeviceProvider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
var _ = Describe("AuxNetDeviceProvider", func() {
DescribeTable("validating configuration",
func(rc *types.ResourceConfig, expected bool) {
rf := factory.NewResourceFactory("fake", "fake", true, false)
rf := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", true, false)
p := auxnetdevice.NewAuxNetDeviceProvider(rf)
actual := p.ValidConfig(rc)
Expect(actual).To(Equal(expected))
Expand Down Expand Up @@ -133,7 +133,7 @@ var _ = Describe("AuxNetDeviceProvider", func() {
On("GetAuxNetDevicesFromPci", "0000:02:00.0").Return([]string{}, nil)
utils.SetSriovnetProviderInst(&fakeSriovnetProvider)

rf := factory.NewResourceFactory("fake", "fake", true, false)
rf := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", true, false)
p := auxnetdevice.NewAuxNetDeviceProvider(rf)
config := &types.ResourceConfig{
DeviceType: types.AuxNetDeviceType,
Expand Down Expand Up @@ -181,7 +181,7 @@ var _ = Describe("AuxNetDeviceProvider", func() {
Describe("getting Filtered devices", func() {
Context("using selectors", func() {
It("should correctly filter devices", func() {
rf := factory.NewResourceFactory("fake", "fake", false, false)
rf := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", false, false)
p := auxnetdevice.NewAuxNetDeviceProvider(rf)
all := make([]types.HostDevice, 5)
mocked := make([]tmocks.AuxNetDevice, 5)
Expand Down Expand Up @@ -265,7 +265,7 @@ var _ = Describe("AuxNetDeviceProvider", func() {
Expect(actual).To(ConsistOf(matchingDevices))
})
It("should error if the selector index is out of bounds", func() {
rf := factory.NewResourceFactory("fake", "fake", false, false)
rf := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", false, false)
p := auxnetdevice.NewAuxNetDeviceProvider(rf)
devs := make([]types.HostDevice, 0)

Expand Down
2 changes: 1 addition & 1 deletion pkg/auxnetdevice/auxNetDevice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ var _ = Describe("AuxNetDevice", func() {
On("GetNetDevicesFromAux", auxDevID).Return([]string{"eth0"}, nil)
utils.SetSriovnetProviderInst(&fakeSriovnetProvider)

f := factory.NewResourceFactory("fake", "fake", true, false)
f := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", true, false)
in := newPciDevice("0000:00:00.1")
rc := &types.ResourceConfig{}

Expand Down
10 changes: 5 additions & 5 deletions pkg/devices/host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var _ = Describe("HostDevice", func() {
}
defer fs.Use()()

f := factory.NewResourceFactory("fake", "fake", true, false)
f := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", true, false)
pciAddr := "0000:00:00.1"
in := newPciDeviceFn(pciAddr)
rc := &types.ResourceConfig{}
Expand All @@ -72,7 +72,7 @@ var _ = Describe("HostDevice", func() {
}
defer fs.Use()()

f := factory.NewResourceFactory("fake", "fake", true, false)
f := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", true, false)
pciAddr := "0000:00:00.1"
in := newPciDeviceFn(pciAddr)
rc := &types.ResourceConfig{}
Expand Down Expand Up @@ -100,7 +100,7 @@ var _ = Describe("HostDevice", func() {
}
defer fs.Use()()

f := factory.NewResourceFactory("fake", "fake", true, false)
f := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", true, false)
pciAddr := "0000:00:00.1"
in := newPciDeviceFn(pciAddr)
rc := &types.ResourceConfig{}
Expand All @@ -123,7 +123,7 @@ var _ = Describe("HostDevice", func() {
}
defer fs.Use()()

f := factory.NewResourceFactory("fake", "fake", true, false)
f := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", true, false)
pciAddr := "0000:00:00.1"
in := newPciDeviceFn(pciAddr)
rc := &types.ResourceConfig{}
Expand All @@ -147,7 +147,7 @@ var _ = Describe("HostDevice", func() {
}
defer fs.Use()()

f := factory.NewResourceFactory("fake", "fake", true, false)
f := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", true, false)
pciAddr := "0000:00:00.1"
in := newPciDeviceFn(pciAddr)
rc := &types.ResourceConfig{ExcludeTopology: true}
Expand Down
6 changes: 4 additions & 2 deletions pkg/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
)

type resourceFactory struct {
kubeletRootDir string
endPointPrefix string
endPointSuffix string
pluginWatch bool
Expand All @@ -39,11 +40,12 @@ type resourceFactory struct {
var instance *resourceFactory

// NewResourceFactory returns an instance of Resource Server factory
func NewResourceFactory(prefix, suffix string, pluginWatch, useCdi bool) types.ResourceFactory {
func NewResourceFactory(prefix, suffix, kubeletRootDir string, pluginWatch, useCdi bool) types.ResourceFactory {
if instance == nil {
return &resourceFactory{
endPointPrefix: prefix,
endPointSuffix: suffix,
kubeletRootDir: kubeletRootDir,
pluginWatch: pluginWatch,
useCdi: useCdi,
}
Expand All @@ -58,7 +60,7 @@ func (rf *resourceFactory) GetResourceServer(rp types.ResourcePool) (types.Resou
if prefixOverride := rp.GetResourcePrefix(); prefixOverride != "" {
prefix = prefixOverride
}
return resources.NewResourceServer(prefix, rf.endPointSuffix, rf.pluginWatch, rf.useCdi, rp), nil
return resources.NewResourceServer(prefix, rf.endPointSuffix, rf.kubeletRootDir, rf.pluginWatch, rf.useCdi, rp), nil
}
return nil, fmt.Errorf("factory: unable to get resource pool object")
}
Expand Down
30 changes: 15 additions & 15 deletions pkg/factory/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ var _ = Describe("Factory", func() {
Describe("getting factory instance", func() {
Context("always", func() {
It("should return the same instance", func() {
f0 := factory.NewResourceFactory("fake", "fake", true, false)
f0 := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", true, false)
Expect(f0).NotTo(BeNil())
f1 := factory.NewResourceFactory("fake", "fake", true, false)
f1 := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", true, false)
Expect(f1).To(Equal(f0))
})
})
})
DescribeTable("getting info provider",
func(name string, expected reflect.Type) {
f := factory.NewResourceFactory("fake", "fake", true, false)
f := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", true, false)
p := f.GetDefaultInfoProvider("fakePCIAddr", name)
Expect(p).To(HaveLen(2)) // for all the providers except netdevice we expect 2 info providers
Expect(reflect.TypeOf(p[1])).To(Equal(expected))
Expand All @@ -64,15 +64,15 @@ var _ = Describe("Factory", func() {
)

Describe("getting info provider for generic netdevice", func() {
f := factory.NewResourceFactory("fake", "fake", true, false)
f := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", true, false)
p := f.GetDefaultInfoProvider("fakePCIAddr", "netdevice")
Expect(p).To(HaveLen(1)) // for all the providers except netdevice we expect 2 info providers
Expect(reflect.TypeOf(p[0])).To(Equal(reflect.TypeOf(infoprovider.NewGenericInfoProvider("fakePCIAddr"))))
})

DescribeTable("getting selector",
func(selector string, shouldSucceed bool, expected reflect.Type) {
f := factory.NewResourceFactory("fake", "fake", true, false)
f := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", true, false)
v := []string{"val1", "val2", "val3"}
s, e := f.GetSelector(selector, v)

Expand Down Expand Up @@ -111,7 +111,7 @@ var _ = Describe("Factory", func() {
devs []types.HostDevice
)
BeforeEach(func() {
f := factory.NewResourceFactory("fake", "fake", true, false)
f := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", true, false)

devs = make([]types.HostDevice, 4)
vendors := []string{"8086", "8086", "8086", "1234"}
Expand Down Expand Up @@ -180,7 +180,7 @@ var _ = Describe("Factory", func() {
DescribeTable("getting resource pool",
func(selectorBytes []byte, hasDevices []string) {
// create factory
f := factory.NewResourceFactory("fake", "fake", true, false)
f := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", true, false)

// parse selector configuration & create resource config
var selectors json.RawMessage
Expand Down Expand Up @@ -310,7 +310,7 @@ var _ = Describe("Factory", func() {
devs []types.HostDevice
)
BeforeEach(func() {
f := factory.NewResourceFactory("fake", "fake", true, false)
f := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", true, false)
devs = make([]types.HostDevice, 4)
vendors := []string{"8086", "8086", "8086", "8086"}
codes := []string{"1111", "1111", "1111", "1111"}
Expand Down Expand Up @@ -443,7 +443,7 @@ var _ = Describe("Factory", func() {
devs []types.HostDevice
)
BeforeEach(func() {
f := factory.NewResourceFactory("fake", "fake", true, false)
f := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", true, false)

devs = make([]types.HostDevice, 1)
vendors := []string{"8086"}
Expand Down Expand Up @@ -501,7 +501,7 @@ var _ = Describe("Factory", func() {
devs []types.HostDevice
)
BeforeEach(func() {
f := factory.NewResourceFactory("fake", "fake", true, false)
f := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", true, false)

devs = make([]types.HostDevice, 4)
vendors := []string{"8086", "8086", "15b3", "15b3"}
Expand Down Expand Up @@ -564,7 +564,7 @@ var _ = Describe("Factory", func() {
})
DescribeTable("getting device provider",
func(dt types.DeviceType, shouldSucceed bool) {
f := factory.NewResourceFactory("fake", "fake", true, false)
f := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", true, false)
p := f.GetDeviceProvider(dt)
if shouldSucceed {
Expect(p).NotTo(BeNil())
Expand All @@ -589,7 +589,7 @@ var _ = Describe("Factory", func() {
Selectors: &s,
}

f := factory.NewResourceFactory("fake", "fake", true, false)
f := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", true, false)

_, e := f.GetDeviceFilter(rc)
if shouldSucceed {
Expand All @@ -612,7 +612,7 @@ var _ = Describe("Factory", func() {
mockProvider.On("HasRdmaParam", mock.AnythingOfType("string"),
mock.AnythingOfType("string")).Return(false, nil)
utils.SetNetlinkProviderInst(mockProvider)
f := factory.NewResourceFactory("fake", "fake", true, false)
f := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", true, false)
rs1 := f.GetRdmaSpec(types.NetDeviceType, "0000:00:00.1")
rs2 := f.GetRdmaSpec(types.AcceleratorType, "0000:00:00.2")
rs3 := f.GetRdmaSpec(types.AuxNetDeviceType, "foo.bar.3")
Expand All @@ -633,15 +633,15 @@ var _ = Describe("Factory", func() {
})
Describe("getting resource server", func() {
Context("when resource pool is nil", func() {
f := factory.NewResourceFactory("fake", "fake", true, false)
f := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", true, false)
rs, e := f.GetResourceServer(nil)
It("should fail", func() {
Expect(e).To(HaveOccurred())
Expect(rs).To(BeNil())
})
})
Context("when resource pool uses overridden prefix", func() {
f := factory.NewResourceFactory("fake", "fake", true, false)
f := factory.NewResourceFactory("fake", "fake", "/var/lib/kubelet", true, false)
rp := mocks.ResourcePool{}
rp.On("GetResourcePrefix").Return("overridden").
On("GetResourceName").Return("fake")
Expand Down
Loading

0 comments on commit 686a578

Please sign in to comment.