Skip to content

Commit 1dc67d5

Browse files
authored
[cinder-csi-plugin] Tag volume with optional pvc/pv metadata (kubernetes#1492)
* [cinder-csi-plugin] Tag volume with optional metadata The external CSI provisioner optionally injects metadata in the CreateVolume that we can pass onto the volume as additional tags. See kubernetes-csi/external-provisioner#399 Signed-off-by: Fabian Ruff <[email protected]> * Add --extra-create-metadata to csi-provisoner manifests Signed-off-by: Fabian Ruff <[email protected]> * Add unit test for extra metadata Signed-off-by: Fabian Ruff <[email protected]> * Bump chart again. Signed-off-by: Fabian Ruff <[email protected]>
1 parent ddc7a5b commit 1dc67d5

File tree

6 files changed

+59
-1
lines changed

6 files changed

+59
-1
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: latest
33
description: Cinder CSI Chart for OpenStack
44
name: openstack-cinder-csi
5-
version: 1.3.6
5+
version: 1.3.7
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-statefulset.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ spec:
4646
- "--timeout={{ .Values.timeout }}"
4747
- "--default-fstype=ext4"
4848
- "--feature-gates=Topology={{ .Values.csi.provisioner.topology }}"
49+
- "--extra-create-metadata"
4950
env:
5051
- name: ADDRESS
5152
value: /var/lib/csi/sockets/pluginproxy/csi.sock

manifests/cinder-csi-plugin/cinder-csi-controllerplugin.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ spec:
5454
- "--timeout=3m"
5555
- "--default-fstype=ext4"
5656
- "--feature-gates=Topology=true"
57+
- "--extra-create-metadata"
5758
env:
5859
- name: ADDRESS
5960
value: /var/lib/csi/sockets/pluginproxy/csi.sock

pkg/csi/cinder/controllerserver.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
103103

104104
// Volume Create
105105
properties := map[string]string{"cinder.csi.openstack.org/cluster": cs.Driver.cluster}
106+
//Tag volume with metadata if present: https://github.com/kubernetes-csi/external-provisioner/pull/399
107+
for _, mKey := range []string{"csi.storage.k8s.io/pvc/name", "csi.storage.k8s.io/pvc/namespace", "csi.storage.k8s.io/pv/name"} {
108+
if v, ok := req.Parameters[mKey]; ok {
109+
properties[mKey] = v
110+
}
111+
}
106112
content := req.GetVolumeContentSource()
107113
var snapshotID string
108114
var sourcevolID string

pkg/csi/cinder/controllerserver_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,53 @@ func TestCreateVolume(t *testing.T) {
8787

8888
}
8989

90+
func TestCreateVolumeWithExtraMetadata(t *testing.T) {
91+
92+
// mock OpenStack
93+
properties := map[string]string{
94+
"cinder.csi.openstack.org/cluster": FakeCluster,
95+
"csi.storage.k8s.io/pv/name": FakePVName,
96+
"csi.storage.k8s.io/pvc/name": FakePVCName,
97+
"csi.storage.k8s.io/pvc/namespace": FakePVCNamespace,
98+
}
99+
// CreateVolume(name string, size int, vtype, availability string, snapshotID string, tags *map[string]string) (string, string, int, error)
100+
osmock.On("CreateVolume", FakeVolName, mock.AnythingOfType("int"), FakeVolType, FakeAvailability, "", "", &properties).Return(&FakeVol, nil)
101+
102+
osmock.On("GetVolumesByName", FakeVolName).Return(FakeVolListEmpty, nil)
103+
104+
// Fake request
105+
fakeReq := &csi.CreateVolumeRequest{
106+
Name: FakeVolName,
107+
Parameters: map[string]string{
108+
"csi.storage.k8s.io/pv/name": FakePVName,
109+
"csi.storage.k8s.io/pvc/name": FakePVCName,
110+
"csi.storage.k8s.io/pvc/namespace": FakePVCNamespace,
111+
},
112+
VolumeCapabilities: []*csi.VolumeCapability{
113+
{
114+
AccessMode: &csi.VolumeCapability_AccessMode{
115+
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
116+
},
117+
},
118+
},
119+
120+
AccessibilityRequirements: &csi.TopologyRequirement{
121+
Requisite: []*csi.Topology{
122+
{
123+
Segments: map[string]string{"topology.cinder.csi.openstack.org/zone": FakeAvailability},
124+
},
125+
},
126+
},
127+
}
128+
129+
// Invoke CreateVolume
130+
_, err := fakeCs.CreateVolume(FakeCtx, fakeReq)
131+
if err != nil {
132+
t.Errorf("failed to CreateVolume: %v", err)
133+
}
134+
135+
}
136+
90137
func TestCreateVolumeFromSnapshot(t *testing.T) {
91138

92139
properties := map[string]string{"cinder.csi.openstack.org/cluster": FakeCluster}

pkg/csi/cinder/fake.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ var FakeAvailability = "nova"
3838
var FakeDevicePath = "/dev/xxx"
3939
var FakeTargetPath = "/mnt/cinder"
4040
var FakeStagingTargetPath = "/mnt/globalmount"
41+
var FakePVName = "fakepv-1"
42+
var FakePVCName = "fakepvc-1"
43+
var FakePVCNamespace = "fakepvc-ns"
4144
var FakeAttachment = volumes.Attachment{
4245
ServerID: FakeNodeID,
4346
}

0 commit comments

Comments
 (0)