#
k8s_openapi/v1_35/api/core/v1/
service_account.rs

    1// Generated from definition io.k8s.api.core.v1.ServiceAccount
    2
    3/// 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
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct ServiceAccount {
    6    /// AutomountServiceAccountToken indicates whether pods running as this service account should have an API token automatically mounted. Can be overridden at the pod level.
    7    pub automount_service_account_token: Option<bool>,
    8
    9    /// 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
    10    pub image_pull_secrets: Option<std::vec::Vec<crate::api::core::v1::LocalObjectReference>>,
    11
    12    /// Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
    13    pub metadata: crate::apimachinery::pkg::apis::meta::v1::ObjectMeta,
    14
    15    /// 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". The "kubernetes.io/enforce-mountable-secrets" annotation is deprecated since v1.32. Prefer separate namespaces to isolate access to mounted secrets. 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
    16    pub secrets: Option<std::vec::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 core::fmt::Formatter<'_>) -> core::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 core::fmt::Formatter<'_>) -> core::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<std::vec::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<std::vec::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: std::string::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: std::string::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() -> std::borrow::Cow<'static, str> {
    190        "io.k8s.api.core.v1.ServiceAccount".into()
    191    }
    192
    193    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    194        crate::schemars::json_schema!({
    195            "description": "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",
    196            "type": "object",
    197            "properties": {
    198                "apiVersion": {
    199                    "description": "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",
    200                    "type": "string",
    201                },
    202                "automountServiceAccountToken": {
    203                    "description": "AutomountServiceAccountToken indicates whether pods running as this service account should have an API token automatically mounted. Can be overridden at the pod level.",
    204                    "type": "boolean",
    205                },
    206                "imagePullSecrets": {
    207                    "description": "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",
    208                    "type": "array",
    209                    "items": (__gen.subschema_for::<crate::api::core::v1::LocalObjectReference>()),
    210                },
    211                "kind": {
    212                    "description": "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",
    213                    "type": "string",
    214                },
    215                "metadata": ({
    216                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>();
    217                    schema_obj.ensure_object().insert("description".into(), "Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata".into());
    218                    schema_obj
    219                }),
    220                "secrets": {
    221                    "description": "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\". The \"kubernetes.io/enforce-mountable-secrets\" annotation is deprecated since v1.32. Prefer separate namespaces to isolate access to mounted secrets. 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",
    222                    "type": "array",
    223                    "items": (__gen.subschema_for::<crate::api::core::v1::ObjectReference>()),
    224                },
    225            },
    226            "required": [
    227                "metadata",
    228            ],
    229        })
    230    }
    231}