-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
307 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
pub mod patch_ext; | ||
|
||
use std::collections::hash_map::DefaultHasher; | ||
use std::hash::{ | ||
Hash, | ||
Hasher, | ||
}; | ||
|
||
use serde_json as json; | ||
|
||
pub fn hash(value: &json::Value) -> anyhow::Result<u64> { | ||
let mut s = DefaultHasher::new(); | ||
Hash::hash_slice(&serde_json::to_vec(value)?, &mut s); | ||
Ok(s.finish()) | ||
} | ||
|
||
#[cfg(test)] | ||
mod patch_ext_test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
use std::fmt; | ||
|
||
use kube::api::{ | ||
DynamicObject, | ||
GroupVersionKind, | ||
}; | ||
use serde::{ | ||
de, | ||
Deserialize, | ||
Deserializer, | ||
Serialize, | ||
Serializer, | ||
}; | ||
|
||
use crate::errors::*; | ||
|
||
#[derive(Clone, Debug, Hash, Eq, PartialEq)] | ||
pub struct GVKKey { | ||
pub gvk: GroupVersionKind, | ||
} | ||
|
||
impl GVKKey { | ||
pub fn from_dynamic_obj(obj: &DynamicObject) -> anyhow::Result<Self> { | ||
match &obj.types { | ||
Some(t) => Ok(GVKKey { gvk: t.try_into()? }), | ||
None => bail!("no type data present"), | ||
} | ||
} | ||
} | ||
|
||
impl Serialize for GVKKey { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: Serializer, | ||
{ | ||
let skey = format!("{}/{}.{}", self.gvk.group, self.gvk.version, self.gvk.kind); | ||
serializer.serialize_str(&skey) | ||
} | ||
} | ||
|
||
struct ObjectKeyVisitor; | ||
|
||
impl<'de> de::Visitor<'de> for ObjectKeyVisitor { | ||
type Value = GVKKey; | ||
|
||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { | ||
formatter.write_str("a GroupVersionKind in the format group/version.kind") | ||
} | ||
|
||
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E> | ||
where | ||
E: de::Error, | ||
{ | ||
let parts: Vec<_> = value.split(|c| c == '/' || c == '.').collect(); | ||
if parts.len() != 3 { | ||
return Err(E::custom(format!("invalid format for gvk: {}", value))); | ||
} | ||
Ok(GVKKey { | ||
gvk: GroupVersionKind { | ||
group: parts[0].into(), | ||
version: parts[1].into(), | ||
kind: parts[2].into(), | ||
}, | ||
}) | ||
} | ||
} | ||
|
||
impl<'de> Deserialize<'de> for GVKKey { | ||
fn deserialize<D>(deserializer: D) -> Result<GVKKey, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
deserializer.deserialize_str(ObjectKeyVisitor) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
mod gvk; | ||
mod util; | ||
|
||
pub use gvk::*; | ||
pub use util::*; | ||
|
||
#[cfg(test)] | ||
mod util_test; |
Oops, something went wrong.