Skip to content

Commit

Permalink
Temporarily calling CSINodeInfo API directly instead of using a lister
Browse files Browse the repository at this point in the history
  • Loading branch information
verult committed Nov 15, 2018
1 parent 9da8c6d commit 950c392
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/csi-attacher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func main() {
vaLister := factory.Storage().V1beta1().VolumeAttachments().Lister()
csiFactory := csiinformers.NewSharedInformerFactory(csiClientset, *resync)
nodeInfoLister := csiFactory.Csi().V1alpha1().CSINodeInfos().Lister()
handler = controller.NewCSIHandler(clientset, attacher, csiConn, pvLister, nodeLister, nodeInfoLister, vaLister, timeout)
handler = controller.NewCSIHandler(clientset, csiClientset, attacher, csiConn, pvLister, nodeLister, nodeInfoLister, vaLister, timeout)
glog.V(2).Infof("CSI driver supports ControllerPublishUnpublish, using real CSI handler")
} else {
handler = controller.NewTrivialHandler(clientset)
Expand Down
7 changes: 6 additions & 1 deletion pkg/controller/csi_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ import (
"github.com/kubernetes-csi/external-attacher/pkg/connection"

csiMigration "github.com/kubernetes-csi/kubernetes-csi-migration-library"
csiclient "k8s.io/csi-api/pkg/client/clientset/versioned"
)

// csiHandler is a handler that calls CSI to attach/detach volume.
// It adds finalizer to VolumeAttachment instance to make sure they're detached
// before deletion.
type csiHandler struct {
client kubernetes.Interface
csiClientSet csiclient.Interface
attacherName string
csiConnection connection.CSIConnection
pvLister corelisters.PersistentVolumeLister
Expand All @@ -58,6 +60,7 @@ var _ Handler = &csiHandler{}
// NewCSIHandler creates a new CSIHandler.
func NewCSIHandler(
client kubernetes.Interface,
csiClientSet csiclient.Interface,
attacherName string,
csiConnection connection.CSIConnection,
pvLister corelisters.PersistentVolumeLister,
Expand All @@ -68,6 +71,7 @@ func NewCSIHandler(

return &csiHandler{
client: client,
csiClientSet: csiClientSet,
attacherName: attacherName,
csiConnection: csiConnection,
pvLister: pvLister,
Expand Down Expand Up @@ -497,7 +501,8 @@ func (h *csiHandler) getCredentialsFromPV(csiSource *v1.CSIPersistentVolumeSourc
// node ID stored in VolumeAttachment annotation.
func (h *csiHandler) getNodeID(driver string, nodeName string, va *storage.VolumeAttachment) (string, error) {
// Try to find CSINodeInfo first.
nodeInfo, err := h.nodeInfoLister.Get(nodeName)
// nodeInfo, err := h.nodeInfoLister.Get(nodeName) // TODO (kubernetes/kubernetes #71052) use the lister once it syncs existing CSINodeInfo objects properly.
nodeInfo, err := h.csiClientSet.CsiV1alpha1().CSINodeInfos().Get(nodeName, metav1.GetOptions{})
if err == nil {
if nodeID, found := GetNodeIDFromNodeInfo(driver, nodeInfo); found {
glog.V(4).Infof("Found NodeID %s in CSINodeInfo %s", nodeID, nodeName)
Expand Down
4 changes: 3 additions & 1 deletion pkg/controller/csi_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"k8s.io/client-go/kubernetes"
core "k8s.io/client-go/testing"
csiapi "k8s.io/csi-api/pkg/apis/csi/v1alpha1"
csiclient "k8s.io/csi-api/pkg/client/clientset/versioned"
csiinformers "k8s.io/csi-api/pkg/client/informers/externalversions"
)

Expand All @@ -50,9 +51,10 @@ var (

var timeout = 10 * time.Millisecond

func csiHandlerFactory(client kubernetes.Interface, informerFactory informers.SharedInformerFactory, csiInformerFactory csiinformers.SharedInformerFactory, csi connection.CSIConnection) Handler {
func csiHandlerFactory(client kubernetes.Interface, csiClient csiclient.Interface, informerFactory informers.SharedInformerFactory, csiInformerFactory csiinformers.SharedInformerFactory, csi connection.CSIConnection) Handler {
return NewCSIHandler(
client,
csiClient,
testAttacherName,
csi,
informerFactory.Core().V1().PersistentVolumes().Lister(),
Expand Down
5 changes: 3 additions & 2 deletions pkg/controller/framework_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"k8s.io/client-go/kubernetes/fake"
core "k8s.io/client-go/testing"
csiapi "k8s.io/csi-api/pkg/apis/csi/v1alpha1"
csiclient "k8s.io/csi-api/pkg/client/clientset/versioned"
fakecsi "k8s.io/csi-api/pkg/client/clientset/versioned/fake"
csiinformers "k8s.io/csi-api/pkg/client/informers/externalversions"
)
Expand Down Expand Up @@ -99,7 +100,7 @@ type csiCall struct {
delay time.Duration
}

type handlerFactory func(client kubernetes.Interface, informerFactory informers.SharedInformerFactory, csiInformerFactory csiinformers.SharedInformerFactory, csi connection.CSIConnection) Handler
type handlerFactory func(client kubernetes.Interface, csiClient csiclient.Interface, informerFactory informers.SharedInformerFactory, csiInformerFactory csiinformers.SharedInformerFactory, csi connection.CSIConnection) Handler

func runTests(t *testing.T, handlerFactory handlerFactory, tests []testCase) {
for _, test := range tests {
Expand Down Expand Up @@ -177,7 +178,7 @@ func runTests(t *testing.T, handlerFactory handlerFactory, tests []testCase) {

// Construct controller
csiConnection := &fakeCSIConnection{t: t, calls: test.expectedCSICalls}
handler := handlerFactory(client, informers, csiInformers, csiConnection)
handler := handlerFactory(client, csiClient, informers, csiInformers, csiConnection)
ctrl := NewCSIAttachController(client, testAttacherName, handler, vaInformer, pvInformer)

// Start the test by enqueueing the right event
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/trivial_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ import (
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
core "k8s.io/client-go/testing"
csiclient "k8s.io/csi-api/pkg/client/clientset/versioned"
csiinformers "k8s.io/csi-api/pkg/client/informers/externalversions"
)

func trivialHandlerFactory(client kubernetes.Interface, informerFactory informers.SharedInformerFactory, csiInformerFactory csiinformers.SharedInformerFactory, csi connection.CSIConnection) Handler {
func trivialHandlerFactory(client kubernetes.Interface, csiClient csiclient.Interface, informerFactory informers.SharedInformerFactory, csiInformerFactory csiinformers.SharedInformerFactory, csi connection.CSIConnection) Handler {
return NewTrivialHandler(client)
}

Expand Down

0 comments on commit 950c392

Please sign in to comment.