tests_fuzz/utils/crd/
common.rsuse std::collections::BTreeMap;
use derive_builder::Builder;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "kebab-case")]
pub enum Mode {
One,
All,
Fixed,
FixedPercent,
RandomMaxPercent,
}
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, Default, Builder, JsonSchema)]
#[serde(default, rename_all = "camelCase")]
#[builder(setter(into, strip_option), default)]
pub struct Selector {
#[serde(skip_serializing_if = "Vec::is_empty")]
namespaces: Vec<String>,
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
label_selectors: BTreeMap<String, String>,
#[serde(skip_serializing_if = "Vec::is_empty")]
expression_selectors: Vec<ExpressionSelector>,
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
annotation_selectors: BTreeMap<String, String>,
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
field_selectors: BTreeMap<String, String>,
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
pod_phase_selectors: BTreeMap<String, String>,
}
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, JsonSchema)]
pub struct ExpressionSelector {
key: String,
operator: String,
values: Vec<String>,
}
#[cfg(test)]
mod tests {
use std::collections::BTreeMap;
use super::SelectorBuilder;
#[test]
fn test_serde() {
let mut fs = BTreeMap::new();
fs.insert("app.kubernetes.io/component".into(), "tikv".into());
let selector = SelectorBuilder::default()
.field_selectors(fs)
.build()
.unwrap();
let ser = serde_yaml::to_string(&selector).unwrap();
assert_eq!(
r#"fieldSelectors:
app.kubernetes.io/component: tikv
"#,
ser
);
}
}