Skip to content

Commit 3b659db

Browse files
committed
manila-csi-plugin: Enable auto-detection of topology, node ID
Same as we do for Cinder. A separate change will deprecate the respective options. Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
1 parent e6fc7d3 commit 3b659db

File tree

7 files changed

+50
-14
lines changed

7 files changed

+50
-14
lines changed

cmd/cinder-csi-plugin/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func handle() {
129129
}
130130

131131
if provideNodeService {
132-
//Initialize mount
132+
// Initialize mount
133133
mount := mount.GetMountProvider()
134134

135135
cfg, err := openstack.GetConfigFromFiles(cloudConfig)
@@ -138,7 +138,7 @@ func handle() {
138138
return
139139
}
140140

141-
//Initialize Metadata
141+
// Initialize Metadata
142142
metadata := metadata.GetMetadataProvider(cfg.Metadata.SearchOrder)
143143

144144
d.SetupNodeService(mount, metadata, cfg.BlockStorage, additionalTopologies)

cmd/manila-csi-plugin/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"k8s.io/cloud-provider-openstack/pkg/csi/manila/csiclient"
2828
"k8s.io/cloud-provider-openstack/pkg/csi/manila/manilaclient"
2929
"k8s.io/cloud-provider-openstack/pkg/csi/manila/runtimeconfig"
30+
"k8s.io/cloud-provider-openstack/pkg/util/metadata"
3031
"k8s.io/cloud-provider-openstack/pkg/version"
3132
"k8s.io/component-base/cli"
3233
"k8s.io/klog/v2"
@@ -108,7 +109,10 @@ func main() {
108109
}
109110

110111
if provideNodeService {
111-
err = d.SetupNodeService()
112+
// Initialize metadata
113+
metadata := metadata.GetMetadataProvider("")
114+
115+
err = d.SetupNodeService(metadata)
112116
if err != nil {
113117
klog.Fatalf("Driver node service initialization failed: %v", err)
114118
}

pkg/csi/manila/driver.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"k8s.io/client-go/listers/core/v1"
3333
"k8s.io/cloud-provider-openstack/pkg/csi/manila/csiclient"
3434
"k8s.io/cloud-provider-openstack/pkg/csi/manila/manilaclient"
35+
"k8s.io/cloud-provider-openstack/pkg/util/metadata"
3536
"k8s.io/cloud-provider-openstack/pkg/version"
3637
"k8s.io/klog/v2"
3738
)
@@ -182,11 +183,7 @@ func (d *Driver) SetupControllerService() error {
182183
return nil
183184
}
184185

185-
func (d *Driver) SetupNodeService() error {
186-
if err := argNotEmpty(d.nodeID, "node ID"); err != nil {
187-
return err
188-
}
189-
186+
func (d *Driver) SetupNodeService(metadata metadata.IMetadata) error {
190187
klog.Info("Providing node service")
191188

192189
var supportsNodeStage bool
@@ -206,7 +203,12 @@ func (d *Driver) SetupNodeService() error {
206203

207204
d.addNodeServiceCapabilities(nscaps)
208205

209-
d.ns = &nodeServer{d: d, supportsNodeStage: supportsNodeStage, nodeStageCache: make(map[volumeID]stageCacheEntry)}
206+
d.ns = &nodeServer{
207+
d: d,
208+
metadata: metadata,
209+
supportsNodeStage: supportsNodeStage,
210+
nodeStageCache: make(map[volumeID]stageCacheEntry),
211+
}
210212
return nil
211213
}
212214

pkg/csi/manila/nodeserver.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ import (
2929
"k8s.io/cloud-provider-openstack/pkg/csi/manila/options"
3030
"k8s.io/cloud-provider-openstack/pkg/csi/manila/shareadapters"
3131
clouderrors "k8s.io/cloud-provider-openstack/pkg/util/errors"
32+
"k8s.io/cloud-provider-openstack/pkg/util/metadata"
3233
"k8s.io/klog/v2"
3334
)
3435

3536
type nodeServer struct {
3637
d *Driver
3738

39+
metadata metadata.IMetadata
3840
supportsNodeStage bool
3941
// The result of NodeStageVolume is stashed away for NodePublishVolume(s) that will follow
4042
nodeStageCache map[volumeID]stageCacheEntry
@@ -324,13 +326,23 @@ func (ns *nodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstag
324326
}
325327

326328
func (ns *nodeServer) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error) {
329+
nodeID, err := ns.metadata.GetInstanceID()
330+
if err != nil {
331+
return nil, status.Errorf(codes.Internal, "[NodeGetInfo] unable to retrieve instance id of node %v", err)
332+
}
333+
327334
nodeInfo := &csi.NodeGetInfoResponse{
328-
NodeId: ns.d.nodeID,
335+
NodeId: nodeID,
329336
}
330337

331338
if ns.d.withTopology {
339+
zone, err := ns.metadata.GetAvailabilityZone()
340+
if err != nil {
341+
return nil, status.Errorf(codes.Internal, "[NodeGetInfo] Unable to retrieve availability zone of node %v", err)
342+
}
343+
332344
nodeInfo.AccessibleTopology = &csi.Topology{
333-
Segments: map[string]string{topologyKey: ns.d.nodeAZ},
345+
Segments: map[string]string{topologyKey: zone},
334346
}
335347
}
336348

tests/sanity/cinder/sanity_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ func TestDriver(t *testing.T) {
2727
}
2828

2929
fakemnt := GetFakeMountProvider()
30-
fakemet := &fakemetadata{}
30+
fakemeta := &fakemetadata{}
3131
fakeOpts := openstack.BlockStorageOpts{
3232
RescanOnResize: false,
3333
NodeVolumeAttachLimit: 200,
3434
}
3535

3636
d.SetupControllerService(openstack.OsInstances)
37-
d.SetupNodeService(fakemnt, fakemet, fakeOpts, map[string]string{})
37+
d.SetupNodeService(fakemnt, fakemeta, fakeOpts, map[string]string{})
3838

3939
// TODO: Stop call
4040

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package sanity
2+
3+
var FakeInstanceID = "321a8b81-3660-43e5-bab8-6470b65ee4e8"
4+
var FakeAvailability = "fake-az"
5+
6+
type fakemetadata struct{}
7+
8+
// fake metadata
9+
10+
func (m *fakemetadata) GetInstanceID() (string, error) {
11+
return FakeInstanceID, nil
12+
}
13+
14+
func (m *fakemetadata) GetAvailabilityZone() (string, error) {
15+
return FakeAvailability, nil
16+
}

tests/sanity/manila/sanity_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ func TestDriver(t *testing.T) {
5454
t.Fatalf("Failed to initialize CSI Manila controller service: %v", err)
5555
}
5656

57-
err = d.SetupNodeService()
57+
fakemeta := &fakemetadata{}
58+
59+
err = d.SetupNodeService(fakemeta)
5860
if err != nil {
5961
t.Fatalf("Failed to initialize CSI Manila node service: %v", err)
6062
}

0 commit comments

Comments
 (0)