k8s_openapi/v1_32/api/admissionregistration/v1alpha1/
apply_configuration.rs

1// Generated from definition io.k8s.api.admissionregistration.v1alpha1.ApplyConfiguration
2
3/// ApplyConfiguration defines the desired configuration values of an object.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ApplyConfiguration {
6    /// expression will be evaluated by CEL to create an apply configuration. ref: https://github.com/google/cel-spec
7    ///
8    /// Apply configurations are declared in CEL using object initialization. For example, this CEL expression returns an apply configuration to set a single field:
9    ///
10    ///   Object{
11    ///       spec: Object.spec{
12    ///         serviceAccountName: "example"
13    ///       }
14    ///     }
15    ///
16    /// Apply configurations may not modify atomic structs, maps or arrays due to the risk of accidental deletion of values not included in the apply configuration.
17    ///
18    /// CEL expressions have access to the object types needed to create apply configurations:
19    ///
20    /// - 'Object' - CEL type of the resource object. - 'Object.\<fieldName\>' - CEL type of object field (such as 'Object.spec') - 'Object.\<fieldName1\>.\<fieldName2\>...\<fieldNameN\>` - CEL type of nested field (such as 'Object.spec.containers')
21    ///
22    /// CEL expressions have access to the contents of the API request, organized into CEL variables as well as some other useful variables:
23    ///
24    /// - 'object' - The object from the incoming request. The value is null for DELETE requests. - 'oldObject' - The existing object. The value is null for CREATE requests. - 'request' - Attributes of the API request(\[ref\](/pkg/apis/admission/types.go#AdmissionRequest)). - 'params' - Parameter resource referred to by the policy binding being evaluated. Only populated if the policy has a ParamKind. - 'namespaceObject' - The namespace object that the incoming object belongs to. The value is null for cluster-scoped resources. - 'variables' - Map of composited variables, from its name to its lazily evaluated value.
25    ///   For example, a variable named 'foo' can be accessed as 'variables.foo'.
26    /// - 'authorizer' - A CEL Authorizer. May be used to perform authorization checks for the principal (user or service account) of the request.
27    ///   See https://pkg.go.dev/k8s.io/apiserver/pkg/cel/library#Authz
28    /// - 'authorizer.requestResource' - A CEL ResourceCheck constructed from the 'authorizer' and configured with the
29    ///   request resource.
30    ///
31    /// The `apiVersion`, `kind`, `metadata.name` and `metadata.generateName` are always accessible from the root of the object. No other metadata properties are accessible.
32    ///
33    /// Only property names of the form `\[a-zA-Z_.-/\]\[a-zA-Z0-9_.-/\]*` are accessible. Required.
34    pub expression: Option<String>,
35}
36
37impl crate::DeepMerge for ApplyConfiguration {
38    fn merge_from(&mut self, other: Self) {
39        crate::DeepMerge::merge_from(&mut self.expression, other.expression);
40    }
41}
42
43impl<'de> crate::serde::Deserialize<'de> for ApplyConfiguration {
44    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
45        #[allow(non_camel_case_types)]
46        enum Field {
47            Key_expression,
48            Other,
49        }
50
51        impl<'de> crate::serde::Deserialize<'de> for Field {
52            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
53                struct Visitor;
54
55                impl crate::serde::de::Visitor<'_> for Visitor {
56                    type Value = Field;
57
58                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
59                        f.write_str("field identifier")
60                    }
61
62                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
63                        Ok(match v {
64                            "expression" => Field::Key_expression,
65                            _ => Field::Other,
66                        })
67                    }
68                }
69
70                deserializer.deserialize_identifier(Visitor)
71            }
72        }
73
74        struct Visitor;
75
76        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
77            type Value = ApplyConfiguration;
78
79            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
80                f.write_str("ApplyConfiguration")
81            }
82
83            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
84                let mut value_expression: Option<String> = None;
85
86                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
87                    match key {
88                        Field::Key_expression => value_expression = crate::serde::de::MapAccess::next_value(&mut map)?,
89                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
90                    }
91                }
92
93                Ok(ApplyConfiguration {
94                    expression: value_expression,
95                })
96            }
97        }
98
99        deserializer.deserialize_struct(
100            "ApplyConfiguration",
101            &[
102                "expression",
103            ],
104            Visitor,
105        )
106    }
107}
108
109impl crate::serde::Serialize for ApplyConfiguration {
110    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
111        let mut state = serializer.serialize_struct(
112            "ApplyConfiguration",
113            self.expression.as_ref().map_or(0, |_| 1),
114        )?;
115        if let Some(value) = &self.expression {
116            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "expression", value)?;
117        }
118        crate::serde::ser::SerializeStruct::end(state)
119    }
120}
121
122#[cfg(feature = "schemars")]
123impl crate::schemars::JsonSchema for ApplyConfiguration {
124    fn schema_name() -> String {
125        "io.k8s.api.admissionregistration.v1alpha1.ApplyConfiguration".to_owned()
126    }
127
128    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
129        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
130            metadata: Some(Box::new(crate::schemars::schema::Metadata {
131                description: Some("ApplyConfiguration defines the desired configuration values of an object.".to_owned()),
132                ..Default::default()
133            })),
134            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
135            object: Some(Box::new(crate::schemars::schema::ObjectValidation {
136                properties: [
137                    (
138                        "expression".to_owned(),
139                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
140                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
141                                description: Some("expression will be evaluated by CEL to create an apply configuration. ref: https://github.com/google/cel-spec\n\nApply configurations are declared in CEL using object initialization. For example, this CEL expression returns an apply configuration to set a single field:\n\n\tObject{\n\t  spec: Object.spec{\n\t    serviceAccountName: \"example\"\n\t  }\n\t}\n\nApply configurations may not modify atomic structs, maps or arrays due to the risk of accidental deletion of values not included in the apply configuration.\n\nCEL expressions have access to the object types needed to create apply configurations:\n\n- 'Object' - CEL type of the resource object. - 'Object.<fieldName>' - CEL type of object field (such as 'Object.spec') - 'Object.<fieldName1>.<fieldName2>...<fieldNameN>` - CEL type of nested field (such as 'Object.spec.containers')\n\nCEL expressions have access to the contents of the API request, organized into CEL variables as well as some other useful variables:\n\n- 'object' - The object from the incoming request. The value is null for DELETE requests. - 'oldObject' - The existing object. The value is null for CREATE requests. - 'request' - Attributes of the API request([ref](/pkg/apis/admission/types.go#AdmissionRequest)). - 'params' - Parameter resource referred to by the policy binding being evaluated. Only populated if the policy has a ParamKind. - 'namespaceObject' - The namespace object that the incoming object belongs to. The value is null for cluster-scoped resources. - 'variables' - Map of composited variables, from its name to its lazily evaluated value.\n  For example, a variable named 'foo' can be accessed as 'variables.foo'.\n- 'authorizer' - A CEL Authorizer. May be used to perform authorization checks for the principal (user or service account) of the request.\n  See https://pkg.go.dev/k8s.io/apiserver/pkg/cel/library#Authz\n- 'authorizer.requestResource' - A CEL ResourceCheck constructed from the 'authorizer' and configured with the\n  request resource.\n\nThe `apiVersion`, `kind`, `metadata.name` and `metadata.generateName` are always accessible from the root of the object. No other metadata properties are accessible.\n\nOnly property names of the form `[a-zA-Z_.-/][a-zA-Z0-9_.-/]*` are accessible. Required.".to_owned()),
142                                ..Default::default()
143                            })),
144                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
145                            ..Default::default()
146                        }),
147                    ),
148                ].into(),
149                ..Default::default()
150            })),
151            ..Default::default()
152        })
153    }
154}