Skip to main content

k8s_openapi/v1_36/apimachinery/pkg/apis/meta/v1/
owner_reference.rs

1// Generated from definition io.k8s.apimachinery.pkg.apis.meta.v1.OwnerReference
2
3/// OwnerReference contains enough information to let you identify an owning object. An owning object must be in the same namespace as the dependent, or be cluster-scoped, so there is no namespace field.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct OwnerReference {
6    /// API version of the referent.
7    pub api_version: std::string::String,
8
9    /// If true, AND if the owner has the "foregroundDeletion" finalizer, then the owner cannot be deleted from the key-value store until this reference is removed. See https://kubernetes.io/docs/concepts/architecture/garbage-collection/#foreground-deletion for how the garbage collector interacts with this field and enforces the foreground deletion. Defaults to false. To set this field, a user needs "delete" permission of the owner, otherwise 422 (Unprocessable Entity) will be returned.
10    pub block_owner_deletion: Option<bool>,
11
12    /// If true, this reference points to the managing controller.
13    pub controller: Option<bool>,
14
15    /// Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
16    pub kind: std::string::String,
17
18    /// Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names#names
19    pub name: std::string::String,
20
21    /// UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names#uids
22    pub uid: std::string::String,
23}
24
25impl crate::DeepMerge for OwnerReference {
26    fn merge_from(&mut self, other: Self) {
27        crate::DeepMerge::merge_from(&mut self.api_version, other.api_version);
28        crate::DeepMerge::merge_from(&mut self.block_owner_deletion, other.block_owner_deletion);
29        crate::DeepMerge::merge_from(&mut self.controller, other.controller);
30        crate::DeepMerge::merge_from(&mut self.kind, other.kind);
31        crate::DeepMerge::merge_from(&mut self.name, other.name);
32        crate::DeepMerge::merge_from(&mut self.uid, other.uid);
33    }
34}
35
36impl<'de> crate::serde::Deserialize<'de> for OwnerReference {
37    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
38        #[allow(non_camel_case_types)]
39        enum Field {
40            Key_api_version,
41            Key_block_owner_deletion,
42            Key_controller,
43            Key_kind,
44            Key_name,
45            Key_uid,
46            Other,
47        }
48
49        impl<'de> crate::serde::Deserialize<'de> for Field {
50            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
51                struct Visitor;
52
53                impl crate::serde::de::Visitor<'_> for Visitor {
54                    type Value = Field;
55
56                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
57                        f.write_str("field identifier")
58                    }
59
60                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
61                        Ok(match v {
62                            "apiVersion" => Field::Key_api_version,
63                            "blockOwnerDeletion" => Field::Key_block_owner_deletion,
64                            "controller" => Field::Key_controller,
65                            "kind" => Field::Key_kind,
66                            "name" => Field::Key_name,
67                            "uid" => Field::Key_uid,
68                            _ => Field::Other,
69                        })
70                    }
71                }
72
73                deserializer.deserialize_identifier(Visitor)
74            }
75        }
76
77        struct Visitor;
78
79        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
80            type Value = OwnerReference;
81
82            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
83                f.write_str("OwnerReference")
84            }
85
86            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
87                let mut value_api_version: Option<std::string::String> = None;
88                let mut value_block_owner_deletion: Option<bool> = None;
89                let mut value_controller: Option<bool> = None;
90                let mut value_kind: Option<std::string::String> = None;
91                let mut value_name: Option<std::string::String> = None;
92                let mut value_uid: Option<std::string::String> = None;
93
94                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
95                    match key {
96                        Field::Key_api_version => value_api_version = crate::serde::de::MapAccess::next_value(&mut map)?,
97                        Field::Key_block_owner_deletion => value_block_owner_deletion = crate::serde::de::MapAccess::next_value(&mut map)?,
98                        Field::Key_controller => value_controller = crate::serde::de::MapAccess::next_value(&mut map)?,
99                        Field::Key_kind => value_kind = crate::serde::de::MapAccess::next_value(&mut map)?,
100                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
101                        Field::Key_uid => value_uid = crate::serde::de::MapAccess::next_value(&mut map)?,
102                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
103                    }
104                }
105
106                Ok(OwnerReference {
107                    api_version: value_api_version.unwrap_or_default(),
108                    block_owner_deletion: value_block_owner_deletion,
109                    controller: value_controller,
110                    kind: value_kind.unwrap_or_default(),
111                    name: value_name.unwrap_or_default(),
112                    uid: value_uid.unwrap_or_default(),
113                })
114            }
115        }
116
117        deserializer.deserialize_struct(
118            "OwnerReference",
119            &[
120                "apiVersion",
121                "blockOwnerDeletion",
122                "controller",
123                "kind",
124                "name",
125                "uid",
126            ],
127            Visitor,
128        )
129    }
130}
131
132impl crate::serde::Serialize for OwnerReference {
133    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
134        let mut state = serializer.serialize_struct(
135            "OwnerReference",
136            4 +
137            self.block_owner_deletion.as_ref().map_or(0, |_| 1) +
138            self.controller.as_ref().map_or(0, |_| 1),
139        )?;
140        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersion", &self.api_version)?;
141        if let Some(value) = &self.block_owner_deletion {
142            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "blockOwnerDeletion", value)?;
143        }
144        if let Some(value) = &self.controller {
145            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "controller", value)?;
146        }
147        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", &self.kind)?;
148        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
149        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "uid", &self.uid)?;
150        crate::serde::ser::SerializeStruct::end(state)
151    }
152}
153
154#[cfg(feature = "schemars")]
155impl crate::schemars::JsonSchema for OwnerReference {
156    fn schema_name() -> std::borrow::Cow<'static, str> {
157        "io.k8s.apimachinery.pkg.apis.meta.v1.OwnerReference".into()
158    }
159
160    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
161        crate::schemars::json_schema!({
162            "description": "OwnerReference contains enough information to let you identify an owning object. An owning object must be in the same namespace as the dependent, or be cluster-scoped, so there is no namespace field.",
163            "type": "object",
164            "properties": {
165                "apiVersion": {
166                    "description": "API version of the referent.",
167                    "type": "string",
168                },
169                "blockOwnerDeletion": {
170                    "description": "If true, AND if the owner has the \"foregroundDeletion\" finalizer, then the owner cannot be deleted from the key-value store until this reference is removed. See https://kubernetes.io/docs/concepts/architecture/garbage-collection/#foreground-deletion for how the garbage collector interacts with this field and enforces the foreground deletion. Defaults to false. To set this field, a user needs \"delete\" permission of the owner, otherwise 422 (Unprocessable Entity) will be returned.",
171                    "type": "boolean",
172                },
173                "controller": {
174                    "description": "If true, this reference points to the managing controller.",
175                    "type": "boolean",
176                },
177                "kind": {
178                    "description": "Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
179                    "type": "string",
180                },
181                "name": {
182                    "description": "Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names#names",
183                    "type": "string",
184                },
185                "uid": {
186                    "description": "UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names#uids",
187                    "type": "string",
188                },
189            },
190            "required": [
191                "apiVersion",
192                "kind",
193                "name",
194                "uid",
195            ],
196        })
197    }
198}
199
200#[cfg(feature = "schemars08")]
201impl crate::schemars08::JsonSchema for OwnerReference {
202    fn schema_name() -> std::string::String {
203        "io.k8s.apimachinery.pkg.apis.meta.v1.OwnerReference".into()
204    }
205
206    fn json_schema(__gen: &mut crate::schemars08::gen::SchemaGenerator) -> crate::schemars08::schema::Schema {
207        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
208            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
209                description: Some("OwnerReference contains enough information to let you identify an owning object. An owning object must be in the same namespace as the dependent, or be cluster-scoped, so there is no namespace field.".into()),
210                ..Default::default()
211            })),
212            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Object))),
213            object: Some(std::boxed::Box::new(crate::schemars08::schema::ObjectValidation {
214                properties: [
215                    (
216                        "apiVersion".into(),
217                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
218                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
219                                description: Some("API version of the referent.".into()),
220                                ..Default::default()
221                            })),
222                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
223                            ..Default::default()
224                        }),
225                    ),
226                    (
227                        "blockOwnerDeletion".into(),
228                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
229                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
230                                description: Some("If true, AND if the owner has the \"foregroundDeletion\" finalizer, then the owner cannot be deleted from the key-value store until this reference is removed. See https://kubernetes.io/docs/concepts/architecture/garbage-collection/#foreground-deletion for how the garbage collector interacts with this field and enforces the foreground deletion. Defaults to false. To set this field, a user needs \"delete\" permission of the owner, otherwise 422 (Unprocessable Entity) will be returned.".into()),
231                                ..Default::default()
232                            })),
233                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Boolean))),
234                            ..Default::default()
235                        }),
236                    ),
237                    (
238                        "controller".into(),
239                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
240                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
241                                description: Some("If true, this reference points to the managing controller.".into()),
242                                ..Default::default()
243                            })),
244                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Boolean))),
245                            ..Default::default()
246                        }),
247                    ),
248                    (
249                        "kind".into(),
250                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
251                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
252                                description: Some("Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds".into()),
253                                ..Default::default()
254                            })),
255                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
256                            ..Default::default()
257                        }),
258                    ),
259                    (
260                        "name".into(),
261                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
262                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
263                                description: Some("Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names#names".into()),
264                                ..Default::default()
265                            })),
266                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
267                            ..Default::default()
268                        }),
269                    ),
270                    (
271                        "uid".into(),
272                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
273                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
274                                description: Some("UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names#uids".into()),
275                                ..Default::default()
276                            })),
277                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
278                            ..Default::default()
279                        }),
280                    ),
281                ].into(),
282                required: [
283                    "apiVersion".into(),
284                    "kind".into(),
285                    "name".into(),
286                    "uid".into(),
287                ].into(),
288                ..Default::default()
289            })),
290            ..Default::default()
291        })
292    }
293}