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