Skip to content

Commit

Permalink
[cinder-csi-plugin] Tag volume with optional pvc/pv metadata (kuberne…
Browse files Browse the repository at this point in the history
…tes#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]>
  • Loading branch information
databus23 authored Apr 29, 2021
1 parent a7daffa commit bed7879
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion charts/cinder-csi-plugin/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v1
appVersion: latest
description: Cinder CSI Chart for OpenStack
name: openstack-cinder-csi
version: 1.3.6
version: 1.3.7
home: https://github.com/kubernetes/cloud-provider-openstack
icon: https://github.com/kubernetes/kubernetes/blob/master/logo/logo.png
maintainers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ spec:
- "--timeout={{ .Values.timeout }}"
- "--default-fstype=ext4"
- "--feature-gates=Topology={{ .Values.csi.provisioner.topology }}"
- "--extra-create-metadata"
env:
- name: ADDRESS
value: /var/lib/csi/sockets/pluginproxy/csi.sock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ spec:
- "--timeout=3m"
- "--default-fstype=ext4"
- "--feature-gates=Topology=true"
- "--extra-create-metadata"
env:
- name: ADDRESS
value: /var/lib/csi/sockets/pluginproxy/csi.sock
Expand Down
6 changes: 6 additions & 0 deletions pkg/csi/cinder/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol

// Volume Create
properties := map[string]string{"cinder.csi.openstack.org/cluster": cs.Driver.cluster}
//Tag volume with metadata if present: https://github.com/kubernetes-csi/external-provisioner/pull/399
for _, mKey := range []string{"csi.storage.k8s.io/pvc/name", "csi.storage.k8s.io/pvc/namespace", "csi.storage.k8s.io/pv/name"} {
if v, ok := req.Parameters[mKey]; ok {
properties[mKey] = v
}
}
content := req.GetVolumeContentSource()
var snapshotID string
var sourcevolID string
Expand Down
47 changes: 47 additions & 0 deletions pkg/csi/cinder/controllerserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,53 @@ func TestCreateVolume(t *testing.T) {

}

func TestCreateVolumeWithExtraMetadata(t *testing.T) {

// mock OpenStack
properties := map[string]string{
"cinder.csi.openstack.org/cluster": FakeCluster,
"csi.storage.k8s.io/pv/name": FakePVName,
"csi.storage.k8s.io/pvc/name": FakePVCName,
"csi.storage.k8s.io/pvc/namespace": FakePVCNamespace,
}
// CreateVolume(name string, size int, vtype, availability string, snapshotID string, tags *map[string]string) (string, string, int, error)
osmock.On("CreateVolume", FakeVolName, mock.AnythingOfType("int"), FakeVolType, FakeAvailability, "", "", &properties).Return(&FakeVol, nil)

osmock.On("GetVolumesByName", FakeVolName).Return(FakeVolListEmpty, nil)

// Fake request
fakeReq := &csi.CreateVolumeRequest{
Name: FakeVolName,
Parameters: map[string]string{
"csi.storage.k8s.io/pv/name": FakePVName,
"csi.storage.k8s.io/pvc/name": FakePVCName,
"csi.storage.k8s.io/pvc/namespace": FakePVCNamespace,
},
VolumeCapabilities: []*csi.VolumeCapability{
{
AccessMode: &csi.VolumeCapability_AccessMode{
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
},
},
},

AccessibilityRequirements: &csi.TopologyRequirement{
Requisite: []*csi.Topology{
{
Segments: map[string]string{"topology.cinder.csi.openstack.org/zone": FakeAvailability},
},
},
},
}

// Invoke CreateVolume
_, err := fakeCs.CreateVolume(FakeCtx, fakeReq)
if err != nil {
t.Errorf("failed to CreateVolume: %v", err)
}

}

func TestCreateVolumeFromSnapshot(t *testing.T) {

properties := map[string]string{"cinder.csi.openstack.org/cluster": FakeCluster}
Expand Down
3 changes: 3 additions & 0 deletions pkg/csi/cinder/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ var FakeAvailability = "nova"
var FakeDevicePath = "/dev/xxx"
var FakeTargetPath = "/mnt/cinder"
var FakeStagingTargetPath = "/mnt/globalmount"
var FakePVName = "fakepv-1"
var FakePVCName = "fakepvc-1"
var FakePVCNamespace = "fakepvc-ns"
var FakeAttachment = volumes.Attachment{
ServerID: FakeNodeID,
}
Expand Down

0 comments on commit bed7879

Please sign in to comment.