Skip to content

Commit 7bfb2eb

Browse files
authored
[csi-plugins] add support for PVC annotations (#2687)
* [csi-plugins] add support for PVC annotations * Add support for volume/share name resolve * Add a timeout to a e2e job, so we can fetch logs
1 parent bf31268 commit 7bfb2eb

File tree

36 files changed

+774
-212
lines changed

36 files changed

+774
-212
lines changed

charts/cinder-csi-plugin/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v1
22
appVersion: v1.31.0
33
description: Cinder CSI Chart for OpenStack
44
name: openstack-cinder-csi
5-
version: 2.31.3
5+
version: 2.31.4
66
home: https://github.com/kubernetes/cloud-provider-openstack
77
icon: https://github.com/kubernetes/kubernetes/blob/master/logo/logo.png
88
maintainers:

charts/cinder-csi-plugin/templates/controllerplugin-deployment.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ spec:
175175
{{- if .Values.csi.plugin.httpEndpoint.enabled }}
176176
- "--http-endpoint=:{{ .Values.csi.plugin.httpEndpoint.port }}"
177177
{{- end }}
178+
{{- if .Values.pvcAnnotations }}
179+
- "--pvc-annotations"
180+
{{- end }}
178181
{{- if .Values.csi.plugin.extraArgs }}
179182
{{- with .Values.csi.plugin.extraArgs }}
180183
{{- tpl . $ | trim | nindent 12 }}

charts/cinder-csi-plugin/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ storageClass:
207207
# to volume metadata in newly provisioned volumes as `cinder.csi.openstack.org/cluster=<cluster ID>`.
208208
clusterID: "kubernetes"
209209

210+
# Enable PVC annotations support to create PVCs with extra parameters
211+
pvcAnnotations: false
212+
210213
priorityClassName: ""
211214

212215
imagePullSecrets: []

charts/manila-csi-plugin/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v1
22
appVersion: v1.31.0
33
description: Manila CSI Chart for OpenStack
44
name: openstack-manila-csi
5-
version: 2.31.0
5+
version: 2.31.1
66
home: http://github.com/kubernetes/cloud-provider-openstack
77
icon: https://github.com/kubernetes/kubernetes/blob/master/logo/logo.png
88
maintainers:

charts/manila-csi-plugin/templates/controllerplugin-statefulset.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ spec:
2626
{{- if $.Values.csimanila.topologyAwarenessEnabled }}
2727
- "--feature-gates=Topology=true"
2828
{{- end }}
29-
{{- if $.Values.controllerplugin.provisioner.extraCreateMetadata }}
29+
{{- if or $.Values.controllerplugin.provisioner.extraCreateMetadata $.Values.csimanila.pvcAnnotations }}
3030
- "--extra-create-metadata"
3131
{{- end }}
3232
env:
@@ -101,7 +101,10 @@ spec:
101101
{{- if .compatibilitySettings }}
102102
--compatibility-settings={{ .compatibilitySettings }}
103103
{{- end }}
104-
--cluster-id="{{ $.Values.csimanila.clusterID }}"'
104+
--cluster-id="{{ $.Values.csimanila.clusterID }}"
105+
{{- if $.Values.csimanila.pvcAnnotations }}
106+
--pvc-annotations
107+
{{- end }}'
105108
]
106109
env:
107110
- name: DRIVER_NAME

charts/manila-csi-plugin/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ csimanila:
4343
# to share metadata in newly provisioned shares as `manila.csi.openstack.org/cluster=<cluster ID>`.
4444
clusterID: ""
4545

46+
# Enable PVC annotations support to create PVCs with extra parameters
47+
pvcAnnotations: false
48+
4649
# Image spec
4750
image:
4851
repository: registry.k8s.io/provider-os/manila-csi-plugin

cmd/cinder-csi-plugin/main.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
"github.com/spf13/cobra"
2424
"github.com/spf13/pflag"
25+
"k8s.io/cloud-provider-openstack/pkg/csi"
2526
"k8s.io/cloud-provider-openstack/pkg/csi/cinder"
2627
"k8s.io/cloud-provider-openstack/pkg/csi/cinder/openstack"
2728
"k8s.io/cloud-provider-openstack/pkg/util/metadata"
@@ -72,6 +73,8 @@ func main() {
7273
Version: version.Version,
7374
}
7475

