k8s_openapi/v1_35/api/core/v1/
workload_reference.rs

1// Generated from definition io.k8s.api.core.v1.WorkloadReference
2
3/// WorkloadReference identifies the Workload object and PodGroup membership that a Pod belongs to. The scheduler uses this information to apply workload-aware scheduling semantics.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct WorkloadReference {
6    /// Name defines the name of the Workload object this Pod belongs to. Workload must be in the same namespace as the Pod. If it doesn't match any existing Workload, the Pod will remain unschedulable until a Workload object is created and observed by the kube-scheduler. It must be a DNS subdomain.
7    pub name: std::string::String,
8
9    /// PodGroup is the name of the PodGroup within the Workload that this Pod belongs to. If it doesn't match any existing PodGroup within the Workload, the Pod will remain unschedulable until the Workload object is recreated and observed by the kube-scheduler. It must be a DNS label.
10    pub pod_group: std::string::String,
11
12    /// PodGroupReplicaKey specifies the replica key of the PodGroup to which this Pod belongs. It is used to distinguish pods belonging to different replicas of the same pod group. The pod group policy is applied separately to each replica. When set, it must be a DNS label.
13    pub pod_group_replica_key: Option<std::string::String>,
14}
15
16impl crate::DeepMerge for WorkloadReference {
17    fn merge_from(&mut self, other: Self) {
18        crate::DeepMerge::merge_from(&mut self.name, other.name);
19        crate::DeepMerge::merge_from(&mut self.pod_group, other.pod_group);
20        crate::DeepMerge::merge_from(&mut self.pod_group_replica_key, other.pod_group_replica_key);
21    }
22}
23
24impl<'de> crate::serde::Deserialize<'de> for WorkloadReference {
25    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
26        #[allow(non_camel_case_types)]
27        enum Field {
28            Key_name,
29            Key_pod_group,
30            Key_pod_group_replica_key,
31            Other,
32        }
33
34        impl<'de> crate::serde::Deserialize<'de> for Field {
35            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
36                struct Visitor;
37
38                impl crate::serde::de::Visitor<'_> for Visitor {
39                    type Value = Field;
40
41                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
42                        f.write_str("field identifier")
43                    }
44
45                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
46                        Ok(match v {
47                            "name" => Field::Key_name,
48                            "podGroup" => Field::Key_pod_group,
49                            "podGroupReplicaKey" => Field::Key_pod_group_replica_key,
50                            _ => Field::Other,
51                        })
52                    }
53                }
54
55                deserializer.deserialize_identifier(Visitor)
56            }
57        }
58
59        struct Visitor;
60
61        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
62            type Value = WorkloadReference;
63
64            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
65                f.write_str("WorkloadReference")
66            }
67
68            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
69                let mut value_name: Option<std::string::String> = None;
70                let mut value_pod_group: Option<std::string::String> = None;
71                let mut value_pod_group_replica_key: Option<std::string::String> = None;
72
73                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
74                    match key {
75                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
76                        Field::Key_pod_group => value_pod_group = crate::serde::de::MapAccess::next_value(&mut map)?,
77                        Field::Key_pod_group_replica_key => value_pod_group_replica_key = crate::serde::de::MapAccess::next_value(&mut map)?,
78                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
79                    }
80                }
81
82                Ok(WorkloadReference {
83                    name: value_name.unwrap_or_default(),
84                    pod_group: value_pod_group.unwrap_or_default(),
85                    pod_group_replica_key: value_pod_group_replica_key,
86                })
87            }
88        }
89
90        deserializer.deserialize_struct(
91            "WorkloadReference",
92            &[
93                "name",
94                "podGroup",
95                "podGroupReplicaKey",
96            ],
97            Visitor,
98        )
99    }
100}
101
102impl crate::serde::Serialize for WorkloadReference {
103    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
104        let mut state = serializer.serialize_struct(
105            "WorkloadReference",
106            2 +
107            self.pod_group_replica_key.as_ref().map_or(0, |_| 1),
108        )?;
109        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
110        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "podGroup", &self.pod_group)?;
111        if let Some(value) = &self.pod_group_replica_key {
112            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "podGroupReplicaKey", value)?;
113        }
114        crate::serde::ser::SerializeStruct::end(state)
115    }
116}
117
118#[cfg(feature = "schemars")]
119impl crate::schemars::JsonSchema for WorkloadReference {
120    fn schema_name() -> std::borrow::Cow<'static, str> {
121        "io.k8s.api.core.v1.WorkloadReference".into()
122    }
123
124    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
125        crate::schemars::json_schema!({
126            "description": "WorkloadReference identifies the Workload object and PodGroup membership that a Pod belongs to. The scheduler uses this information to apply workload-aware scheduling semantics.",
127            "type": "object",
128            "properties": {
129                "name": {
130                    "description": "Name defines the name of the Workload object this Pod belongs to. Workload must be in the same namespace as the Pod. If it doesn't match any existing Workload, the Pod will remain unschedulable until a Workload object is created and observed by the kube-scheduler. It must be a DNS subdomain.",
131                    "type": "string",
132                },
133                "podGroup": {
134                    "description": "PodGroup is the name of the PodGroup within the Workload that this Pod belongs to. If it doesn't match any existing PodGroup within the Workload, the Pod will remain unschedulable until the Workload object is recreated and observed by the kube-scheduler. It must be a DNS label.",
135                    "type": "string",
136                },
137                "podGroupReplicaKey": {
138                    "description": "PodGroupReplicaKey specifies the replica key of the PodGroup to which this Pod belongs. It is used to distinguish pods belonging to different replicas of the same pod group. The pod group policy is applied separately to each replica. When set, it must be a DNS label.",
139                    "type": "string",
140                },
141            },
142            "required": [
143                "name",
144                "podGroup",
145            ],
146        })
147    }
148}