Custom templates, remove volume from StorageClass

This commit is contained in:
Kim Wittenburg 2022-04-16 17:01:59 +02:00
parent 7f998ebec2
commit 7b4d6a9a05
4 changed files with 25 additions and 20 deletions

View File

@ -16,7 +16,6 @@ metadata:
parameters: parameters:
fsType: ext4 fsType: ext4
# The following options affect the LUN representing the volume # The following options affect the LUN representing the volume
volume: /volume2 # Optional. Override the volume on which the LUN will be created.
lunType: BLUN # Btrfs thin provisioning lunType: BLUN # Btrfs thin provisioning
lunType: BLUN_THICK # Btrfs thick provisioning lunType: BLUN_THICK # Btrfs thick provisioning
lunType: THIN # Ext4 thin provisioning lunType: THIN # Ext4 thin provisioning
@ -34,10 +33,18 @@ parameters:
# The following options affect the iSCSI target # The following options affect the iSCSI target
headerDigenst: false headerDigenst: false
dataDigest: false dataDigest: false
maxSessions: 1 # Note that this option requires a compatible filesystem maxSessions: 1 # Note that this option requires a compatible filesystem. Use 0 for unlimited sessions (default).
maxRecieveSegmentBytes: 262144 maxRecieveSegmentBytes: 262144
maxSendSegmentBytes: 262144 maxSendSegmentBytes: 262144
... lunTemplate: |
# This inline yaml object will be passed to the Synology API when creating the LUN. Use this for custom options.
dev_attribs:
- dev_attrib: emulate_caw
enable: 1
targetTemplate: |
# This inline yaml object will be passed to the Synology API when creating the target. Use this for custom
# options.
max_sessions: 0
``` ```
About extended features: About extended features:
@ -61,6 +68,10 @@ parameters:
# Note that AppConsistent snapshots require a working Synology Storage Console. Otherwise both values will have # Note that AppConsistent snapshots require a working Synology Storage Console. Otherwise both values will have
# equivalent behavior. # equivalent behavior.
consistency: AppConsistent # Or CrashConsistent consistency: AppConsistent # Or CrashConsistent
lunSnapshotTemplate: |
# This inline yaml object will be passed to the Synology API when creating the snapshot. Use this for custom
# options.
is_locked: true
... ...
``` ```

View File

@ -10,8 +10,7 @@ httpConnection:
session: "democratic-csi" session: "democratic-csi"
serialize: true serialize: true
# choose the default volume for your system. The default value is /volume1. # Choose the DSM volume this driver operates on. The default value is /volume1.
# This can also be overridden by StorageClasses
# synology: # synology:
# volume: /volume1 # volume: /volume1

View File

@ -39,12 +39,7 @@ class SynologyError extends GrpcError {
class SynologyHttpClient { class SynologyHttpClient {
constructor(options = {}) { constructor(options = {}) {
this.options = Object.assign({ this.options = JSON.parse(JSON.stringify(options));
protocol: "https",
port: 5001,
allowInsecure: false,
session: "democratic-csi"
}, JSON.parse(JSON.stringify(options)));
this.logger = console; this.logger = console;
this.doLoginMutex = new Mutex(); this.doLoginMutex = new Mutex();
this.apiSerializeMutex = new Mutex(); this.apiSerializeMutex = new Mutex();

View File

@ -4,6 +4,7 @@ const registry = require("../../utils/registry");
const SynologyHttpClient = require("./http").SynologyHttpClient; const SynologyHttpClient = require("./http").SynologyHttpClient;
const semver = require("semver"); const semver = require("semver");
const sleep = require("../../utils/general").sleep; const sleep = require("../../utils/general").sleep;
const yaml = require("js-yaml");
const __REGISTRY_NS__ = "ControllerSynologyDriver"; const __REGISTRY_NS__ = "ControllerSynologyDriver";
@ -181,8 +182,8 @@ class ControllerSynologyDriver extends CsiBaseDriver {
* @param {String} parameters.volume - The volume specified by the StorageClass * @param {String} parameters.volume - The volume specified by the StorageClass
* @returns {String} The location of the volume. * @returns {String} The location of the volume.
*/ */
getLocation({volume}) { getLocation() {
let location = volume ?? this.options?.synology?.volume let location = this.options?.synology?.volume;
if (location === undefined) { if (location === undefined) {
location = "volume1" location = "volume1"
} }
@ -469,7 +470,7 @@ class ControllerSynologyDriver extends CsiBaseDriver {
await httpClient.CreateClonedVolume( await httpClient.CreateClonedVolume(
src_lun_uuid, src_lun_uuid,
iscsiName, iscsiName,
driver.getLocation(normalizedParameters), driver.getLocation(),
normalizedParameters.description normalizedParameters.description
); );
} }
@ -490,9 +491,9 @@ class ControllerSynologyDriver extends CsiBaseDriver {
} }
} else { } else {
// create lun // create lun
data = Object.assign({}, driver.options.iscsi.lunTemplate, { data = Object.assign({}, driver.options.iscsi.lunTemplate, yaml.load(normalizedParameters.lunTemplate), {
name: iscsiName, name: iscsiName,
location: driver.getLocation(normalizedParameters), location: driver.getLocation(),
size: capacity_bytes size: capacity_bytes
}); });
data.type = normalizedParameters.lunType ?? data.type; data.type = normalizedParameters.lunType ?? data.type;
@ -550,7 +551,7 @@ class ControllerSynologyDriver extends CsiBaseDriver {
// create target // create target
let iqn = driver.options.iscsi.baseiqn + iscsiName; let iqn = driver.options.iscsi.baseiqn + iscsiName;
data = Object.assign({}, driver.options.iscsi.targetTemplate, { data = Object.assign({}, driver.options.iscsi.targetTemplate, yaml.load(normalizedParameters.targetTemplate), {
name: iscsiName, name: iscsiName,
iqn, iqn,
}); });
@ -887,8 +888,7 @@ class ControllerSynologyDriver extends CsiBaseDriver {
async GetCapacity(call) { async GetCapacity(call) {
const driver = this; const driver = this;
const httpClient = await driver.getHttpClient(); const httpClient = await driver.getHttpClient();
const normalizedParameters = driver.getNormalizedParameters(call.request.parameters) const location = driver.getLocation();
const location = driver.getLocation(normalizedParameters);
if (!location) { if (!location) {
throw new GrpcError( throw new GrpcError(
@ -1001,7 +1001,7 @@ class ControllerSynologyDriver extends CsiBaseDriver {
snapshot = await httpClient.GetSnapshotByLunUUIDAndName(lun.uuid, name); snapshot = await httpClient.GetSnapshotByLunUUIDAndName(lun.uuid, name);
if (!snapshot) { if (!snapshot) {
const normalizedParameters = driver.getNormalizedParameters(call.request.parameters); const normalizedParameters = driver.getNormalizedParameters(call.request.parameters);
let data = Object.assign({}, driver.options.iscsi.lunSnapshotTemplate, { let data = Object.assign({}, driver.options.iscsi.lunSnapshotTemplate, yaml.load(normalizedParameters.lunSnapshotTemplate), {
src_lun_uuid: lun.uuid, src_lun_uuid: lun.uuid,
taken_by: "democratic-csi", taken_by: "democratic-csi",
description: name, //check description: name, //check