Skip to main content

k8s_openapi/v1_37/api/resource/v1/
device_derived_attribute.rs

1// Generated from definition io.k8s.api.resource.v1.DeviceDerivedAttribute
2
3/// DeviceDerivedAttribute defines a derived attribute computed via CEL.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct DeviceDerivedAttribute {
6    /// Expression is a CEL expression evaluated against each candidate device. The expression must evaluate to a primitive scalar (string, integer, boolean, or semver) or a list of these scalars (\[\]string, \[\]int64, \[\]bool, \[\]semver) to act as a virtual grouping key. Any other return type is an error and causes CEL evaluation for the device to fail.
7    ///
8    /// The expression's input is an object named "device", which carries the same properties as in a CELDeviceSelector.
9    ///
10    /// When pod scheduling encounters CEL runtime errors (such as looking up an attribute that isn't defined) for some devices, it will abort allocation and fail scheduling for the Pod. Surfacing evaluation errors immediately prevents silent topology matching failures that are extremely hard to detect. A robust expression should, for example, check for the existence of attributes before referencing them to avoid runtime evaluation errors.
11    ///
12    /// The expression gets evaluated after a device has passed the other selector expressions for the request in which this expression is used. This allows writing expressions that are tailored towards the specific devices being requested (for example, by assuming the device is from a certain vendor and skipping those checks).
13    ///
14    /// The length of the expression must be smaller or equal to 10 Ki. The cost of evaluating it is also limited based on the estimated number of logical steps; the combined cost of all derived attributes in a claim is capped by a shared CEL cost budget.
15    pub expression: std::string::String,
16
17    /// Name is the identifier for this derived attribute, used in constraints.
18    ///
19    /// It must be a DNS subdomain followed by a slash ("/") followed by a C identifier (e.g. "example.com/numaNode" or "derived/numaNode").
20    ///
21    /// If the chosen name matches an existing physical attribute from a driver, the derived attribute's expression will shadow the physical attribute, and its evaluated value will be used in constraints instead. When the goal is to define a derived attribute that is only used within the ResourceClaim and not meant to shadow an existing attribute, use a domain prefix that no DRA driver should be using (e.g. "derived/myAttribute").
22    ///
23    /// It is not valid to define a derived attribute that isn't used in at least one constraint.
24    pub name: std::string::String,
25}
26
27impl crate::DeepMerge for DeviceDerivedAttribute {
28    fn merge_from(&mut self, other: Self) {
29        crate::DeepMerge::merge_from(&mut self.expression, other.expression);
30        crate::DeepMerge::merge_from(&mut self.name, other.name);
31    }
32}
33
34impl<'de> crate::serde::Deserialize<'de> for DeviceDerivedAttribute {
35    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
36        #[allow(non_camel_case_types)]
37        enum Field {
38            Key_expression,
39            Key_name,
40            Other,
41        }
42
43        impl<'de> crate::serde::Deserialize<'de> for Field {
44            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
45                struct Visitor;
46
47                impl crate::serde::de::Visitor<'_> for Visitor {
48                    type Value = Field;
49
50                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
51                        f.write_str("field identifier")
52                    }
53
54                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
55                        Ok(match v {
56                            "expression" => Field::Key_expression,
57                            "name" => Field::Key_name,
58                            _ => Field::Other,
59                        })
60                    }
61                }
62
63                deserializer.deserialize_identifier(Visitor)
64            }
65        }
66
67        struct Visitor;
68
69        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
70            type Value = DeviceDerivedAttribute;
71
72            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
73                f.write_str("DeviceDerivedAttribute")
74            }
75
76            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
77                let mut value_expression: Option<std::string::String> = None;
78                let mut value_name: Option<std::string::String> = None;
79
80                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
81                    match key {
82                        Field::Key_expression => value_expression = crate::serde::de::MapAccess::next_value(&mut map)?,
83                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
84                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
85                    }
86                }
87
88                Ok(DeviceDerivedAttribute {
89                    expression: value_expression.unwrap_or_default(),
90                    name: value_name.unwrap_or_default(),
91                })
92            }
93        }
94
95        deserializer.deserialize_struct(
96            "DeviceDerivedAttribute",
97            &[
98                "expression",
99                "name",
100            ],
101            Visitor,
102        )
103    }
104}
105
106impl crate::serde::Serialize for DeviceDerivedAttribute {
107    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
108        let mut state = serializer.serialize_struct(
109            "DeviceDerivedAttribute",
110            2,
111        )?;
112        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "expression", &self.expression)?;
113        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
114        crate::serde::ser::SerializeStruct::end(state)
115    }
116}
117
118#[cfg(feature = "schemars")]
119impl crate::schemars::JsonSchema for DeviceDerivedAttribute {
120    fn schema_name() -> std::borrow::Cow<'static, str> {
121        "io.k8s.api.resource.v1.DeviceDerivedAttribute".into()
122    }
123
124    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
125        crate::schemars::json_schema!({
126            "description": "DeviceDerivedAttribute defines a derived attribute computed via CEL.",
127            "type": "object",
128            "properties": {
129                "expression": {
130                    "description": "Expression is a CEL expression evaluated against each candidate device. The expression must evaluate to a primitive scalar (string, integer, boolean, or semver) or a list of these scalars ([]string, []int64, []bool, []semver) to act as a virtual grouping key. Any other return type is an error and causes CEL evaluation for the device to fail.\n\nThe expression's input is an object named \"device\", which carries the same properties as in a CELDeviceSelector.\n\nWhen pod scheduling encounters CEL runtime errors (such as looking up an attribute that isn't defined) for some devices, it will abort allocation and fail scheduling for the Pod. Surfacing evaluation errors immediately prevents silent topology matching failures that are extremely hard to detect. A robust expression should, for example, check for the existence of attributes before referencing them to avoid runtime evaluation errors.\n\nThe expression gets evaluated after a device has passed the other selector expressions for the request in which this expression is used. This allows writing expressions that are tailored towards the specific devices being requested (for example, by assuming the device is from a certain vendor and skipping those checks).\n\nThe length of the expression must be smaller or equal to 10 Ki. The cost of evaluating it is also limited based on the estimated number of logical steps; the combined cost of all derived attributes in a claim is capped by a shared CEL cost budget.",
131                    "type": "string",
132                },
133                "name": {
134                    "description": "Name is the identifier for this derived attribute, used in constraints.\n\nIt must be a DNS subdomain followed by a slash (\"/\") followed by a C identifier (e.g. \"example.com/numaNode\" or \"derived/numaNode\").\n\nIf the chosen name matches an existing physical attribute from a driver, the derived attribute's expression will shadow the physical attribute, and its evaluated value will be used in constraints instead. When the goal is to define a derived attribute that is only used within the ResourceClaim and not meant to shadow an existing attribute, use a domain prefix that no DRA driver should be using (e.g. \"derived/myAttribute\").\n\nIt is not valid to define a derived attribute that isn't used in at least one constraint.",
135                    "type": "string",
136                },
137            },
138            "required": [
139                "expression",
140                "name",
141            ],
142        })
143    }
144}