vector/kubernetes/pod_manager_logic.rs
1//! This mod contains bits of logic related to the `kubelet` part called
2//! Pod Manager internal implementation.
3
4use k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta;
5
6/// Extract the static pod config hashsum from the mirror pod annotations.
7///
8/// This part of Kubernetes changed a bit over time, so we're implementing
9/// support up to 1.14, which is an MSKV at this time.
10///
11/// See: <https://github.com/kubernetes/kubernetes/blob/cea1d4e20b4a7886d8ff65f34c6d4f95efcb4742/pkg/kubelet/pod/mirror_client.go#L80-L81>
12pub fn extract_static_pod_config_hashsum(metadata: &ObjectMeta) -> Option<&str> {
13 let annotations = metadata.annotations.as_ref()?;
14 annotations
15 .get("kubernetes.io/config.mirror")
16 .map(String::as_str)
17}
18
19#[cfg(test)]
20mod tests {
21 use super::*;
22
23 #[test]
24 fn test_extract_static_pod_config_hashsum() {
25 let cases = vec![
26 (ObjectMeta::default(), None),
27 (
28 ObjectMeta {
29 annotations: Some(vec![].into_iter().collect()),
30 ..ObjectMeta::default()
31 },
32 None,
33 ),
34 (
35 ObjectMeta {
36 annotations: Some(
37 vec![(
38 "kubernetes.io/config.mirror".to_owned(),
39 "config-hashsum".to_owned(),
40 )]
41 .into_iter()
42 .collect(),
43 ),
44 ..ObjectMeta::default()
45 },
46 Some("config-hashsum"),
47 ),
48 (
49 ObjectMeta {
50 annotations: Some(
51 vec![
52 (
53 "kubernetes.io/config.mirror".to_owned(),
54 "config-hashsum".to_owned(),
55 ),
56 ("other".to_owned(), "value".to_owned()),
57 ]
58 .into_iter()
59 .collect(),
60 ),
61 ..ObjectMeta::default()
62 },
63 Some("config-hashsum"),
64 ),
65 ];
66
67 for (metadata, expected) in cases {
68 assert_eq!(extract_static_pod_config_hashsum(&metadata), expected);
69 }
70 }
71}