76+
csi.AddPVCFlags(cmd)
77+
7578
cmd.PersistentFlags().StringVar(&nodeID, "nodeid", "", "node id")
7679
if err := cmd.PersistentFlags().MarkDeprecated("nodeid", "This flag would be removed in future. Currently, the value is ignored by the driver"); err != nil {
7780
klog.Fatalf("Unable to mark flag nodeid to be deprecated: %v", err)
@@ -103,7 +106,11 @@ func main() {
103106

104107
func handle() {
105108
// Initialize cloud
106-
d := cinder.NewDriver(&cinder.DriverOpts{Endpoint: endpoint, ClusterID: cluster})
109+
d := cinder.NewDriver(&cinder.DriverOpts{
110+
Endpoint: endpoint,
111+
ClusterID: cluster,
112+
PVCLister: csi.GetPVCLister(),
113+
})
107114

108115
openstack.InitOpenStackProvider(cloudConfig, httpEndpoint)
109116

cmd/manila-csi-plugin/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"strings"
2323

2424
"github.com/spf13/cobra"
25+
"k8s.io/cloud-provider-openstack/pkg/csi"
2526
"k8s.io/cloud-provider-openstack/pkg/csi/manila"
2627
"k8s.io/cloud-provider-openstack/pkg/csi/manila/csiclient"
2728
"k8s.io/cloud-provider-openstack/pkg/csi/manila/manilaclient"
@@ -86,6 +87,7 @@ func main() {
8687
ManilaClientBuilder: manilaClientBuilder,
8788
CSIClientBuilder: csiClientBuilder,
8889
ClusterID: clusterID,
90+
PVCLister: csi.GetPVCLister(),
8991
}
9092

9193
if provideNodeService {
@@ -119,6 +121,8 @@ func main() {
119121
Version: version.Version,
120122
}
121123

124+
csi.AddPVCFlags(cmd)
125+
122126
cmd.PersistentFlags().StringVar(&endpoint, "endpoint", "unix://tmp/csi.sock", "CSI endpoint")
123127

124128
cmd.PersistentFlags().StringVar(&driverName, "drivername", "manila.csi.openstack.org", "name of the driver")

docs/cinder-csi-plugin/examples.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- [Snapshot Create and Restore](#snapshot-create-and-restore)
1111
- [Use Topology](#use-topology)
1212
- [Disaster recovery of PV and PVC](#disaster-recovery-of-pv-and-pvc)
13+
- [Use scheduler hints annotations](#use-scheduler-hints-annotations)
1314

1415
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
1516

@@ -453,3 +454,51 @@ spec:
453454
storageClassName: sata
454455
volumeMode: Filesystem
455456
```
457+
458+
## Use scheduler hints annotations
459+
460+
Cinder CSI driver supports the use of scheduler hints to influence the
461+
placement of volumes. Scheduler hints can be specified in the
462+
PersistentVolumeClaim (PVC) annotations:
463+
464+
* `cinder.csi.openstack.org/affinity`
465+
* `cinder.csi.openstack.org/anti-affinity`
466+
467+
In order to use scheduler hints, the Cinder CSI controller plugin must be
468+
started with the `--pvc-annotations` flag. The PVC annotations take effect only
469+
when the PVC is created. The scheduler hints are not updated when the PVC is
470+
updated. The following example demonstrates how to use scheduler hints to
471+
influence the placement of volumes:
472+
473+
```
474+
$ kubectl apply -f scheduler-hints-pvc.yaml
475+
```
476+
477+
```
478+
apiVersion: v1
479+
kind: PersistentVolumeClaim
480+
metadata:
481+
name: csi-pvc-cinderplugin
482+
annotations:
483+
cinder.csi.openstack.org/affinity: "1b4e28ba-2fa1-11ec-8d3d-0242ac130003"
484+
cinder.csi.openstack.org/anti-affinity: "1b4e28ba-2fa1-11ec-8d3d-0242ac130004,pv-k8s--cluster-1b5f47bf-0119-442e-8529-254c36e43644"
485+
spec:
486+
accessModes:
487+
- ReadWriteOnce
488+
resources:
489+
requests:
490+
storage: 1Gi
491+
storageClassName: csi-sc-cinderplugin
492+
```
493+
494+
where `1b4e28ba-2fa1-11ec-8d3d-0242ac130003`,
495+
`1b4e28ba-2fa1-11ec-8d3d-0242ac130004` and
496+
`pv-k8s--cluster-1b5f47bf-0119-442e-8529-254c36e43644` are names or UUIDs of
497+
the already provisioned volumes in the OpenStack cloud. The scheduler will try
498+
to place the volume in the same block storage server as the volume with the
499+
`1b4e28ba-2fa1-11ec-8d3d-0242ac130003` UUID and avoid placing the volume in the
500+
same block storage server as the volumes with the
501+
`1b4e28ba-2fa1-11ec-8d3d-0242ac130004` UUID and the
502+
`pv-k8s--cluster-1b5f47bf-0119-442e-8529-254c36e43644` volume name. If the
503+
scheduler hints are not satisfied, the volume will not be provisioned with an
504+
error message in the controller logs.

docs/cinder-csi-plugin/using-cinder-csi-plugin.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- [Supported Features](#supported-features)
1818
- [Sidecar Compatibility](#sidecar-compatibility)
1919
- [Supported Parameters](#supported-parameters)
20+
- [Supported PVC Annotations](#supported-pvc-annotations)
2021
- [Local Development](#local-development)
2122
- [Build](#build)
2223
- [Testing](#testing)
@@ -110,6 +111,14 @@ In addition to the standard set of klog flags, `cinder-csi-plugin` accepts the f
110111
If set to true then the CSI driver does provide the node service.
111112

112113
The default is to provide the node service.
114+
115+
<dt>--pvc-annotations &lt;disabled&gt;</dt>
116+
<dd>
117+
If set to true then the CSI driver will use PVC annotations to provide volume
118+
scheduler hints. See [Supported PVC Annotations](#supported-pvc-annotations)
119+
for more information.
120+
121+
The default is not to provide the PVC annotations support.
113122
</dd>
114123
</dl>
115124

@@ -273,6 +282,24 @@ helm install --namespace kube-system --name cinder-csi ./charts/cinder-csi-plugi
273282
| Inline Volume `volumeAttributes` | `capacity` | `1Gi` | volume size for creating inline volumes|
274283
| Inline Volume `VolumeAttributes` | `type` | Empty String | Name/ID of Volume type. Corresponding volume type should exist in cinder |
275284

285+
## Supported PVC Annotations
286+
287+
The PVC annotations support must be enabled in the Cinder CSI controller with
288+
the `--pvc-annotations` flag. The PVC annotations take effect only when the PVC
289+
is created. The scheduler hints are not updated when the PVC is updated. The
290+
following PVC annotations are supported:
291+
292+
| Annotation Name | Description | Example |
293+
|------------------------- |-----------------|----------|
294+
| `cinder.csi.openstack.org/affinity` | Volume affinity to existing volume or volumes names/UUIDs. The value should be a comma-separated list of volume names/UUIDs. | `cinder.csi.openstack.org/affinity: "1b4e28ba-2fa1-11ec-8d3d-0242ac130003"` |
295+
| `cinder.csi.openstack.org/anti-affinity` | Volume anti-affinity to existing volume or volumes names/UUIDs. The value should be a comma-separated list of volume names/UUIDs. | `cinder.csi.openstack.org/anti-affinity: "1b4e28ba-2fa1-11ec-8d3d-0242ac130004,pv-k8s--cluster-1b5f47bf-0119-442e-8529-254c36e43644"` |
296+
297+
If the PVC annotation is set, the volume will be created according to the
298+
existing volume names/UUIDs placements, i.e. on the same host as the
299+
`1b4e28ba-2fa1-11ec-8d3d-0242ac130003` volume and not on the same host as the
300+
`1b4e28ba-2fa1-11ec-8d3d-0242ac130004` and
301+
`pv-k8s--cluster-1b5f47bf-0119-442e-8529-254c36e43644` volumes.
302+
276303
## Local Development
277304

278305
### Build

0 commit comments

Comments
 (0)