Skip to content

Commit

Permalink
feat(cinder-csi-plugin): add possibility to set custom topology keys (#…
Browse files Browse the repository at this point in the history
…2035)

* feat(cinder-csi-plugin-node): Additionnal topology keys `--additionnal-topology` are announced on NodeGetInfo to create proper CSINode object
    and could used in storage class allowedTopologies field, in combination with csi-provisioner `--feature-gates Topology=true`
    created PV will have nodeAffinity set with topologies presents in storageClass allowedTopologies and in `--additionnal-topology` argument.

Signed-off-by: MatthieuFin <matthieu2717@gmail.com>
  • Loading branch information
MatthieuFin committed May 14, 2024
1 parent 102fd87 commit 8b36da6
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 17 deletions.
4 changes: 3 additions & 1 deletion cmd/cinder-csi-plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var (
nodeID string
cloudConfig []string
cloudNames []string
additionalTopologies map[string]string
cluster string
httpEndpoint string
provideControllerService bool
Expand Down Expand Up @@ -67,6 +68,7 @@ func main() {
}

cmd.PersistentFlags().StringSliceVar(&cloudNames, "cloud-name", []string{""}, "CSI driver cloud name in config files. This option can be given multiple times to manage multiple openstack clouds")
cmd.PersistentFlags().StringToStringVar(&additionalTopologies, "additionnal-topology", map[string]string{}, "CSI driver topology example topology.kubernetes.io/region=REGION1. This option can be given multiple times to manage multiple topology keys")

cmd.PersistentFlags().StringVar(&cluster, "cluster", "", "The identifier of the cluster that the plugin is running in.")
cmd.PersistentFlags().StringVar(&httpEndpoint, "http-endpoint", "", "The TCP network address where the HTTP server for providing metrics for diagnostics, will listen (example: `:8080`). The default is empty string, which means the server is disabled.")
Expand Down Expand Up @@ -106,7 +108,7 @@ func handle() {
//Initialize Metadata
metadata := metadata.GetMetadataProvider(clouds[cloudNames[0]].GetMetadataOpts().SearchOrder)

d.SetupNodeService(clouds[cloudNames[0]], mount, metadata)
d.SetupNodeService(clouds[cloudNames[0]], mount, metadata, additionalTopologies)
}

d.Run()
Expand Down
4 changes: 2 additions & 2 deletions pkg/csi/cinder/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ func (d *Driver) SetupControllerService(clouds map[string]openstack.IOpenStack)
d.cs = NewControllerServer(d, clouds)
}

func (d *Driver) SetupNodeService(cloud openstack.IOpenStack, mount mount.IMount, metadata metadata.IMetadata) {
func (d *Driver) SetupNodeService(cloud openstack.IOpenStack, mount mount.IMount, metadata metadata.IMetadata, topologies map[string]string) {
klog.Info("Providing node service")
d.ns = NewNodeServer(d, mount, metadata, cloud)
d.ns = NewNodeServer(d, mount, metadata, cloud, topologies)
}

func (d *Driver) Run() {
Expand Down
16 changes: 11 additions & 5 deletions pkg/csi/cinder/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ import (
)

type nodeServer struct {
Driver *Driver
Mount mount.IMount
Metadata metadata.IMetadata
Cloud openstack.IOpenStack
Driver *Driver
Mount mount.IMount
Metadata metadata.IMetadata
Cloud openstack.IOpenStack
Topologies map[string]string
}

func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) {
Expand Down Expand Up @@ -467,7 +468,12 @@ func (ns *nodeServer) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoReque
if err != nil {
return nil, status.Errorf(codes.Internal, "[NodeGetInfo] Unable to retrieve availability zone of node %v", err)
}
topology := &csi.Topology{Segments: map[string]string{topologyKey: zone}}
topologyMap := make(map[string]string, len(ns.Topologies)+1)
topologyMap[topologyKey] = zone
for k, v := range ns.Topologies {
topologyMap[k] = v
}
topology := &csi.Topology{Segments: topologyMap}

maxVolume := ns.Cloud.GetMaxVolLimit()

Expand Down
6 changes: 3 additions & 3 deletions pkg/csi/cinder/nodeserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func init() {
"": omock,
}

fakeNs = NewNodeServer(d, mount.MInstance, metadata.MetadataService, openstack.OsInstances[""])
fakeNs = NewNodeServer(d, mount.MInstance, metadata.MetadataService, openstack.OsInstances[""], map[string]string{})
}
}

Expand Down Expand Up @@ -147,7 +147,7 @@ func TestNodePublishVolumeEphermeral(t *testing.T) {
}

d := NewDriver(&DriverOpts{Endpoint: FakeEndpoint, ClusterID: FakeCluster})
fakeNse := NewNodeServer(d, mount.MInstance, metadata.MetadataService, openstack.OsInstances[""])
fakeNse := NewNodeServer(d, mount.MInstance, metadata.MetadataService, openstack.OsInstances[""], map[string]string{})

// Init assert
assert := assert.New(t)
Expand Down Expand Up @@ -299,7 +299,7 @@ func TestNodeUnpublishVolumeEphermeral(t *testing.T) {
omock.On("DeleteVolume", FakeVolID).Return(nil)

d := NewDriver(&DriverOpts{Endpoint: FakeEndpoint, ClusterID: FakeCluster})
fakeNse := NewNodeServer(d, mount.MInstance, metadata.MetadataService, osmock[""])
fakeNse := NewNodeServer(d, mount.MInstance, metadata.MetadataService, osmock[""], map[string]string{})

// Init assert
assert := assert.New(t)
Expand Down
11 changes: 6 additions & 5 deletions pkg/csi/cinder/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ func NewIdentityServer(d *Driver) *identityServer {
}
}

func NewNodeServer(d *Driver, mount mount.IMount, metadata metadata.IMetadata, cloud openstack.IOpenStack) *nodeServer {
func NewNodeServer(d *Driver, mount mount.IMount, metadata metadata.IMetadata, cloud openstack.IOpenStack, topologies map[string]string) *nodeServer {
return &nodeServer{
Driver: d,
Mount: mount,
Metadata: metadata,
Cloud: cloud,
Driver: d,
Mount: mount,
Metadata: metadata,
Cloud: cloud,
Topologies: topologies,
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/sanity/cinder/sanity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestDriver(t *testing.T) {
fakemet := &fakemetadata{}

d.SetupControllerService(openstack.OsInstances)
d.SetupNodeService(fakecloudprovider, fakemnt, fakemet)
d.SetupNodeService(fakecloudprovider, fakemnt, fakemet, map[string]string{})

// TODO: Stop call

Expand Down

0 comments on commit 8b36da6

Please sign in to comment.