1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct CSIDriverSpec {
6 pub attach_required: Option<bool>,
10
11 pub fs_group_policy: Option<std::string::String>,
17
18 pub node_allocatable_update_period_seconds: Option<i64>,
24
25 pub pod_info_on_mount: Option<bool>,
36
37 pub requires_republish: Option<bool>,
41
42 pub se_linux_mount: Option<bool>,
50
51 pub service_account_token_in_secrets: Option<bool>,
61
62 pub storage_capacity: Option<bool>,
70
71 pub token_requests: Option<std::vec::Vec<crate::api::storage::v1::TokenRequest>>,
81
82 pub volume_lifecycle_modes: Option<std::vec::Vec<std::string::String>>,
90}
91
92impl crate::DeepMerge for CSIDriverSpec {
93 fn merge_from(&mut self, other: Self) {
94 crate::DeepMerge::merge_from(&mut self.attach_required, other.attach_required);
95 crate::DeepMerge::merge_from(&mut self.fs_group_policy, other.fs_group_policy);
96 crate::DeepMerge::merge_from(&mut self.node_allocatable_update_period_seconds, other.node_allocatable_update_period_seconds);
97 crate::DeepMerge::merge_from(&mut self.pod_info_on_mount, other.pod_info_on_mount);
98 crate::DeepMerge::merge_from(&mut self.requires_republish, other.requires_republish);
99 crate::DeepMerge::merge_from(&mut self.se_linux_mount, other.se_linux_mount);
100 crate::DeepMerge::merge_from(&mut self.service_account_token_in_secrets, other.service_account_token_in_secrets);
101 crate::DeepMerge::merge_from(&mut self.storage_capacity, other.storage_capacity);
102 crate::merge_strategies::list::atomic(&mut self.token_requests, other.token_requests);
103 crate::merge_strategies::list::set(&mut self.volume_lifecycle_modes, other.volume_lifecycle_modes);
104 }
105}
106
107impl<'de> crate::serde::Deserialize<'de> for CSIDriverSpec {
108 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
109 #[allow(non_camel_case_types)]
110 enum Field {
111 Key_attach_required,
112 Key_fs_group_policy,
113 Key_node_allocatable_update_period_seconds,
114 Key_pod_info_on_mount,
115 Key_requires_republish,
116 Key_se_linux_mount,
117 Key_service_account_token_in_secrets,
118 Key_storage_capacity,
119 Key_token_requests,
120 Key_volume_lifecycle_modes,
121 Other,
122 }
123
124 impl<'de> crate::serde::Deserialize<'de> for Field {
125 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
126 struct Visitor;
127
128 impl crate::serde::de::Visitor<'_> for Visitor {
129 type Value = Field;
130
131 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
132 f.write_str("field identifier")
133 }
134
135 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
136 Ok(match v {
137 "attachRequired" => Field::Key_attach_required,
138 "fsGroupPolicy" => Field::Key_fs_group_policy,
139 "nodeAllocatableUpdatePeriodSeconds" => Field::Key_node_allocatable_update_period_seconds,
140 "podInfoOnMount" => Field::Key_pod_info_on_mount,
141 "requiresRepublish" => Field::Key_requires_republish,
142 "seLinuxMount" => Field::Key_se_linux_mount,
143 "serviceAccountTokenInSecrets" => Field::Key_service_account_token_in_secrets,
144 "storageCapacity" => Field::Key_storage_capacity,
145 "tokenRequests" => Field::Key_token_requests,
146 "volumeLifecycleModes" => Field::Key_volume_lifecycle_modes,
147 _ => Field::Other,
148 })
149 }
150 }
151
152 deserializer.deserialize_identifier(Visitor)
153 }
154 }
155
156 struct Visitor;
157
158 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
159 type Value = CSIDriverSpec;
160
161 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
162 f.write_str("CSIDriverSpec")
163 }
164
165 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
166 let mut value_attach_required: Option<bool> = None;
167 let mut value_fs_group_policy: Option<std::string::String> = None;
168 let mut value_node_allocatable_update_period_seconds: Option<i64> = None;
169 let mut value_pod_info_on_mount: Option<bool> = None;
170 let mut value_requires_republish: Option<bool> = None;
171 let mut value_se_linux_mount: Option<bool> = None;
172 let mut value_service_account_token_in_secrets: Option<bool> = None;
173 let mut value_storage_capacity: Option<bool> = None;
174 let mut value_token_requests: Option<std::vec::Vec<crate::api::storage::v1::TokenRequest>> = None;
175 let mut value_volume_lifecycle_modes: Option<std::vec::Vec<std::string::String>> = None;
176
177 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
178 match key {
179 Field::Key_attach_required => value_attach_required = crate::serde::de::MapAccess::next_value(&mut map)?,
180 Field::Key_fs_group_policy => value_fs_group_policy = crate::serde::de::MapAccess::next_value(&mut map)?,
181 Field::Key_node_allocatable_update_period_seconds => value_node_allocatable_update_period_seconds = crate::serde::de::MapAccess::next_value(&mut map)?,
182 Field::Key_pod_info_on_mount => value_pod_info_on_mount = crate::serde::de::MapAccess::next_value(&mut map)?,
183 Field::Key_requires_republish => value_requires_republish = crate::serde::de::MapAccess::next_value(&mut map)?,
184 Field::Key_se_linux_mount => value_se_linux_mount = crate::serde::de::MapAccess::next_value(&mut map)?,
185 Field::Key_service_account_token_in_secrets => value_service_account_token_in_secrets = crate::serde::de::MapAccess::next_value(&mut map)?,
186 Field::Key_storage_capacity => value_storage_capacity = crate::serde::de::MapAccess::next_value(&mut map)?,
187 Field::Key_token_requests => value_token_requests = crate::serde::de::MapAccess::next_value(&mut map)?,
188 Field::Key_volume_lifecycle_modes => value_volume_lifecycle_modes = crate::serde::de::MapAccess::next_value(&mut map)?,
189 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
190 }
191 }
192
193 Ok(CSIDriverSpec {
194 attach_required: value_attach_required,
195 fs_group_policy: value_fs_group_policy,
196 node_allocatable_update_period_seconds: value_node_allocatable_update_period_seconds,
197 pod_info_on_mount: value_pod_info_on_mount,
198 requires_republish: value_requires_republish,
199 se_linux_mount: value_se_linux_mount,
200 service_account_token_in_secrets: value_service_account_token_in_secrets,
201 storage_capacity: value_storage_capacity,
202 token_requests: value_token_requests,
203 volume_lifecycle_modes: value_volume_lifecycle_modes,
204 })
205 }
206 }
207
208 deserializer.deserialize_struct(
209 "CSIDriverSpec",
210 &[
211 "attachRequired",
212 "fsGroupPolicy",
213 "nodeAllocatableUpdatePeriodSeconds",
214 "podInfoOnMount",
215 "requiresRepublish",
216 "seLinuxMount",
217 "serviceAccountTokenInSecrets",
218 "storageCapacity",
219 "tokenRequests",
220 "volumeLifecycleModes",
221 ],
222 Visitor,
223 )
224 }
225}
226
227impl crate::serde::Serialize for CSIDriverSpec {
228 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
229 let mut state = serializer.serialize_struct(
230 "CSIDriverSpec",
231 self.attach_required.as_ref().map_or(0, |_| 1) +
232 self.fs_group_policy.as_ref().map_or(0, |_| 1) +
233 self.node_allocatable_update_period_seconds.as_ref().map_or(0, |_| 1) +
234 self.pod_info_on_mount.as_ref().map_or(0, |_| 1) +
235 self.requires_republish.as_ref().map_or(0, |_| 1) +
236 self.se_linux_mount.as_ref().map_or(0, |_| 1) +
237 self.service_account_token_in_secrets.as_ref().map_or(0, |_| 1) +
238 self.storage_capacity.as_ref().map_or(0, |_| 1) +
239 self.token_requests.as_ref().map_or(0, |_| 1) +
240 self.volume_lifecycle_modes.as_ref().map_or(0, |_| 1),
241 )?;
242 if let Some(value) = &self.attach_required {
243 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "attachRequired", value)?;
244 }
245 if let Some(value) = &self.fs_group_policy {
246 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "fsGroupPolicy", value)?;
247 }
248 if let Some(value) = &self.node_allocatable_update_period_seconds {
249 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "nodeAllocatableUpdatePeriodSeconds", value)?;
250 }
251 if let Some(value) = &self.pod_info_on_mount {
252 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "podInfoOnMount", value)?;
253 }
254 if let Some(value) = &self.requires_republish {
255 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "requiresRepublish", value)?;
256 }
257 if let Some(value) = &self.se_linux_mount {
258 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "seLinuxMount", value)?;
259 }
260 if let Some(value) = &self.service_account_token_in_secrets {
261 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "serviceAccountTokenInSecrets", value)?;
262 }
263 if let Some(value) = &self.storage_capacity {
264 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "storageCapacity", value)?;
265 }
266 if let Some(value) = &self.token_requests {
267 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "tokenRequests", value)?;
268 }
269 if let Some(value) = &self.volume_lifecycle_modes {
270 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "volumeLifecycleModes", value)?;
271 }
272 crate::serde::ser::SerializeStruct::end(state)
273 }
274}
275
276#[cfg(feature = "schemars")]
277impl crate::schemars::JsonSchema for CSIDriverSpec {
278 fn schema_name() -> std::borrow::Cow<'static, str> {
279 "io.k8s.api.storage.v1.CSIDriverSpec".into()
280 }
281
282 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
283 crate::schemars::json_schema!({
284 "description": "CSIDriverSpec is the specification of a CSIDriver.",
285 "type": "object",
286 "properties": {
287 "attachRequired": {
288 "description": "attachRequired indicates this CSI volume driver requires an attach operation (because it implements the CSI ControllerPublishVolume() method), and that the Kubernetes attach detach controller should call the attach volume interface which checks the volumeattachment status and waits until the volume is attached before proceeding to mounting. The CSI external-attacher coordinates with CSI volume driver and updates the volumeattachment status when the attach operation is complete. If the value is specified to false, the attach operation will be skipped. Otherwise the attach operation will be called.\n\nThis field is immutable.",
289 "type": "boolean",
290 },
291 "fsGroupPolicy": {
292 "description": "fsGroupPolicy defines if the underlying volume supports changing ownership and permission of the volume before being mounted. Refer to the specific FSGroupPolicy values for additional details.\n\nThis field was immutable in Kubernetes < 1.29 and now is mutable.\n\nDefaults to ReadWriteOnceWithFSType, which will examine each volume to determine if Kubernetes should modify ownership and permissions of the volume. With the default policy the defined fsGroup will only be applied if a fstype is defined and the volume's access mode contains ReadWriteOnce.",
293 "type": "string",
294 },
295 "nodeAllocatableUpdatePeriodSeconds": {
296 "description": "nodeAllocatableUpdatePeriodSeconds specifies the interval between periodic updates of the CSINode allocatable capacity for this driver. When set, both periodic updates and updates triggered by capacity-related failures are enabled. If not set, no updates occur (neither periodic nor upon detecting capacity-related failures), and the allocatable.count remains static. The minimum allowed value for this field is 10 seconds.\n\nThis is a beta feature and requires the MutableCSINodeAllocatableCount feature gate to be enabled.\n\nThis field is mutable.",
297 "type": "integer",
298 "format": "int64",
299 },
300 "podInfoOnMount": {
301 "description": "podInfoOnMount indicates this CSI volume driver requires additional pod information (like podName, podUID, etc.) during mount operations, if set to true. If set to false, pod information will not be passed on mount. Default is false.\n\nThe CSI driver specifies podInfoOnMount as part of driver deployment. If true, Kubelet will pass pod information as VolumeContext in the CSI NodePublishVolume() calls. The CSI driver is responsible for parsing and validating the information passed in as VolumeContext.\n\nThe following VolumeContext will be passed if podInfoOnMount is set to true. This list might grow, but the prefix will be used. \"csi.storage.k8s.io/pod.name\": pod.Name \"csi.storage.k8s.io/pod.namespace\": pod.Namespace \"csi.storage.k8s.io/pod.uid\": string(pod.UID) \"csi.storage.k8s.io/ephemeral\": \"true\" if the volume is an ephemeral inline volume\n defined by a CSIVolumeSource, otherwise \"false\"\n\n\"csi.storage.k8s.io/ephemeral\" is a new feature in Kubernetes 1.16. It is only required for drivers which support both the \"Persistent\" and \"Ephemeral\" VolumeLifecycleMode. Other drivers can leave pod info disabled and/or ignore this field. As Kubernetes 1.15 doesn't support this field, drivers can only support one mode when deployed on such a cluster and the deployment determines which mode that is, for example via a command line parameter of the driver.\n\nThis field was immutable in Kubernetes < 1.29 and now is mutable.",
302 "type": "boolean",
303 },
304 "requiresRepublish": {
305 "description": "requiresRepublish indicates the CSI driver wants `NodePublishVolume` being periodically called to reflect any possible change in the mounted volume. This field defaults to false.\n\nNote: After a successful initial NodePublishVolume call, subsequent calls to NodePublishVolume should only update the contents of the volume. New mount points will not be seen by a running container.",
306 "type": "boolean",
307 },
308 "seLinuxMount": {
309 "description": "seLinuxMount specifies if the CSI driver supports \"-o context\" mount option.\n\nWhen \"true\", the CSI driver must ensure that all volumes provided by this CSI driver can be mounted separately with different `-o context` options. This is typical for storage backends that provide volumes as filesystems on block devices or as independent shared volumes. Kubernetes will call NodeStage / NodePublish with \"-o context=xyz\" mount option when mounting a ReadWriteOncePod volume used in Pod that has explicitly set SELinux context. In the future, it may be expanded to other volume AccessModes. In any case, Kubernetes will ensure that the volume is mounted only with a single SELinux context.\n\nWhen \"false\", Kubernetes won't pass any special SELinux mount options to the driver. This is typical for volumes that represent subdirectories of a bigger shared filesystem.\n\nDefault is \"false\".",
310 "type": "boolean",
311 },
312 "serviceAccountTokenInSecrets": {
313 "description": "serviceAccountTokenInSecrets is an opt-in for CSI drivers to indicate that service account tokens should be passed via the Secrets field in NodePublishVolumeRequest instead of the VolumeContext field. The CSI specification provides a dedicated Secrets field for sensitive information like tokens, which is the appropriate mechanism for handling credentials. This addresses security concerns where sensitive tokens were being logged as part of volume context.\n\nWhen \"true\", kubelet will pass the tokens only in the Secrets field with the key \"csi.storage.k8s.io/serviceAccount.tokens\". The CSI driver must be updated to read tokens from the Secrets field instead of VolumeContext.\n\nWhen \"false\" or not set, kubelet will pass the tokens in VolumeContext with the key \"csi.storage.k8s.io/serviceAccount.tokens\" (existing behavior). This maintains backward compatibility with existing CSI drivers.\n\nThis field can only be set when TokenRequests is configured. The API server will reject CSIDriver specs that set this field without TokenRequests.\n\nDefault behavior if unset is to pass tokens in the VolumeContext field.",
314 "type": "boolean",
315 },
316 "storageCapacity": {
317 "description": "storageCapacity indicates that the CSI volume driver wants pod scheduling to consider the storage capacity that the driver deployment will report by creating CSIStorageCapacity objects with capacity information, if set to true.\n\nThe check can be enabled immediately when deploying a driver. In that case, provisioning new volumes with late binding will pause until the driver deployment has published some suitable CSIStorageCapacity object.\n\nAlternatively, the driver can be deployed with the field unset or false and it can be flipped later when storage capacity information has been published.\n\nThis field was immutable in Kubernetes <= 1.22 and now is mutable.",
318 "type": "boolean",
319 },
320 "tokenRequests": {
321 "description": "tokenRequests indicates the CSI driver needs pods' service account tokens it is mounting volume for to do necessary authentication. Kubelet will pass the tokens in VolumeContext in the CSI NodePublishVolume calls. The CSI driver should parse and validate the following VolumeContext: \"csi.storage.k8s.io/serviceAccount.tokens\": {\n \"<audience>\": {\n \"token\": <token>,\n \"expirationTimestamp\": <expiration timestamp in RFC3339>,\n },\n ...\n}\n\nNote: Audience in each TokenRequest should be different and at most one token is empty string. To receive a new token after expiry, RequiresRepublish can be used to trigger NodePublishVolume periodically.",
322 "type": "array",
323 "items": (__gen.subschema_for::<crate::api::storage::v1::TokenRequest>()),
324 },
325 "volumeLifecycleModes": {
326 "description": "volumeLifecycleModes defines what kind of volumes this CSI volume driver supports. The default if the list is empty is \"Persistent\", which is the usage defined by the CSI specification and implemented in Kubernetes via the usual PV/PVC mechanism.\n\nThe other mode is \"Ephemeral\". In this mode, volumes are defined inline inside the pod spec with CSIVolumeSource and their lifecycle is tied to the lifecycle of that pod. A driver has to be aware of this because it is only going to get a NodePublishVolume call for such a volume.\n\nFor more information about implementing this mode, see https://kubernetes-csi.github.io/docs/ephemeral-local-volumes.html A driver can support one or more of these modes and more modes may be added in the future.\n\nThis field is beta. This field is immutable.",
327 "type": "array",
328 "items": {
329 "type": "string",
330 },
331 },
332 },
333 })
334 }
335}