Skip to content

Commit d47fb7d

Browse files
committed
block: address CR feedback
1 parent 4b800a3 commit d47fb7d

File tree

13 files changed

+321
-125
lines changed

13 files changed

+321
-125
lines changed

charts/vastblock/templates/node.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ spec:
3939
{{- toYaml .Values.node.podAntiAffinity | nindent 10 }}
4040
nodeAffinity:
4141
{{- toYaml .Values.node.nodeAffinity | nindent 10 }}
42+
hostIPC: true
4243
containers:
4344
- name: csi-node-driver-registrar
4445
image: {{ printf "%s:%s" $csi_images.csiNodeDriverRegistrar.repository (toString $csi_images.csiNodeDriverRegistrar.tag) }}

charts/vastblock/templates/shared/_helpers.tpl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,19 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
6464
app.kubernetes.io/name: {{ include "vastcsi.name" . }}
6565
app.kubernetes.io/instance: {{ .Release.Name }}
6666
{{- end }}
67+
68+
69+
{{- define "vastcsi.dictToYaml" -}}
70+
{{- $input := index . 0 -}} {{/* The map to render */}}
71+
{{- $prefix := index . 1 | default "" -}} {{/* Optional prefix for keys */}}
72+
{{- if not (kindIs "map" $input) }}
73+
{{- $errorMsg := printf "Invalid format. Expected a dictionary but got:\n%s" (toYaml $input) }}
74+
{{- fail $errorMsg }}
75+
{{- else }}
76+
{{- range $k, $v := $input }}
77+
{{- if and $v (ne $v "") }}
78+
{{ printf "%s%s: %s" $prefix $k ($v | quote) }}
79+
{{- end }}
80+
{{- end }}
81+
{{- end }}
82+
{{- end }}

