Skip to content

Commit bbcdfd4

Browse files
authored
Merge pull request #90 from verult/nodeinfo-apicall
Temporarily calling CSINodeInfo API directly instead of using a lister
2 parents 3680b7c + 950c392 commit bbcdfd4

5 files changed

Lines changed: 15 additions & 6 deletions

File tree

cmd/csi-attacher/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func main() {
148148
vaLister := factory.Storage().V1beta1().VolumeAttachments().Lister()
149149
csiFactory := csiinformers.NewSharedInformerFactory(csiClientset, *resync)
150150
nodeInfoLister := csiFactory.Csi().V1alpha1().CSINodeInfos().Lister()
151-
handler = controller.NewCSIHandler(clientset, attacher, csiConn, pvLister, nodeLister, nodeInfoLister, vaLister, timeout)
151+
handler = controller.NewCSIHandler(clientset, csiClientset, attacher, csiConn, pvLister, nodeLister, nodeInfoLister, vaLister, timeout)
152152
glog.V(2).Infof("CSI driver supports ControllerPublishUnpublish, using real CSI handler")
153153
} else {
154154
handler = controller.NewTrivialHandler(clientset)

pkg/controller/csi_handler.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ import (
3636
"github.com/kubernetes-csi/external-attacher/pkg/connection"
3737

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

4142
// csiHandler is a handler that calls CSI to attach/detach volume.
4243
// It adds finalizer to VolumeAttachment instance to make sure they're detached
4344
// before deletion.
4445
type csiHandler struct {
4546
client kubernetes.Interface
47+
csiClientSet csiclient.Interface
4648
attacherName string
4749
csiConnection connection.CSIConnection
4850
pvLister corelisters.PersistentVolumeLister
@@ -58,6 +60,7 @@ var _ Handler = &csiHandler{}
5860
// NewCSIHandler creates a new CSIHandler.
5961
func NewCSIHandler(
6062
client kubernetes.Interface,
63+
csiClientSet csiclient.Interface,
6164
attacherName string,
6265
csiConnection connection.CSIConnection,
6366
pvLister corelisters.PersistentVolumeLister,
@@ -68,6 +71,7 @@ func NewCSIHandler(
6871

6972
return &csiHandler{
7073
client: client,
74+
csiClientSet: csiClientSet,
7175
attacherName: attacherName,
7276
csiConnection: csiConnection,
7377
pvLister: pvLister,
@@ -497,7 +501,8 @@ func (h *csiHandler) getCredentialsFromPV(csiSource *v1.CSIPersistentVolumeSourc
497501
// node ID stored in VolumeAttachment annotation.
498502
func (h *csiHandler) getNodeID(driver string, nodeName string, va *storage.VolumeAttachment) (string, error) {
499503
// Try to find CSINodeInfo first.
500-
nodeInfo, err := h.nodeInfoLister.Get(nodeName)
504+
// nodeInfo, err := h.nodeInfoLister.Get(nodeName) // TODO (kubernetes/kubernetes #71052) use the lister once it syncs existing CSINodeInfo objects properly.
505+
nodeInfo, err := h.csiClientSet.CsiV1alpha1().CSINodeInfos().Get(nodeName, metav1.GetOptions{})
501506
if err == nil {
502507
if nodeID, found := GetNodeIDFromNodeInfo(driver, nodeInfo); found {
503508
glog.V(4).Infof("Found NodeID %s in CSINodeInfo %s", nodeID, nodeName)

pkg/controller/csi_handler_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"k8s.io/client-go/kubernetes"
3535
core "k8s.io/client-go/testing"
3636
csiapi "k8s.io/csi-api/pkg/apis/csi/v1alpha1"
37+
csiclient "k8s.io/csi-api/pkg/client/clientset/versioned"
3738
csiinformers "k8s.io/csi-api/pkg/client/informers/externalversions"
3839
)
3940

@@ -50,9 +51,10 @@ var (
5051

5152
var timeout = 10 * time.Millisecond
5253

53-
func csiHandlerFactory(client kubernetes.Interface, informerFactory informers.SharedInformerFactory, csiInformerFactory csiinformers.SharedInformerFactory, csi connection.CSIConnection) Handler {
54+
func csiHandlerFactory(client kubernetes.Interface, csiClient csiclient.Interface, informerFactory informers.SharedInformerFactory, csiInformerFactory csiinformers.SharedInformerFactory, csi connection.CSIConnection) Handler {
5455
return NewCSIHandler(
5556
client,
57+
csiClient,
5658
testAttacherName,
5759
csi,
5860
informerFactory.Core().V1().PersistentVolumes().Lister(),

pkg/controller/framework_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"k8s.io/client-go/kubernetes/fake"
3939
core "k8s.io/client-go/testing"
4040
csiapi "k8s.io/csi-api/pkg/apis/csi/v1alpha1"
41+
csiclient "k8s.io/csi-api/pkg/client/clientset/versioned"
4142
fakecsi "k8s.io/csi-api/pkg/client/clientset/versioned/fake"
4243
csiinformers "k8s.io/csi-api/pkg/client/informers/externalversions"
4344
)
@@ -99,7 +100,7 @@ type csiCall struct {
99100
delay time.Duration
100101
}
101102

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

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

178179
// Construct controller
179180
csiConnection := &fakeCSIConnection{t: t, calls: test.expectedCSICalls}
180-
handler := handlerFactory(client, informers, csiInformers, csiConnection)
181+
handler := handlerFactory(client, csiClient, informers, csiInformers, csiConnection)
181182
ctrl := NewCSIAttachController(client, testAttacherName, handler, vaInformer, pvInformer)
182183

183184
// Start the test by enqueueing the right event

pkg/controller/trivial_handler_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ import (
3030
"k8s.io/client-go/informers"
3131
"k8s.io/client-go/kubernetes"
3232
core "k8s.io/client-go/testing"
33+
csiclient "k8s.io/csi-api/pkg/client/clientset/versioned"
3334
csiinformers "k8s.io/csi-api/pkg/client/informers/externalversions"
3435
)
3536

36-
func trivialHandlerFactory(client kubernetes.Interface, informerFactory informers.SharedInformerFactory, csiInformerFactory csiinformers.SharedInformerFactory, csi connection.CSIConnection) Handler {
37+
func trivialHandlerFactory(client kubernetes.Interface, csiClient csiclient.Interface, informerFactory informers.SharedInformerFactory, csiInformerFactory csiinformers.SharedInformerFactory, csi connection.CSIConnection) Handler {
3738
return NewTrivialHandler(client)
3839
}
3940

0 commit comments

Comments
 (0)