diff --git a/charts/manila-csi-plugin/Chart.yaml b/charts/manila-csi-plugin/Chart.yaml index 9fc97a5e79..b0d23754de 100644 --- a/charts/manila-csi-plugin/Chart.yaml +++ b/charts/manila-csi-plugin/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v1 appVersion: v1.31.2 description: Manila CSI Chart for OpenStack name: openstack-manila-csi -version: 2.31.2 +version: 2.31.3 home: http://github.com/kubernetes/cloud-provider-openstack icon: https://github.com/kubernetes/kubernetes/blob/master/logo/logo.png maintainers: diff --git a/charts/manila-csi-plugin/templates/controllerplugin-statefulset.yaml b/charts/manila-csi-plugin/templates/controllerplugin-statefulset.yaml index bdb3f6874b..e9263739e4 100644 --- a/charts/manila-csi-plugin/templates/controllerplugin-statefulset.yaml +++ b/charts/manila-csi-plugin/templates/controllerplugin-statefulset.yaml @@ -86,10 +86,8 @@ spec: command: ["/bin/sh", "-c", '/bin/manila-csi-plugin -v={{ $.Values.logVerbosityLevel }} - --nodeid=$(NODE_ID) {{- if $.Values.csimanila.topologyAwarenessEnabled }} --with-topology - --nodeaz={{ $.Values.csimanila.nodeAZ }} {{- end }} {{- if $.Values.csimanila.runtimeConfig.enabled }} --runtime-config-file=/runtimeconfig/runtimeconfig.json @@ -109,10 +107,6 @@ spec: env: - name: DRIVER_NAME value: {{ printf "%s.%s" .protocolSelector $.Values.driverName | lower }} - - name: NODE_ID - valueFrom: - fieldRef: - fieldPath: spec.nodeName - name: CSI_ENDPOINT value: "unix:///var/lib/kubelet/plugins/{{ printf "%s.%s" .protocolSelector $.Values.driverName | lower }}/csi-controllerplugin.sock" - name: FWD_CSI_ENDPOINT diff --git a/charts/manila-csi-plugin/templates/nodeplugin-daemonset.yaml b/charts/manila-csi-plugin/templates/nodeplugin-daemonset.yaml index 50647a62fc..aa173cc53f 100644 --- a/charts/manila-csi-plugin/templates/nodeplugin-daemonset.yaml +++ b/charts/manila-csi-plugin/templates/nodeplugin-daemonset.yaml @@ -50,13 +50,11 @@ spec: command: ["/bin/sh", "-c", '/bin/manila-csi-plugin -v={{ $.Values.logVerbosityLevel }} - --nodeid=$(NODE_ID) {{- if $.Values.csimanila.runtimeConfig.enabled }} --runtime-config-file=/runtimeconfig/runtimeconfig.json {{- end }} {{- if $.Values.csimanila.topologyAwarenessEnabled }} --with-topology - --nodeaz={{ $.Values.csimanila.nodeAZ }} {{- end }} --endpoint=$(CSI_ENDPOINT) --drivername=$(DRIVER_NAME) @@ -67,10 +65,6 @@ spec: env: - name: DRIVER_NAME value: {{ printf "%s.%s" .protocolSelector $.Values.driverName | lower }} - - name: NODE_ID - valueFrom: - fieldRef: - fieldPath: spec.nodeName - name: CSI_ENDPOINT value: "unix:///var/lib/kubelet/plugins/{{ printf "%s.%s" .protocolSelector $.Values.driverName | lower }}/csi.sock" - name: FWD_CSI_ENDPOINT diff --git a/charts/manila-csi-plugin/values.yaml b/charts/manila-csi-plugin/values.yaml index 81fd752ad1..51b99ccd25 100644 --- a/charts/manila-csi-plugin/values.yaml +++ b/charts/manila-csi-plugin/values.yaml @@ -35,10 +35,6 @@ csimanila: } } - # Availability zone for each node. topologyAwarenessEnabled must be set to true for this option to have any effect. - # If your Kubernetes cluster runs atop of Nova and want to use Nova AZs as AZs for the nodes of the cluster, uncomment the line below: - # nodeAZ: "$(curl http://169.254.169.254/openstack/latest/meta_data.json | jq -r .availability_zone)" - # You may set ID of the cluster where manila-csi is deployed. This value will be appended # to share metadata in newly provisioned shares as `manila.csi.openstack.org/cluster=`. clusterID: "" diff --git a/cmd/cinder-csi-plugin/main.go b/cmd/cinder-csi-plugin/main.go index b12c562e38..d31d376d37 100644 --- a/cmd/cinder-csi-plugin/main.go +++ b/cmd/cinder-csi-plugin/main.go @@ -76,7 +76,7 @@ func main() { csi.AddPVCFlags(cmd) cmd.PersistentFlags().StringVar(&nodeID, "nodeid", "", "node id") - if err := cmd.PersistentFlags().MarkDeprecated("nodeid", "This flag would be removed in future. Currently, the value is ignored by the driver"); err != nil { + if err := cmd.PersistentFlags().MarkDeprecated("nodeid", "This option is now ignored by the driver. It will be removed in a future release."); err != nil { klog.Fatalf("Unable to mark flag nodeid to be deprecated: %v", err) } @@ -129,7 +129,7 @@ func handle() { } if provideNodeService { - //Initialize mount + // Initialize mount mount := mount.GetMountProvider() cfg, err := openstack.GetConfigFromFiles(cloudConfig) @@ -138,7 +138,7 @@ func handle() { return } - //Initialize Metadata + // Initialize Metadata metadata := metadata.GetMetadataProvider(cfg.Metadata.SearchOrder) d.SetupNodeService(mount, metadata, cfg.BlockStorage, additionalTopologies) diff --git a/cmd/manila-csi-plugin/main.go b/cmd/manila-csi-plugin/main.go index 716a544062..f1505b3f98 100644 --- a/cmd/manila-csi-plugin/main.go +++ b/cmd/manila-csi-plugin/main.go @@ -27,6 +27,7 @@ import ( "k8s.io/cloud-provider-openstack/pkg/csi/manila/csiclient" "k8s.io/cloud-provider-openstack/pkg/csi/manila/manilaclient" "k8s.io/cloud-provider-openstack/pkg/csi/manila/runtimeconfig" + "k8s.io/cloud-provider-openstack/pkg/util/metadata" "k8s.io/cloud-provider-openstack/pkg/version" "k8s.io/component-base/cli" "k8s.io/klog/v2" @@ -90,11 +91,6 @@ func main() { PVCLister: csi.GetPVCLister(), } - if provideNodeService { - opts.NodeID = nodeID - opts.NodeAZ = nodeAZ - } - d, err := manila.NewDriver(opts) if err != nil { klog.Fatalf("Driver initialization failed: %v", err) @@ -108,7 +104,10 @@ func main() { } if provideNodeService { - err = d.SetupNodeService() + // Initialize metadata + metadata := metadata.GetMetadataProvider("") + + err = d.SetupNodeService(metadata) if err != nil { klog.Fatalf("Driver node service initialization failed: %v", err) } @@ -127,9 +126,15 @@ func main() { cmd.PersistentFlags().StringVar(&driverName, "drivername", "manila.csi.openstack.org", "name of the driver") - cmd.PersistentFlags().StringVar(&nodeID, "nodeid", "", "this node's ID. This value is required if the node service is provided by this CSI driver instance.") + cmd.PersistentFlags().StringVar(&nodeID, "nodeid", "", "this node's ID") + if err := cmd.PersistentFlags().MarkDeprecated("nodeid", "This option is now ignored by the driver. It will be removed in a future release."); err != nil { + klog.Fatalf("Unable to mark flag nodeid to be deprecated: %v", err) + } cmd.PersistentFlags().StringVar(&nodeAZ, "nodeaz", "", "this node's availability zone") + if err := cmd.PersistentFlags().MarkDeprecated("nodeaz", "This option is now ignored by the driver. It will be removed in a future release."); err != nil { + klog.Fatalf("Unable to mark flag nodeaz to be deprecated: %v", err) + } cmd.PersistentFlags().StringVar(&runtimeConfigFile, "runtime-config-file", "", "path to the runtime configuration file") diff --git a/docs/cinder-csi-plugin/csc-tool.md b/docs/cinder-csi-plugin/csc-tool.md deleted file mode 100644 index 07989abef9..0000000000 --- a/docs/cinder-csi-plugin/csc-tool.md +++ /dev/null @@ -1,198 +0,0 @@ - - -**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* - -- [Using CSC tool for Testing](#using-csc-tool-for-testing) - - [Test using csc](#test-using-csc) - - [Start Cinder driver](#start-cinder-driver) - - [Get plugin info](#get-plugin-info) - - [Get supported capabilities](#get-supported-capabilities) - - [Get controller implemented capabilities](#get-controller-implemented-capabilities) - - [Create a volume](#create-a-volume) - - [List volumes](#list-volumes) - - [Delete a volume](#delete-a-volume) - - [Create a snapshot from volume](#create-a-snapshot-from-volume) - - [List snapshots](#list-snapshots) - - [Delete a snapshot](#delete-a-snapshot) - - [ControllerPublish a volume](#controllerpublish-a-volume) - - [ControllerUnpublish a volume](#controllerunpublish-a-volume) - - [NodePublish a volume](#nodepublish-a-volume) - - [NodeUnpublish a volume](#nodeunpublish-a-volume) - - [Get NodeID](#get-nodeid) - - - -# Using CSC tool for Testing - -## Test using csc -Get ```csc``` tool from https://github.com/thecodeteam/gocsi/tree/master/csc - -## Start Cinder driver - -First, you need to start the plugin as daemon to accept request from csc. -Following example is starting listening at localhost port 10000 with cloud configuration -given in /etc/cloud.conf and the node id is CSINodeID. ClusterID is the identifier of -the cluster in which the plugin is running. - -``` -$ sudo cinder-csi-plugin --endpoint tcp://127.0.0.1:10000 --cloud-config /etc/cloud.conf --nodeid CSINodeID --cluster ClusterID -``` - -## Get plugin info -``` -$ csc identity plugin-info --endpoint tcp://127.0.0.1:10000 -"cinder.csi.openstack.org" "1.0.0" -``` - -## Get supported capabilities -``` -$ csc identity plugin-capabilities --endpoint tcp://127.0.0.1:10000 -CONTROLLER_SERVICE -VOLUME_ACCESSIBILITY_CONSTRAINTS -``` - -## Get controller implemented capabilities -``` -$ csc controller get-capabilities --endpoint tcp://127.0.0.1:10000 -&{type:LIST_VOLUMES } -&{type:CREATE_DELETE_VOLUME } -&{type:PUBLISH_UNPUBLISH_VOLUME } -&{type:CREATE_DELETE_SNAPSHOT } -&{type:LIST_SNAPSHOTS } -``` - -## Create a volume -Following sample creates a volume named ``CSIVolumeName`` and the -volume id returned is ``8a55f98f-e987-43ab-a9f5-973352bee19c`` with size ``1073741824`` bytes (1Gb) -``` -$ csc controller create-volume --endpoint tcp://127.0.0.1:10000 CSIVolumeName -"8a55f98f-e987-43ab-a9f5-973352bee19c" 1073741824 "availability"="nova" -``` - -## List volumes -Following sample list all volumes: -``` -$ csc controller list-volumes --endpoint tcp://127.0.0.1:10000 -"8a55f98f-e987-43ab-a9f5-973352bee19c" 1073741824 -``` - -## Delete a volume -Following sample deletes a volume ``01217e93-bd1b-4760-b5d8-18b8b3d47f91`` -``` -$ csc controller delete-volume --endpoint tcp://127.0.0.1:10000 01217e93-bd1b-4760-b5d8-18b8b3d47f91 -01217e93-bd1b-4760-b5d8-18b8b3d47f91 -``` - -## Create a snapshot from volume -Following sample creates a snapshot from volume `40615da4-3fda-4e78-bf58-820692536e68`. -After execution, snapshot `e2df8c2a-58eb-40fb-8ec9-45aee5b8f39f` will be created. -``` -$ csc controller create-snapshot --source-volume 40615da4-3fda-4e78-bf58-820692536e68 --endpoint tcp://127.0.0.1:10000 s1 -"e2df8c2a-58eb-40fb-8ec9-45aee5b8f39f" 1073741824 40615da4-3fda-4e78-bf58-820692536e68 seconds:1561530261 true -``` - -Use openstack command to verify: -``` -openstack volume snapshot list -+--------------------------------------+------+-------------+-----------+------+ -| ID | Name | Description | Status | Size | -+--------------------------------------+------+-------------+-----------+------+ -| e2df8c2a-58eb-40fb-8ec9-45aee5b8f39f | s1 | None | available | 1 | -+--------------------------------------+------+-------------+-----------+------+ -``` - -## List snapshots - -Following sample lists all snapshots: -``` -$ csc controller list-snapshots --endpoint tcp://127.0.0.1:10000 -"e2df8c2a-58eb-40fb-8ec9-45aee5b8f39f" 1073741824 40615da4-3fda-4e78-bf58-820692536e68 seconds:1561532425 true -``` - -## Delete a snapshot - -Following sample deletes the snapshot `e2df8c2a-58eb-40fb-8ec9-45aee5b8f39f`. -``` -$ csc controller delete-snapshot e2df8c2a-58eb-40fb-8ec9-45aee5b8f39f --endpoint tcp://127.0.0.1:10000 -e2df8c2a-58eb-40fb-8ec9-45aee5b8f39f -``` - -Use openstack command to verify: -``` -$ openstack volume snapshot list - -``` - -## ControllerPublish a volume -The action has similar result to ``nova volume-attach`` command: - -Assume we have following result in openstack now: -``` -$ openstack server list -+--------------------------------------+-------+--------+--------------------------------+--------+---------+ -| ID | Name | Status | Networks | Image | Flavor | -+--------------------------------------+-------+--------+--------------------------------+--------+---------+ -| 17e540e6-8d08-4a5a-8835-668bc8fe913c | demo1 | ACTIVE | demo-net=10.0.0.13 | cirros | m1.tiny | -+--------------------------------------+-------+--------+--------------------------------+--------+---------+ - -$ openstack volume list -+--------------------------------------+-----------------------------------+-----------+------+-------------+ -| ID | Name | Status | Size | Attached to | -+--------------------------------------+-----------------------------------+-----------+------+-------------+ -| ed893ce1-807d-4c6e-a558-88c61b439659 | v1 | available | 1 | | -+--------------------------------------+-----------------------------------+-----------+------+-------------+ -``` - -Then execute: - -``` -# csc controller publish --endpoint tcp://127.0.0.1:10000 --node-id=17e540e6-8d08-4a5a-8835-668bc8fe913c ed893ce1-807d-4c6e-a558-88c61b439659 -"ed893ce1-807d-4c6e-a558-88c61b439659" "DevicePath"="/dev/vdb" -``` - -From openstack side you will see following result: - -``` -$ openstack server list -+--------------------------------------+-------+--------+--------------------------------+--------+---------+ -| ID | Name | Status | Networks | Image | Flavor | -+--------------------------------------+-------+--------+--------------------------------+--------+---------+ -| 17e540e6-8d08-4a5a-8835-668bc8fe913c | demo1 | ACTIVE | demo-net=10.0.0.13 | cirros | m1.tiny | -+--------------------------------------+-------+--------+--------------------------------+--------+---------+ -$ openstack volume list -+--------------------------------------+-----------------------------------+-----------+------+--------------------------------+ -| ID | Name | Status | Size | Attached to | -+--------------------------------------+-----------------------------------+-----------+------+--------------------------------+ -| ed893ce1-807d-4c6e-a558-88c61b439659 | v1 | in-use | 1 | Attached to demo1 on /dev/vdb | -+--------------------------------------+-----------------------------------+-----------+------+--------------------------------+ - -Note: -volume "Status" field will change to "in-use" afterwards. -"Attached to" field will change to volume mount point. -``` - -## ControllerUnpublish a volume -ControllerUnpublish is reserver action of ControllerPublish, which is similar to ``nova volume-detach`` -``` -[root@kvm-017212 docs]# csc controller unpublish --endpoint tcp://127.0.0.1:10000 --node-id=17e540e6-8d08-4a5a-8835-668bc8fe913c ed893ce1-807d-4c6e-a558-88c61b439659 - -ed893ce1-807d-4c6e-a558-88c61b439659 -``` - -## NodePublish a volume -``` -$ csc node publish --endpoint tcp://127.0.0.1:10000 --target-path /mnt/cinder --pub-info DevicePath="/dev/xxx" CSIVolumeID -CSIVolumeID -``` - -## NodeUnpublish a volume -``` -$ csc node unpublish --endpoint tcp://127.0.0.1:10000 --target-path /mnt/cinder CSIVolumeID -CSIVolumeID -``` - -## Get NodeID -``` -$ csc node get-id --endpoint tcp://127.0.0.1:10000 -CSINodeID -``` diff --git a/docs/cinder-csi-plugin/using-cinder-csi-plugin.md b/docs/cinder-csi-plugin/using-cinder-csi-plugin.md index dbbed195b0..52b450356d 100644 --- a/docs/cinder-csi-plugin/using-cinder-csi-plugin.md +++ b/docs/cinder-csi-plugin/using-cinder-csi-plugin.md @@ -56,7 +56,7 @@ In addition to the standard set of klog flags, `cinder-csi-plugin` accepts the f
--nodeid <node id>
- This argument is deprecated, will be removed in future. + This argument is deprecated. It will be removed in future. An identifier for the current node which will be used in OpenStack API calls. This can be either the UUID or name of the OpenStack server, but note that if using name it must be unique.
@@ -335,8 +335,6 @@ Run sanity tests for cinder CSI driver using: $ make test-cinder-csi-sanity ``` -Optionally, to test the driver csc tool could be used. please refer, [usage guide](./csc-tool.md) for more info. - ## In-tree Cinder provisioner to cinder CSI Migration Starting from Kubernetes 1.21, OpenStack Cinder CSI migration is supported as beta feature and is `ON` by default. Cinder CSI driver must be installed on clusters on OpenStack for Cinder volumes to work. If you have persistence volumes that are created with in-tree `kubernetes.io/cinder` plugin, you could migrate to use `cinder.csi.openstack.org` Container Storage Interface (CSI) Driver. diff --git a/docs/manila-csi-plugin/using-manila-csi-plugin.md b/docs/manila-csi-plugin/using-manila-csi-plugin.md index f9e0301ad8..6379e29ab8 100644 --- a/docs/manila-csi-plugin/using-manila-csi-plugin.md +++ b/docs/manila-csi-plugin/using-manila-csi-plugin.md @@ -34,8 +34,8 @@ Option | Default value | Description -------|---------------|------------ `--endpoint` | `unix:///tmp/csi.sock` | CSI Manila's CSI endpoint `--drivername` | `manila.csi.openstack.org` | Name of this driver -`--nodeid` | _none_ | ID of this node -`--nodeaz` | _none_ | Availability zone of this node +`--nodeid` | _none_ | **DEPRECATED** ID of this node. This value is now automatically retrieved from the metadata service. +`--nodeaz` | _none_ | **DEPRECATED** Availability zone of this node. This value is now automatically retrieved from the metadata service. `--runtime-config-file` | _none_ | Path to the [runtime configuration file](#runtime-configuration-file) `--with-topology` | _none_ | CSI Manila is topology-aware. See [Topology-aware dynamic provisioning](#topology-aware-dynamic-provisioning) for more info `--share-protocol-selector` | _none_ | Specifies which Manila share protocol to use for this instance of the driver. See [supported protocols](#share-protocol-support-matrix) for valid values. @@ -103,7 +103,7 @@ With topology awareness enabled, administrators can specify the mapping between Doing so will instruct the CO scheduler to place the workloads+shares only on nodes that are able to reach the underlying storage. CSI Manila uses `topology.manila.csi.openstack.org/zone` _topology key_ to identify node's affinity to a certain compute availability zone. -Each node of the cluster then gets labeled with a key/value pair of `topology.manila.csi.openstack.org/zone` / value of [`--nodeaz`](#command-line-arguments) cmd arg. +Each node of the cluster then gets labeled with the `topology.manila.csi.openstack.org/zone` where the value is the value of the AZ retrieved from the Nova metadata service. This label may be used as a node selector when defining topology constraints for dynamic provisioning. Administrators are also free to pass arbitrary labels, and as long as they are valid node selectors, they will be honored by the scheduler. @@ -258,11 +258,10 @@ To test the deployment further, see `examples/csi-manila-plugin`. If you're deploying CSI Manila with Helm: 1. Set `csimanila.topologyAwarenessEnabled` to `true` -2. Set `csimanila.nodeAZ`. This value will be sourced into the [`--nodeaz`](#command-line-arguments) cmd flag. Bash expressions are also allowed. If you're deploying CSI Manila manually: 1. Run the [external-provisioner](https://github.com/kubernetes-csi/external-provisioner) with `--feature-gates=Topology=true` cmd flag. -2. Run CSI Manila with [`--with-topology`](#command-line-arguments) and set [`--nodeaz`](#command-line-arguments) to node's availability zone. For Nova, the zone may be retrieved via the Metadata service like so: `--nodeaz=$(curl http://169.254.169.254/openstack/latest/meta_data.json | jq -r .availability_zone)` +2. Run CSI Manila with [`--with-topology`](#command-line-arguments). See `examples/csi-manila-plugin/nfs/topology-aware` for examples on defining topology constraints. diff --git a/manifests/manila-csi-plugin/csi-controllerplugin.yaml b/manifests/manila-csi-plugin/csi-controllerplugin.yaml index 25f4d54e3c..d8d9d9e030 100644 --- a/manifests/manila-csi-plugin/csi-controllerplugin.yaml +++ b/manifests/manila-csi-plugin/csi-controllerplugin.yaml @@ -81,16 +81,14 @@ spec: image: registry.k8s.io/provider-os/manila-csi-plugin:v1.31.2 command: ["/bin/sh", "-c", '/bin/manila-csi-plugin - --nodeid=$(NODE_ID) --endpoint=$(CSI_ENDPOINT) --drivername=$(DRIVER_NAME) --share-protocol-selector=$(MANILA_SHARE_PROTO) --fwdendpoint=$(FWD_CSI_ENDPOINT) --pvc-annotations' - # To enable topology awareness and retrieve compute node AZs from the OpenStack Metadata Service, add the following flags: + # To enable topology awareness and retrieve compute node AZs from the OpenStack Metadata Service, add the following flag: # --with-topology - # --nodeaz=$(curl http://169.254.169.254/openstack/latest/meta_data.json | jq -r .availability_zone) - # Those flags need to be added to csi-nodeplugin.yaml as well. + # This flag needs to be added to csi-nodeplugin.yaml as well. ] env: - name: DRIVER_NAME diff --git a/manifests/manila-csi-plugin/csi-nodeplugin.yaml b/manifests/manila-csi-plugin/csi-nodeplugin.yaml index 4dd8aa9956..c098165c64 100644 --- a/manifests/manila-csi-plugin/csi-nodeplugin.yaml +++ b/manifests/manila-csi-plugin/csi-nodeplugin.yaml @@ -53,15 +53,13 @@ spec: image: registry.k8s.io/provider-os/manila-csi-plugin:v1.31.2 command: ["/bin/sh", "-c", '/bin/manila-csi-plugin - --nodeid=$(NODE_ID) --endpoint=$(CSI_ENDPOINT) --drivername=$(DRIVER_NAME) --share-protocol-selector=$(MANILA_SHARE_PROTO) --fwdendpoint=$(FWD_CSI_ENDPOINT)' - # To enable topology awareness and retrieve compute node AZs from the OpenStack Metadata Service, add the following flags: + # To enable topology awareness and retrieve compute node AZs from the OpenStack Metadata Service, add the following flag: # --with-topology - # --nodeaz=$(curl http://169.254.169.254/openstack/latest/meta_data.json | jq -r .availability_zone) - # Those flags need to be added to csi-controllerplugin.yaml as well. + # This flag needs to be added to csi-controllerplugin.yaml as well. ] env: - name: DRIVER_NAME diff --git a/pkg/csi/cinder/controllerserver.go b/pkg/csi/cinder/controllerserver.go index 43b2ba1941..43f54305ec 100644 --- a/pkg/csi/cinder/controllerserver.go +++ b/pkg/csi/cinder/controllerserver.go @@ -121,7 +121,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol } // Volume Create - properties := map[string]string{cinderCSIClusterIDKey: cs.Driver.cluster} + properties := map[string]string{cinderCSIClusterIDKey: cs.Driver.clusterID} //Tag volume with metadata if present: https://github.com/kubernetes-csi/external-provisioner/pull/399 for _, mKey := range sharedcsi.RecognizedCSIProvisionerParams { if v, ok := req.Parameters[mKey]; ok { @@ -764,7 +764,7 @@ func (cs *controllerServer) createSnapshot(cloud openstack.IOpenStack, name stri } // Add cluster ID to the snapshot metadata - properties := map[string]string{cinderCSIClusterIDKey: cs.Driver.cluster} + properties := map[string]string{cinderCSIClusterIDKey: cs.Driver.clusterID} // see https://github.com/kubernetes-csi/external-snapshotter/pull/375/ // Also, we don't want to tag every param but we still want to send the @@ -790,7 +790,7 @@ func (cs *controllerServer) createSnapshot(cloud openstack.IOpenStack, name stri func (cs *controllerServer) createBackup(cloud openstack.IOpenStack, name string, volumeID string, snap *snapshots.Snapshot, parameters map[string]string) (*backups.Backup, error) { // Add cluster ID to the snapshot metadata - properties := map[string]string{cinderCSIClusterIDKey: cs.Driver.cluster} + properties := map[string]string{cinderCSIClusterIDKey: cs.Driver.clusterID} // see https://github.com/kubernetes-csi/external-snapshotter/pull/375/ // Also, we don't want to tag every param but we still want to send the diff --git a/pkg/csi/cinder/driver.go b/pkg/csi/cinder/driver.go index bd5180a03e..85ceea0a1f 100644 --- a/pkg/csi/cinder/driver.go +++ b/pkg/csi/cinder/driver.go @@ -66,16 +66,17 @@ type Driver struct { name string fqVersion string //Fully qualified version in format {Version}@{CPO version} endpoint string - cluster string + clusterID string - ids *identityServer - cs *controllerServer - ns *nodeServer - pvcLister v1.PersistentVolumeClaimLister + ids *identityServer + cs *controllerServer + ns *nodeServer vcap []*csi.VolumeCapability_AccessMode cscap []*csi.ControllerServiceCapability nscap []*csi.NodeServiceCapability + + pvcLister v1.PersistentVolumeClaimLister } type DriverOpts struct { @@ -89,7 +90,7 @@ func NewDriver(o *DriverOpts) *Driver { name: driverName, fqVersion: fmt.Sprintf("%s@%s", Version, version.Version), endpoint: o.Endpoint, - cluster: o.ClusterID, + clusterID: o.ClusterID, pvcLister: o.PVCLister, } diff --git a/pkg/csi/manila/driver.go b/pkg/csi/manila/driver.go index 8b888d0907..b792c1d3b7 100644 --- a/pkg/csi/manila/driver.go +++ b/pkg/csi/manila/driver.go @@ -32,35 +32,18 @@ import ( "k8s.io/client-go/listers/core/v1" "k8s.io/cloud-provider-openstack/pkg/csi/manila/csiclient" "k8s.io/cloud-provider-openstack/pkg/csi/manila/manilaclient" + "k8s.io/cloud-provider-openstack/pkg/util/metadata" "k8s.io/cloud-provider-openstack/pkg/version" "k8s.io/klog/v2" ) -type DriverOpts struct { - DriverName string - NodeID string - NodeAZ string - WithTopology bool - ShareProto string - ClusterID string - - ServerCSIEndpoint string - FwdCSIEndpoint string - - ManilaClientBuilder manilaclient.Builder - CSIClientBuilder csiclient.Builder - - PVCLister v1.PersistentVolumeClaimLister -} - type Driver struct { - nodeID string - nodeAZ string + name string + fqVersion string // Fully qualified version in format {driverVersion}@{CPO version} + shareProto string + clusterID string + withTopology bool - name string - fqVersion string // Fully qualified version in format {driverVersion}@{CPO version} - shareProto string - clusterID string serverEndpoint string fwdEndpoint string @@ -79,6 +62,22 @@ type Driver struct { pvcLister v1.PersistentVolumeClaimLister } +type DriverOpts struct { + DriverName string + ShareProto string + ClusterID string + + WithTopology bool + + ServerCSIEndpoint string + FwdCSIEndpoint string + + ManilaClientBuilder manilaclient.Builder + CSIClientBuilder csiclient.Builder + + PVCLister v1.PersistentVolumeClaimLister +} + type nonBlockingGRPCServer struct { wg sync.WaitGroup server *grpc.Server @@ -117,8 +116,6 @@ func NewDriver(o *DriverOpts) (*Driver, error) { d := &Driver{ fqVersion: fmt.Sprintf("%s@%s", driverVersion, version.Version), - nodeID: o.NodeID, - nodeAZ: o.NodeAZ, withTopology: o.WithTopology, name: o.DriverName, serverEndpoint: o.ServerCSIEndpoint, @@ -138,7 +135,7 @@ func NewDriver(o *DriverOpts) (*Driver, error) { klog.Infof("Operating on %s shares", d.shareProto) if d.withTopology { - klog.Infof("Topology awareness enabled, node availability zone: %s", d.nodeAZ) + klog.Infof("Topology awareness enabled") } else { klog.Info("Topology awareness disabled") } @@ -182,11 +179,7 @@ func (d *Driver) SetupControllerService() error { return nil } -func (d *Driver) SetupNodeService() error { - if err := argNotEmpty(d.nodeID, "node ID"); err != nil { - return err - } - +func (d *Driver) SetupNodeService(metadata metadata.IMetadata) error { klog.Info("Providing node service") var supportsNodeStage bool @@ -206,7 +199,12 @@ func (d *Driver) SetupNodeService() error { d.addNodeServiceCapabilities(nscaps) - d.ns = &nodeServer{d: d, supportsNodeStage: supportsNodeStage, nodeStageCache: make(map[volumeID]stageCacheEntry)} + d.ns = &nodeServer{ + d: d, + metadata: metadata, + supportsNodeStage: supportsNodeStage, + nodeStageCache: make(map[volumeID]stageCacheEntry), + } return nil } diff --git a/pkg/csi/manila/nodeserver.go b/pkg/csi/manila/nodeserver.go index 0c9da1824c..7b6a405b61 100644 --- a/pkg/csi/manila/nodeserver.go +++ b/pkg/csi/manila/nodeserver.go @@ -29,12 +29,14 @@ import ( "k8s.io/cloud-provider-openstack/pkg/csi/manila/options" "k8s.io/cloud-provider-openstack/pkg/csi/manila/shareadapters" clouderrors "k8s.io/cloud-provider-openstack/pkg/util/errors" + "k8s.io/cloud-provider-openstack/pkg/util/metadata" "k8s.io/klog/v2" ) type nodeServer struct { d *Driver + metadata metadata.IMetadata supportsNodeStage bool // The result of NodeStageVolume is stashed away for NodePublishVolume(s) that will follow nodeStageCache map[volumeID]stageCacheEntry @@ -324,13 +326,23 @@ func (ns *nodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstag } func (ns *nodeServer) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error) { + nodeID, err := ns.metadata.GetInstanceID() + if err != nil { + return nil, status.Errorf(codes.Internal, "[NodeGetInfo] unable to retrieve instance id of node %v", err) + } + nodeInfo := &csi.NodeGetInfoResponse{ - NodeId: ns.d.nodeID, + NodeId: nodeID, } if ns.d.withTopology { + zone, err := ns.metadata.GetAvailabilityZone() + if err != nil { + return nil, status.Errorf(codes.Internal, "[NodeGetInfo] Unable to retrieve availability zone of node %v", err) + } + nodeInfo.AccessibleTopology = &csi.Topology{ - Segments: map[string]string{topologyKey: ns.d.nodeAZ}, + Segments: map[string]string{topologyKey: zone}, } } diff --git a/tests/sanity/cinder/sanity_test.go b/tests/sanity/cinder/sanity_test.go index 3857c5d96e..c404a4c102 100644 --- a/tests/sanity/cinder/sanity_test.go +++ b/tests/sanity/cinder/sanity_test.go @@ -27,14 +27,14 @@ func TestDriver(t *testing.T) { } fakemnt := GetFakeMountProvider() - fakemet := &fakemetadata{} + fakemeta := &fakemetadata{} fakeOpts := openstack.BlockStorageOpts{ RescanOnResize: false, NodeVolumeAttachLimit: 200, } d.SetupControllerService(openstack.OsInstances) - d.SetupNodeService(fakemnt, fakemet, fakeOpts, map[string]string{}) + d.SetupNodeService(fakemnt, fakemeta, fakeOpts, map[string]string{}) // TODO: Stop call diff --git a/tests/sanity/manila/fakemetadata.go b/tests/sanity/manila/fakemetadata.go new file mode 100644 index 0000000000..4e7d33a0a2 --- /dev/null +++ b/tests/sanity/manila/fakemetadata.go @@ -0,0 +1,16 @@ +package sanity + +var FakeInstanceID = "321a8b81-3660-43e5-bab8-6470b65ee4e8" +var FakeAvailability = "fake-az" + +type fakemetadata struct{} + +// fake metadata + +func (m *fakemetadata) GetInstanceID() (string, error) { + return FakeInstanceID, nil +} + +func (m *fakemetadata) GetAvailabilityZone() (string, error) { + return FakeAvailability, nil +} diff --git a/tests/sanity/manila/sanity_test.go b/tests/sanity/manila/sanity_test.go index 8a9d672f85..0219e2b894 100644 --- a/tests/sanity/manila/sanity_test.go +++ b/tests/sanity/manila/sanity_test.go @@ -35,9 +35,7 @@ func TestDriver(t *testing.T) { d, err := manila.NewDriver( &manila.DriverOpts{ DriverName: "fake.manila.csi.openstack.org", - NodeID: "node", WithTopology: true, - NodeAZ: "fake-az", ShareProto: "NFS", ServerCSIEndpoint: endpoint, FwdCSIEndpoint: fwdEndpoint, @@ -54,7 +52,9 @@ func TestDriver(t *testing.T) { t.Fatalf("Failed to initialize CSI Manila controller service: %v", err) } - err = d.SetupNodeService() + fakemeta := &fakemetadata{} + + err = d.SetupNodeService(fakemeta) if err != nil { t.Fatalf("Failed to initialize CSI Manila node service: %v", err) }