New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding CSI driver registration with plugin watcher #64560
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ import ( | |
"fmt" | ||
"os" | ||
"path" | ||
"strings" | ||
"sync" | ||
"time" | ||
|
||
"github.com/golang/glog" | ||
|
@@ -29,6 +31,7 @@ import ( | |
"k8s.io/apimachinery/pkg/types" | ||
"k8s.io/kubernetes/pkg/util/mount" | ||
"k8s.io/kubernetes/pkg/volume" | ||
"k8s.io/kubernetes/pkg/volume/csi/labelmanager" | ||
) | ||
|
||
const ( | ||
|
@@ -59,9 +62,54 @@ func ProbeVolumePlugins() []volume.VolumePlugin { | |
// volume.VolumePlugin methods | ||
var _ volume.VolumePlugin = &csiPlugin{} | ||
|
||
type csiDriver struct { | ||
driverName string | ||
driverEndpoint string | ||
} | ||
|
||
type csiDriversStore struct { | ||
driversMap map[string]csiDriver | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious why you are no longer using the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a comment about sync.Map suggesting that it is not strong typed. So I switched back to a simple map with mutex. |
||
sync.RWMutex | ||
} | ||
|
||
// csiDrivers map keep track of all registered CSI drivers on the node and their | ||
// corresponding sockets | ||
var csiDrivers csiDriversStore | ||
|
||
var lm labelmanager.Interface | ||
|
||
// RegistrationCallback is called by kubelet's plugin watcher upon detection | ||
// of a new registration socket opened by CSI Driver registrar side car. | ||
func RegistrationCallback(pluginName string, endpoint string, versions []string, socketPath string) (error, chan bool) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Golint arg-order: error should be the last type when returning multiple items. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Due to the kubelet's function returning variable in this order. |
||
|
||
glog.Infof(log("Callback from kubelet with plugin name: %s endpoint: %s versions: %s socket path: %s", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. may be we should use verbose level like V(4) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will change it once the feature becomes more mature/beta. For now we need to see this but without trigger 10 million of other messages. |
||
pluginName, endpoint, strings.Join(versions, ","), socketPath)) | ||
|
||
if endpoint == "" { | ||
endpoint = socketPath | ||
} | ||
// Calling nodeLabelManager to update label for newly registered CSI driver | ||
err := lm.AddLabels(pluginName) | ||
if err != nil { | ||
return err, nil | ||
} | ||
// Storing endpoint of newly registered CSI driver into the map, where CSI driver name will be the key | ||
// all other CSI components will be able to get the actual socket of CSI drivers by its name. | ||
csiDrivers.Lock() | ||
defer csiDrivers.Unlock() | ||
csiDrivers.driversMap[pluginName] = csiDriver{driverName: pluginName, driverEndpoint: endpoint} | ||
|
||
return nil, nil | ||
} | ||
|
||
func (p *csiPlugin) Init(host volume.VolumeHost) error { | ||
glog.Info(log("plugin initializing...")) | ||
p.host = host | ||
|
||
// Initializing csiDrivers map and label management channels | ||
csiDrivers = csiDriversStore{driversMap: map[string]csiDriver{}} | ||
lm = labelmanager.NewLabelManager(host.GetNodeName(), host.GetKubeClient()) | ||
|
||
return nil | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "go_default_library", | ||
srcs = ["labelmanager.go"], | ||
importpath = "k8s.io/kubernetes/pkg/volume/csi/labelmanager", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//vendor/github.com/golang/glog:go_default_library", | ||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", | ||
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library", | ||
"//vendor/k8s.io/client-go/kubernetes:go_default_library", | ||
"//vendor/k8s.io/client-go/kubernetes/typed/core/v1:go_default_library", | ||
"//vendor/k8s.io/client-go/util/retry:go_default_library", | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "package-srcs", | ||
srcs = glob(["**"]), | ||
tags = ["automanaged"], | ||
visibility = ["//visibility:private"], | ||
) | ||
|
||
filegroup( | ||
name = "all-srcs", | ||
srcs = [":package-srcs"], | ||
tags = ["automanaged"], | ||
visibility = ["//visibility:public"], | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be used from API instead of harcoding https://github.com/kubernetes/kubernetes/blob/master/pkg/kubelet/apis/pluginregistration/v1alpha1/constants.go#L20
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, will do in the follow up PR.