k8s_openapi/v1_30/api/core/v1/
service_account.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ServiceAccount {
6 pub automount_service_account_token: Option<bool>,
8
9 pub image_pull_secrets: Option<Vec<crate::api::core::v1::LocalObjectReference>>,
11
12 pub metadata: crate::apimachinery::pkg::apis::meta::v1::ObjectMeta,
14
15 pub secrets: Option<Vec<crate::api::core::v1::ObjectReference>>,
17}
18
19impl crate::Resource for ServiceAccount {
20 const API_VERSION: &'static str = "v1";
21 const GROUP: &'static str = "";
22 const KIND: &'static str = "ServiceAccount";
23 const VERSION: &'static str = "v1";
24 const URL_PATH_SEGMENT: &'static str = "serviceaccounts";
25 type Scope = crate::NamespaceResourceScope;
26}
27
28impl crate::ListableResource for ServiceAccount {
29 const LIST_KIND: &'static str = "ServiceAccountList";
30}
31
32impl crate::Metadata for ServiceAccount {
33 type Ty = crate::apimachinery::pkg::apis::meta::v1::ObjectMeta;
34
35 fn metadata(&self) -> &<Self as crate::Metadata>::Ty {
36 &self.metadata
37 }
38
39 fn metadata_mut(&mut self) -> &mut<Self as crate::Metadata>::Ty {
40 &mut self.metadata
41 }
42}
43
44impl crate::DeepMerge for ServiceAccount {
45 fn merge_from(&mut self, other: Self) {
46 crate::DeepMerge::merge_from(&mut self.automount_service_account_token, other.automount_service_account_token);
47 crate::merge_strategies::list::atomic(&mut self.image_pull_secrets, other.image_pull_secrets);
48 crate::DeepMerge::merge_from(&mut self.metadata, other.metadata);
49 crate::merge_strategies::list::map(
50 &mut self.secrets,
51 other.secrets,
52 &[|lhs, rhs| lhs.name == rhs.name],
53 |current_item, other_item| {
54 crate::DeepMerge::merge_from(current_item, other_item);
55 },
56 );
57 }
58}
59
60impl<'de> crate::serde::Deserialize<'de> for ServiceAccount {
61 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
62 #[allow(non_camel_case_types)]
63 enum Field {
64 Key_api_version,
65 Key_kind,
66 Key_automount_service_account_token,
67 Key_image_pull_secrets,
68 Key_metadata,
69 Key_secrets,
70 Other,
71 }
72
73 impl<'de> crate::serde::Deserialize<'de> for Field {
74 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
75 struct Visitor;
76
77 impl crate::serde::de::Visitor<'_> for Visitor {
78 type Value = Field;
79
80 fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
81 f.write_str("field identifier")
82 }
83
84 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
85 Ok(match v {
86 "apiVersion" => Field::Key_api_version,
87 "kind" => Field::Key_kind,
88 "automountServiceAccountToken" => Field::Key_automount_service_account_token,
89 "imagePullSecrets" => Field::Key_image_pull_secrets,
90 "metadata" => Field::Key_metadata,
91 "secrets" => Field::Key_secrets,
92 _ => Field::Other,
93 })
94 }
95 }
96
97 deserializer.deserialize_identifier(Visitor)
98 }
99 }
100
101 struct Visitor;
102
103 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
104 type Value = ServiceAccount;
105
106 fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
107 f.write_str(<Self::Value as crate::Resource>::KIND)
108 }
109
110 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
111 let mut value_automount_service_account_token: Option<bool> = None;
112 let mut value_image_pull_secrets: Option<Vec<crate::api::core::v1::LocalObjectReference>> = None;
113 let mut value_metadata: Option<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta> = None;
114 let mut value_secrets: Option<Vec<crate::api::core::v1::ObjectReference>> = None;
115
116 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
117 match key {
118 Field::Key_api_version => {
119 let value_api_version: String = crate::serde::de::MapAccess::next_value(&mut map)?;
120 if value_api_version != <Self::Value as crate::Resource>::API_VERSION {
121 return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_api_version), &<Self::Value as crate::Resource>::API_VERSION));
122 }
123 },
124 Field::Key_kind => {
125 let value_kind: String = crate::serde::de::MapAccess::next_value(&mut map)?;
126 if value_kind != <Self::Value as crate::Resource>::KIND {
127 return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_kind), &<Self::Value as crate::Resource>::KIND));
128 }
129 },
130 Field::Key_automount_service_account_token => value_automount_service_account_token = crate::serde::de::MapAccess::next_value(&mut map)?,
131 Field::Key_image_pull_secrets => value_image_pull_secrets = crate::serde::de::MapAccess::next_value(&mut map)?,
132 Field::Key_metadata => value_metadata = crate::serde::de::MapAccess::next_value(&mut map)?,
133 Field::Key_secrets => value_secrets = crate::serde::de::MapAccess::next_value(&mut map)?,
134 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
135 }
136 }
137
138 Ok(ServiceAccount {
139 automount_service_account_token: value_automount_service_account_token,
140 image_pull_secrets: value_image_pull_secrets,
141 metadata: value_metadata.unwrap_or_default(),
142 secrets: value_secrets,
143 })
144 }
145 }
146
147 deserializer.deserialize_struct(
148 <Self as crate::Resource>::KIND,
149 &[
150 "apiVersion",
151 "kind",
152 "automountServiceAccountToken",
153 "imagePullSecrets",
154 "metadata",
155 "secrets",
156 ],
157 Visitor,
158 )
159 }
160}
161
162impl crate::serde::Serialize for ServiceAccount {
163 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
164 let mut state = serializer.serialize_struct(
165 <Self as crate::Resource>::KIND,
166 3 +
167 self.automount_service_account_token.as_ref().map_or(0, |_| 1) +
168 self.image_pull_secrets.as_ref().map_or(0, |_| 1) +
169 self.secrets.as_ref().map_or(0, |_| 1),
170 )?;
171 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersion", <Self as crate::Resource>::API_VERSION)?;
172 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", <Self as crate::Resource>::KIND)?;
173 if let Some(value) = &self.automount_service_account_token {
174 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "automountServiceAccountToken", value)?;
175 }
176 if let Some(value) = &self.image_pull_secrets {
177 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "imagePullSecrets", value)?;
178 }
179 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "metadata", &self.metadata)?;
180 if let Some(value) = &self.secrets {
181 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "secrets", value)?;
182 }
183 crate::serde::ser::SerializeStruct::end(state)
184 }
185}
186
187#[cfg(feature = "schemars")]
188impl crate::schemars::JsonSchema for ServiceAccount {
189 fn schema_name() -> String {
190 "io.k8s.api.core.v1.ServiceAccount".to_owned()
191 }
192
193 fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
194 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
195 metadata: Some(Box::new(crate::schemars::schema::Metadata {
196 description: Some("ServiceAccount binds together: * a name, understood by users, and perhaps by peripheral systems, for an identity * a principal that can be authenticated and authorized * a set of secrets".to_owned()),
197 ..Default::default()
198 })),
199 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
200 object: Some(Box::new(crate::schemars::schema::ObjectValidation {
201 properties: [
202 (
203 "apiVersion".to_owned(),
204 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
205 metadata: Some(Box::new(crate::schemars::schema::Metadata {
206 description: Some("APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources".to_owned()),
207 ..Default::default()
208 })),
209 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
210 ..Default::default()
211 }),
212 ),
213 (
214 "automountServiceAccountToken".to_owned(),
215 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
216 metadata: Some(Box::new(crate::schemars::schema::Metadata {
217 description: Some("AutomountServiceAccountToken indicates whether pods running as this service account should have an API token automatically mounted. Can be overridden at the pod level.".to_owned()),
218 ..Default::default()
219 })),
220 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Boolean))),
221 ..Default::default()
222 }),
223 ),
224 (
225 "imagePullSecrets".to_owned(),
226 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
227 metadata: Some(Box::new(crate::schemars::schema::Metadata {
228 description: Some("ImagePullSecrets is a list of references to secrets in the same namespace to use for pulling any images in pods that reference this ServiceAccount. ImagePullSecrets are distinct from Secrets because Secrets can be mounted in the pod, but ImagePullSecrets are only accessed by the kubelet. More info: https://kubernetes.io/docs/concepts/containers/images/#specifying-imagepullsecrets-on-a-pod".to_owned()),
229 ..Default::default()
230 })),
231 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
232 array: Some(Box::new(crate::schemars::schema::ArrayValidation {
233 items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(__gen.subschema_for::<crate::api::core::v1::LocalObjectReference>()))),
234 ..Default::default()
235 })),
236 ..Default::default()
237 }),
238 ),
239 (
240 "kind".to_owned(),
241 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
242 metadata: Some(Box::new(crate::schemars::schema::Metadata {
243 description: Some("Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds".to_owned()),
244 ..Default::default()
245 })),
246 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
247 ..Default::default()
248 }),
249 ),
250 (
251 "metadata".to_owned(),
252 {
253 let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>().into_object();
254 schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
255 description: Some("Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata".to_owned()),
256 ..Default::default()
257 }));
258 crate::schemars::schema::Schema::Object(schema_obj)
259 },
260 ),
261 (
262 "secrets".to_owned(),
263 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
264 metadata: Some(Box::new(crate::schemars::schema::Metadata {
265 description: Some("Secrets is a list of the secrets in the same namespace that pods running using this ServiceAccount are allowed to use. Pods are only limited to this list if this service account has a \"kubernetes.io/enforce-mountable-secrets\" annotation set to \"true\". This field should not be used to find auto-generated service account token secrets for use outside of pods. Instead, tokens can be requested directly using the TokenRequest API, or service account token secrets can be manually created. More info: https://kubernetes.io/docs/concepts/configuration/secret".to_owned()),
266 ..Default::default()
267 })),
268 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
269 array: Some(Box::new(crate::schemars::schema::ArrayValidation {
270 items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(__gen.subschema_for::<crate::api::core::v1::ObjectReference>()))),
271 ..Default::default()
272 })),
273 ..Default::default()
274 }),
275 ),
276 ].into(),
277 required: [
278 "metadata".to_owned(),
279 ].into(),
280 ..Default::default()
281 })),
282 ..Default::default()
283 })
284 }
285}