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 storage_capacity: Option<bool>,
59
60 pub token_requests: Option<std::vec::Vec<crate::api::storage::v1::TokenRequest>>,
70
71 pub volume_lifecycle_modes: Option<std::vec::Vec<std::string::String>>,
79}
80
81impl crate::DeepMerge for CSIDriverSpec {
82 fn merge_from(&mut self, other: Self) {
83 crate::DeepMerge::merge_from(&mut self.attach_required, other.attach_required);
84 crate::DeepMerge::merge_from(&mut self.fs_group_policy, other.fs_group_policy);
85 crate::DeepMerge::merge_from(&mut self.node_allocatable_update_period_seconds, other.node_allocatable_update_period_seconds);
86 crate::DeepMerge::merge_from(&mut self.pod_info_on_mount, other.pod_info_on_mount);
87 crate::DeepMerge::merge_from(&mut self.requires_republish, other.requires_republish);
88 crate::DeepMerge::merge_from(&mut self.se_linux_mount, other.se_linux_mount);
89 crate::DeepMerge::merge_from(&mut self.storage_capacity, other.storage_capacity);
90 crate::merge_strategies::list::atomic(&mut self.token_requests, other.token_requests);
91 crate::merge_strategies::list::set(&mut self.volume_lifecycle_modes, other.volume_lifecycle_modes);
92 }
93}
94
95impl<'de> crate::serde::Deserialize<'de> for CSIDriverSpec {
96 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
97 #[allow(non_camel_case_types)]
98 enum Field {
99 Key_attach_required,
100 Key_fs_group_policy,
101 Key_node_allocatable_update_period_seconds,
102 Key_pod_info_on_mount,
103 Key_requires_republish,
104 Key_se_linux_mount,
105 Key_storage_capacity,
106 Key_token_requests,
107 Key_volume_lifecycle_modes,
108 Other,
109 }
110
111 impl<'de> crate::serde::Deserialize<'de> for Field {
112 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
113 struct Visitor;
114
115 impl crate::serde::de::Visitor<'_> for Visitor {
116 type Value = Field;
117
118 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
119 f.write_str("field identifier")
120 }
121
122 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
123 Ok(match v {
124 "attachRequired" => Field::Key_attach_required,
125 "fsGroupPolicy" => Field::Key_fs_group_policy,
126 "nodeAllocatableUpdatePeriodSeconds" => Field::Key_node_allocatable_update_period_seconds,
127 "podInfoOnMount" => Field::Key_pod_info_on_mount,
128 "requiresRepublish" => Field::Key_requires_republish,
129 "seLinuxMount" => Field::Key_se_linux_mount,
130 "storageCapacity" => Field::Key_storage_capacity,
131 "tokenRequests" => Field::Key_token_requests,
132 "volumeLifecycleModes" => Field::Key_volume_lifecycle_modes,
133 _ => Field::Other,
134 })
135 }
136 }
137
138 deserializer.deserialize_identifier(Visitor)
139 }
140 }
141
142 struct Visitor;
143
144 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
145 type Value = CSIDriverSpec;
146
147 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
148 f.write_str("CSIDriverSpec")
149 }
150
151 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
152 let mut value_attach_required: Option<bool> = None;
153 let mut value_fs_group_policy: Option<std::string::String> = None;
154 let mut value_node_allocatable_update_period_seconds: Option<i64> = None;
155 let mut value_pod_info_on_mount: Option<bool> = None;
156 let mut value_requires_republish: Option<bool> = None;
157 let mut value_se_linux_mount: Option<bool> = None;
158 let mut value_storage_capacity: Option<bool> = None;
159 let mut value_token_requests: Option<std::vec::Vec<crate::api::storage::v1::TokenRequest>> = None;
160 let mut value_volume_lifecycle_modes: Option<std::vec::Vec<std::string::String>> = None;
161
162 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
163 match key {
164 Field::Key_attach_required => value_attach_required = crate::serde::de::MapAccess::next_value(&mut map)?,
165 Field::Key_fs_group_policy => value_fs_group_policy = crate::serde::de::MapAccess::next_value(&mut map)?,
166 Field::Key_node_allocatable_update_period_seconds => value_node_allocatable_update_period_seconds = crate::serde::de::MapAccess::next_value(&mut map)?,
167 Field::Key_pod_info_on_mount => value_pod_info_on_mount = crate::serde::de::MapAccess::next_value(&mut map)?,
168 Field::Key_requires_republish => value_requires_republish = crate::serde::de::MapAccess::next_value(&mut map)?,
169 Field::Key_se_linux_mount => value_se_linux_mount = crate::serde::de::MapAccess::next_value(&mut map)?,
170 Field::Key_storage_capacity => value_storage_capacity = crate::serde::de::MapAccess::next_value(&mut map)?,
171 Field::Key_token_requests => value_token_requests = crate::serde::de::MapAccess::next_value(&mut map)?,
172 Field::Key_volume_lifecycle_modes => value_volume_lifecycle_modes = crate::serde::de::MapAccess::next_value(&mut map)?,
173 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
174 }
175 }
176
177 Ok(CSIDriverSpec {
178 attach_required: value_attach_required,
179 fs_group_policy: value_fs_group_policy,
180 node_allocatable_update_period_seconds: value_node_allocatable_update_period_seconds,
181 pod_info_on_mount: value_pod_info_on_mount,
182 requires_republish: value_requires_republish,
183 se_linux_mount: value_se_linux_mount,
184 storage_capacity: value_storage_capacity,
185 token_requests: value_token_requests,
186 volume_lifecycle_modes: value_volume_lifecycle_modes,
187 })
188 }
189 }
190
191 deserializer.deserialize_struct(
192 "CSIDriverSpec",
193 &[
194 "attachRequired",
195 "fsGroupPolicy",
196 "nodeAllocatableUpdatePeriodSeconds",
197 "podInfoOnMount",
198 "requiresRepublish",
199 "seLinuxMount",
200 "storageCapacity",
201 "tokenRequests",
202 "volumeLifecycleModes",
203 ],
204 Visitor,
205 )
206 }
207}
208
209impl crate::serde::Serialize for CSIDriverSpec {
210 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
211 let mut state = serializer.serialize_struct(
212 "CSIDriverSpec",
213 self.attach_required.as_ref().map_or(0, |_| 1) +
214 self.fs_group_policy.as_ref().map_or(0, |_| 1) +
215 self.node_allocatable_update_period_seconds.as_ref().map_or(0, |_| 1) +
216 self.pod_info_on_mount.as_ref().map_or(0, |_| 1) +
217 self.requires_republish.as_ref().map_or(0, |_| 1) +
218 self.se_linux_mount.as_ref().map_or(0, |_| 1) +
219 self.storage_capacity.as_ref().map_or(0, |_| 1) +
220 self.token_requests.as_ref().map_or(0, |_| 1) +
221 self.volume_lifecycle_modes.as_ref().map_or(0, |_| 1),
222 )?;
223 if let Some(value) = &self.attach_required {
224 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "attachRequired", value)?;
225 }
226 if let Some(value) = &self.fs_group_policy {
227 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "fsGroupPolicy", value)?;
228 }
229 if let Some(value) = &self.node_allocatable_update_period_seconds {
230 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "nodeAllocatableUpdatePeriodSeconds", value)?;
231 }
232 if let Some(value) = &self.pod_info_on_mount {
233 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "podInfoOnMount", value)?;
234 }
235 if let Some(value) = &self.requires_republish {
236 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "requiresRepublish", value)?;
237 }
238 if let Some(value) = &self.se_linux_mount {
239 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "seLinuxMount", value)?;
240 }
241 if let Some(value) = &self.storage_capacity {
242 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "storageCapacity", value)?;
243 }
244 if let Some(value) = &self.token_requests {
245 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "tokenRequests", value)?;
246 }
247 if let Some(value) = &self.volume_lifecycle_modes {
248 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "volumeLifecycleModes", value)?;
249 }
250 crate::serde::ser::SerializeStruct::end(state)
251 }
252}
253
254#[cfg(feature = "schemars")]
255impl crate::schemars::JsonSchema for CSIDriverSpec {
256 fn schema_name() -> std::string::String {
257 "io.k8s.api.storage.v1.CSIDriverSpec".into()
258 }
259
260 fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
261 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
262 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
263 description: Some("CSIDriverSpec is the specification of a CSIDriver.".into()),
264 ..Default::default()
265 })),
266 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
267 object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
268 properties: [
269 (
270 "attachRequired".into(),
271 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
272 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
273 description: Some("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 CSIDriverRegistry feature gate is enabled and the value is specified to false, the attach operation will be skipped. Otherwise the attach operation will be called.\n\nThis field is immutable.".into()),
274 ..Default::default()
275 })),
276 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Boolean))),
277 ..Default::default()
278 }),
279 ),
280 (
281 "fsGroupPolicy".into(),
282 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
283 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
284 description: Some("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.".into()),
285 ..Default::default()
286 })),
287 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
288 ..Default::default()
289 }),
290 ),
291 (
292 "nodeAllocatableUpdatePeriodSeconds".into(),
293 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
294 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
295 description: Some("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 an alpha feature and requires the MutableCSINodeAllocatableCount feature gate to be enabled.\n\nThis field is mutable.".into()),
296 ..Default::default()
297 })),
298 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Integer))),
299 format: Some("int64".into()),
300 ..Default::default()
301 }),
302 ),
303 (
304 "podInfoOnMount".into(),
305 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
306 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
307 description: Some("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.".into()),
308 ..Default::default()
309 })),
310 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Boolean))),
311 ..Default::default()
312 }),
313 ),
314 (
315 "requiresRepublish".into(),
316 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
317 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
318 description: Some("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.".into()),
319 ..Default::default()
320 })),
321 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Boolean))),
322 ..Default::default()
323 }),
324 ),
325 (
326 "seLinuxMount".into(),
327 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
328 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
329 description: Some("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\".".into()),
330 ..Default::default()
331 })),
332 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Boolean))),
333 ..Default::default()
334 }),
335 ),
336 (
337 "storageCapacity".into(),
338 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
339 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
340 description: Some("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.".into()),
341 ..Default::default()
342 })),
343 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Boolean))),
344 ..Default::default()
345 }),
346 ),
347 (
348 "tokenRequests".into(),
349 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
350 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
351 description: Some("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.".into()),
352 ..Default::default()
353 })),
354 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
355 array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
356 items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::storage::v1::TokenRequest>()))),
357 ..Default::default()
358 })),
359 ..Default::default()
360 }),
361 ),
362 (
363 "volumeLifecycleModes".into(),
364 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
365 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
366 description: Some("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.".into()),
367 ..Default::default()
368 })),
369 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
370 array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
371 items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(
372 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
373 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
374 ..Default::default()
375 })
376 ))),
377 ..Default::default()
378 })),
379 ..Default::default()
380 }),
381 ),
382 ].into(),
383 ..Default::default()
384 })),
385 ..Default::default()
386 })
387 }
388}