charts/vastblock/templates/storage-class.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
{{- $tenant_name := pluck "tenantName" $options $.Values.storageClassDefaults | first | quote -}}
2828
{{- $volume_group := pluck "volumeGroup" $options $.Values.storageClassDefaults | first | quote -}}
29-
{{- $volume_encryption := pluck "volumeEncryption" $options $.Values.storageClassDefaults | first | quote -}}
3029
{{- $mount_options := pluck "mountOptions" $options $.Values.storageClassDefaults | first -}}
3130
{{- $reclaim_policy := pluck "reclaimPolicy" $options $.Values.storageClassDefaults | first | quote -}}
3231
{{-
@@ -39,7 +38,7 @@
3938
{{- $storage_class_secret_namespace := pluck "secretNamespace" $options $.Values.storageClassDefaults | first | default $.Release.Namespace | quote -}}
4039
{{- $fstype := pluck "fsType" $options $.Values.storageClassDefaults | first -}}
4140
{{- $transport_type := pluck "transportType" $options $.Values.storageClassDefaults | first -}}
42-
41+
{{- $host_encryption := pluck "host_encryption" $options $.Values.storageClassDefaults | first | default dict -}}
4342

4443
kind: StorageClass
4544
apiVersion: storage.k8s.io/v1
@@ -54,11 +53,14 @@ metadata:
5453
reclaimPolicy: {{ $reclaim_policy }}
5554
parameters:
5655
subsystem: {{ $subsystem }}
57-
{{- range $key, $value := dict "vip_pool_name" $vip_pool_name "vip_pool_fqdn" $vip_pool_fqdn "volume_group" $volume_group "volume_encryption" $volume_encryption "transport_type" $transport_type "fsType" $fstype "tenant_name" $tenant_name }}
56+
{{- range $key, $value := dict "vip_pool_name" $vip_pool_name "vip_pool_fqdn" $vip_pool_fqdn "volume_group" $volume_group "transport_type" $transport_type "fsType" $fstype "tenant_name" $tenant_name }}
5857
{{- if and $value (ne $value ( quote "" )) }}
5958
{{ $key }}: {{ if (kindIs "int" $value) }}{{ $value | quote }}{{ else }}{{ $value }}{{ end }}
6059
{{- end }}
6160
{{- end }}
61+
{{- if $host_encryption }}
62+
{{- include "vastcsi.dictToYaml" (list $host_encryption "host_encryption.") | indent 2 }}
63+
{{- end }}
6264
{{- if ne $storage_class_secret ( quote "" ) }}
6365
csi.storage.k8s.io/provisioner-secret-name: {{ $storage_class_secret }}
6466
csi.storage.k8s.io/provisioner-secret-namespace: {{ $storage_class_secret_namespace }}

charts/vastblock/values.yaml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,19 @@ storageClassDefaults:
5959
# - "folder1/folder2/block-{namespace}-{id}
6060
volumeGroup: ""
6161
# Enables encryption using LUKS on the device on the client side.
62-
# If set to true, the CSI driver will expect a volume-specific secret to be provided
63-
# with the encryption passphrase.
64-
# This secret must be referenced in the StorageClass with the keys:
65-
# csi.storage.k8s.io/volume-secret-name: <secret-name>
66-
# csi.storage.k8s.io/volume-secret-namespace: <namespace>
62+
# If set to true, the CSI driver will expect a passphrase to be provided
63+
# with the vast-mgmt secret.
6764

68-
# Example Kubernetes Secret for volume encryption:
69-
# kubectl create secret generic volume-secret-namespace \
70-
# --from-literal=passphrase='my-secret-pass'
65+
# Example Kubernetes Secret for host encryption:
66+
# kubectl create secret generic vast-mgmt --from-literal=username='' --from-literal=password='' --from-literal=endpoint='' --from-literal=passphrase=''
7167

72-
# Ensure the StorageClass has the following parameters set when volume_encryption is true:
73-
# csi.storage.k8s.io/volume-secret-name: volume-secret
74-
# csi.storage.k8s.io/volume-secret-namespace: default
75-
volume_encryption: true
68+
# Ensure the StorageClass has the following parameters set when host Eencryption is true:
69+
# Optional host encryption parameters (will default if not specified):
70+
# cipher: "aes-xts-plain64" # Encryption cipher
71+
# key_size: "512" # Key size in bits (e.g., 256 or 512)
72+
# hash: "sha256" # Hashing algorithm
73+
# pbkdf_memory: "65536" # Memory cost for PBKDF in KB
74+
hostEncryption: {}
7675
# Name of VAST VIP pool to use. Must specify either vipPool or vipPoolFQDN.
7776
vipPool: ""
7877
# The FQDN of the VIP pool to use. Must specify either vipPool or vipPoolFQDN.

examples/block/sc-vol-encryption.yaml renamed to examples/block/sc-with-host-encryption.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ parameters:
99
csi.storage.k8s.io/controller-publish-secret-namespace: default
1010
csi.storage.k8s.io/provisioner-secret-name: vast-mgmt
1111
csi.storage.k8s.io/provisioner-secret-namespace: default
12+
csi.storage.k8s.io/node-stage-secret-name: vast-mgmt
13+
csi.storage.k8s.io/node-stage-secret-namespace: default
1214
subsystem: myblock
13-
vip_pool_name: vip1
15+
vip_pool_name: vippool-1
1416
transport_type: TCP
15-
volume_encryption: "true"
16-
csi.storage.k8s.io/volume-secret-name: volume-secret
17-
csi.storage.k8s.io/volume-secret-namespace: default
17+
host_encryption: '{"luks_type":"luks2","cipher":"aes-xts-plain64"}'
1818
provisioner: block.csi.vastdata.com

vast_csi/block_utils.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -30,44 +30,6 @@ def is_native_multipath_enabled():
3030
except Exception:
3131
return False
3232

33-
def is_luks_device(device_path: str) -> bool:
34-
"""
35-
Check if the given device is a LUKS-encrypted volume.
36-
37-
Args:
38-
device_path (str): The path to the block device.
39-
40-
Returns:
41-
bool: True if the device is LUKS, False otherwise.
42-
"""
43-
try:
44-
run(["cryptsetup", "isLuks", device_path])
45-
return True
46-
except ProcessExecutionError:
47-
return False
48-
49-
def is_crypto_luks(device_path):
50-
"""
51-
Determines whether the given device is a LUKS-encrypted block device.
52-
53-
Args:
54-
device_path (str): The path to the block device (e.g., /dev/nvme0n1).
55-
56-
Returns:
57-
bool: True if the device is using LUKS encryption (FSTYPE is crypto_LUKS), False otherwise.
58-
"""
59-
try:
60-
result = subprocess.run(
61-
['lsblk', '-no', 'FSTYPE', device_path],
62-
check=True,
63-
stdout=subprocess.PIPE,
64-
stderr=subprocess.DEVNULL,
65-
text=True
66-
)
67-
return result.stdout.strip() == 'crypto_LUKS'
68-
except subprocess.CalledProcessError:
69-
return False
70-
7133
def list_nvme_sessions():
7234
"""
7335
Example output:

vast_csi/builders/block.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import json
23
from datetime import timedelta
34
from dataclasses import dataclass
45
from typing import final, Optional
@@ -37,7 +38,7 @@ class BlockProvisionBase(BaseVolumeBuilder):
3738
capacity_range: Optional[int] = None
3839
pvc_name: Optional[str] = None
3940
pvc_namespace: Optional[str] = None
40-
volume_encryption: Optional[str] = None
41+
host_encryption: Optional[dict] = None
4142
volume_content_source: Optional[types.VolumeContentSource] = None # Either volume or snapshot
4243

4344
@classmethod
@@ -57,7 +58,7 @@ def from_parameters(
5758
vip_pool_fqdn = parameters.get("vip_pool_fqdn")
5859
vip_pool_name = parameters.get("vip_pool_name")
5960
volume_group = parameters.get("volume_group", "")
60-
volume_encryption = parameters.get("volume_encryption", "False")
61+
host_encryption = cls._parse_host_encryption(parameters)
6162
transport_type = parameters.get("transport_type", "TCP").upper()
6263
metadata = cls._parse_metadata_from_params(parameters)
6364
cls._validate_mount_src(vip_pool_name, vip_pool_fqdn, conf.use_local_ip_for_mount)
@@ -73,9 +74,9 @@ def from_parameters(
7374
tenant_name=tenant_name,
7475
transport_type=transport_type,
7576
volume_group=volume_group,
76-
volume_encryption=volume_encryption,
7777
vip_pool_name=vip_pool_name,
7878
vip_pool_fqdn=vip_pool_fqdn,
79+
host_encryption=host_encryption,
7980
cluster_name=cluster_name,
8081
volume_content_source=volume_content_source,
8182
**metadata,
@@ -104,6 +105,16 @@ def build_volume_name(self) -> str:
104105
# make sure the volume group is a valid absolute path
105106
return os.path.join("/", volume_group, self.name).lstrip("/")
106107

108+
@staticmethod
109+
def _parse_host_encryption(parameters):
110+
host_encryption = params.get("host_encryption", {})
111+
if isinstance(host_encryption, str):
112+
try:
113+
host_encryption = json.loads(host_encryption)
114+
except json.JSONDecodeError:
115+
host_encryption = {}
116+
return host_encryption
117+
107118
@property
108119
def volume_context(self) -> dict:
109120
context = {
@@ -116,8 +127,9 @@ def volume_context(self) -> dict:
116127
context["vip_pool_name"] = self.vip_pool_name
117128
elif self.vip_pool_fqdn:
118129
context["vip_pool_fqdn"] = self.vip_pool_fqdn_with_prefix
119-
if self.volume_encryption:
120-
context["volume_encryption"] = self.volume_encryption
130+
if self.host_encryption:
131+
for key, value in self.host_encryption.items():
132+
context[f"host_encryption.{key}"] = value
121133
return context
122134

123135

@@ -282,7 +294,6 @@ class StaticBlockVolumeBuilder(BaseVolumeBuilder):
282294
cluster_name: Optional[str] = None
283295
vip_pool_name: Optional[str] = None
284296
vip_pool_fqdn: Optional[str] = None
285-
volume_encryption: Optional[str] None
286297
transport_type: Optional[str] = "TCP"
287298

288299
@classmethod
@@ -300,7 +311,6 @@ def from_parameters(
300311
vip_pool_fqdn = parameters.get("vip_pool_fqdn")
301312
vip_pool_name = parameters.get("vip_pool_name")
302313
transport_type = parameters.get("transport_type", "TCP").upper()
303-
volume_encryption = parameters.get("volume_encryption")
304314
cls._validate_mount_src(vip_pool_name, vip_pool_fqdn, conf.use_local_ip_for_mount)
305315
cluster_name = parameters.get("cluster_name")
306316
return cls(
@@ -314,7 +324,6 @@ def from_parameters(
314324
vip_pool_fqdn=vip_pool_fqdn,
315325
transport_type=transport_type,
316326
cluster_name=cluster_name,
317-
volume_encryption=volume_encryption,
318327
)
319328

320329
@property
@@ -329,8 +338,6 @@ def volume_context(self) -> dict:
329338
context["vip_pool_name"] = self.vip_pool_name
330339
elif self.vip_pool_fqdn:
331340
context["vip_pool_fqdn"] = self.vip_pool_fqdn_with_prefix
332-
if self.volume_encryption:
333-
context["volume_encryption"] = self.volume_encryption
334341
return context
335342

336343
def build_volume(self) -> types.Volume:

vast_csi/builders/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class TestVolumeBuilder(BaseVolumeBuilder):
2727
cluster_name: Optional[str] = None
2828
vip_pool_name: Optional[str] = None
2929
vip_pool_fqdn: Optional[str] = None
30-
volume_encryption: Optional[str] = None
30+
host_encryption: Optional[dict] = None
3131
qos_policy: Optional[str] = None
3232
capacity_range: Optional[int] = None # Optional desired volume capacity
3333
pvc_name: Optional[str] = None

vast_csi/filesystem_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,12 @@ def need_resize(device: str, target_mount, fs_type: str):
338338
return device_size > fs_size + block_size
339339

340340

341-
def resize_device(device: str, target_mount: str, fs_type: str):
341+
def resize_device(device: str, target_mount: str, fs_type: str, passphrase=None):
342342
"""Perform resize of the filesystem."""
343343
if need_resize(device, target_mount, fs_type):
344+
if passphrase:
345+
luks_manager = LuksManager(logger, device_path=device)
346+
luks_manager.luks_resize_device(passphrase)
344347
if fs_type in ("ext3", "ext4"):
345348
ext_resize(device)
346349
elif fs_type == "xfs":

0 commit comments

Comments
 (0)