Skip to content

Commit

Permalink
plugin watcher mode support (#107)
Browse files Browse the repository at this point in the history
* glide update for plugin watcher mode

* switch to kubelet plugin watcher mode

Fixes #60

* fix device socket mount path

Kubernetes 1.13 supports(GA) a new plugin registration
path {kubelet_root_dir}/plugins_registry, but it also
maintains backward compat for old registration path at
{kubelet_root_dir}/device-plugins; This change allows
both pathes be mounted to sriov device plugin pod.
  • Loading branch information
zshi-redhat committed Apr 3, 2019
1 parent 4d18815 commit 4f3dd24
Show file tree
Hide file tree
Showing 3,780 changed files with 1,034,570 additions and 223,471 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
20 changes: 15 additions & 5 deletions cmd/sriovdp/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type cliParams struct {

type resourceManager struct {
cliParams
pluginWatchMode bool
socketSuffix string
rFactory types.ResourceFactory
configList []*types.ResourceConfig // resourceName -> resourcePool
Expand All @@ -64,11 +65,18 @@ type resourceManager struct {
}

func newResourceManager(cp *cliParams) *resourceManager {
pluginWatchMode := utils.DetectPluginWatchMode(types.SockDir)
if pluginWatchMode {
glog.Infof("Using Kubelet Plugin Registry Mode")
} else {
glog.Infof("Using Deprecated Devie Plugin Registry Path")
}
return &resourceManager{
cliParams: *cp,
rFactory: resources.NewResourceFactory(cp.resourcePrefix, socketSuffix),
netDeviceList: make([]types.PciNetDevice, 0),
linkWatchList: make(map[string]types.LinkWatcher, 0),
cliParams: *cp,
pluginWatchMode: pluginWatchMode,
rFactory: resources.NewResourceFactory(cp.resourcePrefix, socketSuffix, pluginWatchMode),
netDeviceList: make([]types.PciNetDevice, 0),
linkWatchList: make(map[string]types.LinkWatcher, 0),
}
}

Expand Down Expand Up @@ -127,7 +135,9 @@ func (rm *resourceManager) startAllServers() error {
}

// start watcher
go rs.Watch()
if !rm.pluginWatchMode {
go rs.Watch()
}
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/sriovdp/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ var _ = Describe("Resource manager", func() {
os.Setenv("GHW_CHROOT", fs.RootDir)
defer os.Unsetenv("GHW_CHROOT")

rf := resources.NewResourceFactory("fake", "fake")
rf := resources.NewResourceFactory("fake", "fake", true)
rm := &resourceManager{
rFactory: rf,
configList: []*types.ResourceConfig{
Expand Down Expand Up @@ -384,7 +384,7 @@ var _ = Describe("Resource manager", func() {
func(fs *utils.FakeFilesystem, addr string, expected []types.LinkWatcher) {
defer fs.Use()()

rf := resources.NewResourceFactory("fake", "fake")
rf := resources.NewResourceFactory("fake", "fake", true)
rm := &resourceManager{
rFactory: rf,
configList: []*types.ResourceConfig{
Expand Down
4 changes: 2 additions & 2 deletions deployments/pod-sriovdp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spec:
securityContext:
privileged: true
volumeMounts:
- mountPath: /var/lib/kubelet/device-plugins/
- mountPath: /var/lib/kubelet/
name: devicesock
readOnly: false
- mountPath: /sys
Expand All @@ -29,7 +29,7 @@ spec:
volumes:
- name: devicesock
hostPath:
path: /var/lib/kubelet/device-plugins/
path: /var/lib/kubelet/
- name: net
hostPath:
path: /sys
Expand Down
100 changes: 49 additions & 51 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import:
- package: k8s.io/kubernetes
subpackages:
- pkg/kubelet/apis/deviceplugin/v1beta1
- pkg/kubelet/apis/pluginregistration/v1
- package: github.com/jaypipes/ghw
version: ^0.3.0
- package: github.com/vishvananda/netlink
Expand Down
2 changes: 1 addition & 1 deletion images/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Note: The likely best practice here is to build your own image given the Dockerf
Example docker run command:

```
$ docker run -it -v /var/lib/kubelet/device-plugins/:/var/lib/kubelet/device-plugins/ -v /sys/class/net:/sys/class/net --entrypoint=/bin/bash nfvpe/sriovdp
$ docker run -it -v /var/lib/kubelet/:/var/lib/kubelet/ -v /sys/class/net:/sys/class/net --entrypoint=/bin/bash nfvpe/sriovdp
```

Originally inspired by and is a portmanteau of the [Flannel daemonset](https://github.com/coreos/flannel/blob/master/Documentation/kube-flannel.yml), the [Calico Daemonset](https://github.com/projectcalico/calico/blob/master/v2.0/getting-started/kubernetes/installation/hosted/k8s-backend-addon-manager/calico-daemonset.yaml), and the [Calico CNI install bash script](https://github.com/projectcalico/cni-plugin/blob/be4df4db2e47aa7378b1bdf6933724bac1f348d0/k8s-install/scripts/install-cni.sh#L104-L153).
5 changes: 2 additions & 3 deletions images/sriovdp-daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ spec:
privileged: true
volumeMounts:
- name: devicesock
mountPath: /var/lib/kubelet/device-plugins/
mountPath: /var/lib/kubelet/
readOnly: false
- name: log
mountPath: /var/log
Expand All @@ -53,7 +53,7 @@ spec:
volumes:
- name: devicesock
hostPath:
path: /var/lib/kubelet/device-plugins/
path: /var/lib/kubelet/
- name: log
hostPath:
path: /var/log
Expand All @@ -66,4 +66,3 @@ spec:
items:
- key: config.json
path: config.json

6 changes: 4 additions & 2 deletions pkg/resources/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,19 @@ import (
type resourceFactory struct {
endPointPrefix string
endPointSuffix string
pluginWatch bool
}

var instance *resourceFactory

// NewResourceFactory returns an instance of Resource Server factory
func NewResourceFactory(prefix, suffix string) types.ResourceFactory {
func NewResourceFactory(prefix, suffix string, pluginWatch bool) types.ResourceFactory {

if instance == nil {
return &resourceFactory{
endPointPrefix: prefix,
endPointSuffix: suffix,
pluginWatch: pluginWatch,
}
}
return instance
Expand All @@ -44,7 +46,7 @@ func NewResourceFactory(prefix, suffix string) types.ResourceFactory {
// GetResourceServer returns an instance of ResourceServer for a ResourcePool
func (rf *resourceFactory) GetResourceServer(rp types.ResourcePool) (types.ResourceServer, error) {
if rp != nil {
return newResourceServer(rf.endPointPrefix, rf.endPointSuffix, rp), nil
return newResourceServer(rf.endPointPrefix, rf.endPointSuffix, rf.pluginWatch, rp), nil
}
return nil, fmt.Errorf("factory: unable to get resource pool object")
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/resources/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ var _ = Describe("Factory", func() {
Describe("getting factory instance", func() {
Context("always", func() {
It("should return the same instance", func() {
f0 := NewResourceFactory("fake", "fake")
f0 := NewResourceFactory("fake", "fake", true)
Expect(f0).NotTo(BeNil())
f1 := NewResourceFactory("fake", "fake")
f1 := NewResourceFactory("fake", "fake", true)
Expect(f1).To(Equal(f0))
})
})
})
DescribeTable("getting info provider",
func(name string, expected reflect.Type) {
f := NewResourceFactory("fake", "fake")
f := NewResourceFactory("fake", "fake", true)
p := f.GetInfoProvider(name)
Expect(reflect.TypeOf(p)).To(Equal(expected))
},
Expand All @@ -42,7 +42,7 @@ var _ = Describe("Factory", func() {
devs []types.PciNetDevice
)
BeforeEach(func() {
f := NewResourceFactory("fake", "fake")
f := NewResourceFactory("fake", "fake", true)

devs = make([]types.PciNetDevice, 4)
vendors := []string{"8086", "8086", "8086", "1234"}
Expand Down
Loading

0 comments on commit 4f3dd24

Please sign in to comment.