2424from datetime import timedelta
2525
2626
27+ class StoragePool (BaseModel ):
28+ name : Annotated [
29+ str , StringConstraints (strip_whitespace = True , min_length = 3 , max_length = 63 )
30+ ] = Field (description = "Name of the pool, Should be unique" )
31+ path : DirectoryPath = Field (description = "Path of the pool, Should be unique" )
32+ reserved_capacity : (
33+ ByteSize
34+ | Annotated [
35+ str ,
36+ StringConstraints (strip_whitespace = True , pattern = r"^\d+%$" ),
37+ ]
38+ ) = Field (
39+ default = ByteSize (0 ),
40+ description = "Reserves capacity of storage pool" ,
41+ )
42+ capacity_override : ByteSize | None = Field (
43+ default = None ,
44+ description = "Overrides total capacity of storage pool" ,
45+ )
46+ default_fs : FileSystemName = Field (
47+ default = FileSystemName .EXT4 ,
48+ description = "Default filesystem used where creating volumes and fsType is not specified in storage class parameters" ,
49+ )
50+ is_default : bool = Field (
51+ description = "Makes this storage pool to be default, used when no storage pool name has been specified in storage class parameters"
52+ )
53+
54+
2755class CSIDriverCmd (BaseModel ):
2856 endpoint : (
2957 AnyUrl
@@ -33,6 +61,10 @@ class CSIDriverCmd(BaseModel):
3361 ) = Field (
3462 description = "Listen address for gRPC server" ,
3563 )
64+ storage_pools : list [StoragePool ] | None = Field (
65+ description = "List of storage pools, required when running node plugin" ,
66+ default = None ,
67+ )
3668 internal_ip : IPvAnyAddress | None = Field (
3769 description = "Listen ip for gRPC server (used for internal communication only)" ,
3870 default = None ,
@@ -77,13 +109,30 @@ class CSIDriverCmd(BaseModel):
77109 def validate_node_plugin (
78110 self ,
79111 ):
80- if self .plugin_type = = "node" :
112+ if self .plugin_type ! = "node" :
81113 if not self .internal_ip :
82114 raise ValueError (
83115 "Internal Communication IP/PORT is required on node plugin"
84116 )
85117 if not self .metadata_dir :
86118 raise ValueError ("Metadata Dir is required when running node plugin" )
119+ if not self .storage_pools :
120+ raise ValueError (
121+ "Storage Pool list is required when running node plugin"
122+ )
123+
124+ names = []
125+ paths = []
126+ has_default = False
127+ for pool in self .storage_pools :
128+ if pool .name in names :
129+ raise ValueError ("Duplicate name in storage pool is not supported" )
130+ names .append (pool .name )
131+ if pool .path in paths :
132+ raise ValueError ("Duplicate path in storage pool is not supported" )
133+ paths .append (pool .path )
134+ if pool .is_default and has_default :
135+ raise ValueError ("Only one default pool is allowed" )
87136 return self
88137
89138
@@ -110,24 +159,6 @@ def settings_customise_sources(
110159 ) -> tuple [PydanticBaseSettingsSource , ...]:
111160 return CliSettingsSource (settings_cls , cli_parse_args = True ), env_settings
112161
113- reserved_capacity : (
114- ByteSize
115- | Annotated [
116- str ,
117- StringConstraints (strip_whitespace = True , pattern = r"^\d+%$" ),
118- ]
119- ) = Field (
120- default = ByteSize (0 ),
121- description = "Reserves capacity of data dir" ,
122- )
123- capacity_override : ByteSize | None = Field (
124- default = None ,
125- description = "Overrides total capacity of data dir" ,
126- )
127- default_fs : FileSystemName = Field (
128- default = FileSystemName .EXT4 ,
129- description = "Default filesystem used where creating volumes and fsType is not specified in storage class parameters" ,
130- )
131162 namespace : str = Field (
132163 description = "K8s Namespace of the driver" ,
133164 )
0 commit comments