#[derive(Clone, Debug, Default, PartialEq)]
pub struct MatchResources {
pub exclude_resource_rules: Option<Vec<crate::api::admissionregistration::v1beta1::NamedRuleWithOperations>>,
pub match_policy: Option<String>,
pub namespace_selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>,
pub object_selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>,
pub resource_rules: Option<Vec<crate::api::admissionregistration::v1beta1::NamedRuleWithOperations>>,
}
impl crate::DeepMerge for MatchResources {
fn merge_from(&mut self, other: Self) {
crate::merge_strategies::list::atomic(&mut self.exclude_resource_rules, other.exclude_resource_rules);
crate::DeepMerge::merge_from(&mut self.match_policy, other.match_policy);
crate::DeepMerge::merge_from(&mut self.namespace_selector, other.namespace_selector);
crate::DeepMerge::merge_from(&mut self.object_selector, other.object_selector);
crate::merge_strategies::list::atomic(&mut self.resource_rules, other.resource_rules);
}
}
impl<'de> crate::serde::Deserialize<'de> for MatchResources {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
#[allow(non_camel_case_types)]
enum Field {
Key_exclude_resource_rules,
Key_match_policy,
Key_namespace_selector,
Key_object_selector,
Key_resource_rules,
Other,
}
impl<'de> crate::serde::Deserialize<'de> for Field {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
struct Visitor;
impl<'de> crate::serde::de::Visitor<'de> for Visitor {
type Value = Field;
fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("field identifier")
}
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
Ok(match v {
"excludeResourceRules" => Field::Key_exclude_resource_rules,
"matchPolicy" => Field::Key_match_policy,
"namespaceSelector" => Field::Key_namespace_selector,
"objectSelector" => Field::Key_object_selector,
"resourceRules" => Field::Key_resource_rules,
_ => Field::Other,
})
}
}
deserializer.deserialize_identifier(Visitor)
}
}
struct Visitor;
impl<'de> crate::serde::de::Visitor<'de> for Visitor {
type Value = MatchResources;
fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("MatchResources")
}
fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
let mut value_exclude_resource_rules: Option<Vec<crate::api::admissionregistration::v1beta1::NamedRuleWithOperations>> = None;
let mut value_match_policy: Option<String> = None;
let mut value_namespace_selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector> = None;
let mut value_object_selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector> = None;
let mut value_resource_rules: Option<Vec<crate::api::admissionregistration::v1beta1::NamedRuleWithOperations>> = None;
while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
match key {
Field::Key_exclude_resource_rules => value_exclude_resource_rules = crate::serde::de::MapAccess::next_value(&mut map)?,
Field::Key_match_policy => value_match_policy = crate::serde::de::MapAccess::next_value(&mut map)?,
Field::Key_namespace_selector => value_namespace_selector = crate::serde::de::MapAccess::next_value(&mut map)?,
Field::Key_object_selector => value_object_selector = crate::serde::de::MapAccess::next_value(&mut map)?,
Field::Key_resource_rules => value_resource_rules = crate::serde::de::MapAccess::next_value(&mut map)?,
Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
}
}
Ok(MatchResources {
exclude_resource_rules: value_exclude_resource_rules,
match_policy: value_match_policy,
namespace_selector: value_namespace_selector,
object_selector: value_object_selector,
resource_rules: value_resource_rules,
})
}
}
deserializer.deserialize_struct(
"MatchResources",
&[
"excludeResourceRules",
"matchPolicy",
"namespaceSelector",
"objectSelector",
"resourceRules",
],
Visitor,
)
}
}
impl crate::serde::Serialize for MatchResources {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
let mut state = serializer.serialize_struct(
"MatchResources",
self.exclude_resource_rules.as_ref().map_or(0, |_| 1) +
self.match_policy.as_ref().map_or(0, |_| 1) +
self.namespace_selector.as_ref().map_or(0, |_| 1) +
self.object_selector.as_ref().map_or(0, |_| 1) +
self.resource_rules.as_ref().map_or(0, |_| 1),
)?;
if let Some(value) = &self.exclude_resource_rules {
crate::serde::ser::SerializeStruct::serialize_field(&mut state, "excludeResourceRules", value)?;
}
if let Some(value) = &self.match_policy {
crate::serde::ser::SerializeStruct::serialize_field(&mut state, "matchPolicy", value)?;
}
if let Some(value) = &self.namespace_selector {
crate::serde::ser::SerializeStruct::serialize_field(&mut state, "namespaceSelector", value)?;
}
if let Some(value) = &self.object_selector {
crate::serde::ser::SerializeStruct::serialize_field(&mut state, "objectSelector", value)?;
}
if let Some(value) = &self.resource_rules {
crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resourceRules", value)?;
}
crate::serde::ser::SerializeStruct::end(state)
}
}
#[cfg(feature = "schemars")]
impl crate::schemars::JsonSchema for MatchResources {
fn schema_name() -> String {
"io.k8s.api.admissionregistration.v1beta1.MatchResources".to_owned()
}
fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
metadata: Some(Box::new(crate::schemars::schema::Metadata {
description: Some("MatchResources decides whether to run the admission control policy on an object based on whether it meets the match criteria. The exclude rules take precedence over include rules (if a resource matches both, it is excluded)".to_owned()),
..Default::default()
})),
instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
object: Some(Box::new(crate::schemars::schema::ObjectValidation {
properties: [
(
"excludeResourceRules".to_owned(),
crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
metadata: Some(Box::new(crate::schemars::schema::Metadata {
description: Some("ExcludeResourceRules describes what operations on what resources/subresources the ValidatingAdmissionPolicy should not care about. The exclude rules take precedence over include rules (if a resource matches both, it is excluded)".to_owned()),
..Default::default()
})),
instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
array: Some(Box::new(crate::schemars::schema::ArrayValidation {
items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(__gen.subschema_for::<crate::api::admissionregistration::v1beta1::NamedRuleWithOperations>()))),
..Default::default()
})),
..Default::default()
}),
),
(
"matchPolicy".to_owned(),
crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
metadata: Some(Box::new(crate::schemars::schema::Metadata {
description: Some("matchPolicy defines how the \"MatchResources\" list is used to match incoming requests. Allowed values are \"Exact\" or \"Equivalent\".\n\n- Exact: match a request only if it exactly matches a specified rule. For example, if deployments can be modified via apps/v1, apps/v1beta1, and extensions/v1beta1, but \"rules\" only included `apiGroups:[\"apps\"], apiVersions:[\"v1\"], resources: [\"deployments\"]`, a request to apps/v1beta1 or extensions/v1beta1 would not be sent to the ValidatingAdmissionPolicy.\n\n- Equivalent: match a request if modifies a resource listed in rules, even via another API group or version. For example, if deployments can be modified via apps/v1, apps/v1beta1, and extensions/v1beta1, and \"rules\" only included `apiGroups:[\"apps\"], apiVersions:[\"v1\"], resources: [\"deployments\"]`, a request to apps/v1beta1 or extensions/v1beta1 would be converted to apps/v1 and sent to the ValidatingAdmissionPolicy.\n\nDefaults to \"Equivalent\"".to_owned()),
..Default::default()
})),
instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
..Default::default()
}),
),
(
"namespaceSelector".to_owned(),
{
let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>().into_object();
schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
description: Some("NamespaceSelector decides whether to run the admission control policy on an object based on whether the namespace for that object matches the selector. If the object itself is a namespace, the matching is performed on object.metadata.labels. If the object is another cluster scoped resource, it never skips the policy.\n\nFor example, to run the webhook on any objects whose namespace is not associated with \"runlevel\" of \"0\" or \"1\"; you will set the selector as follows: \"namespaceSelector\": {\n \"matchExpressions\": [\n {\n \"key\": \"runlevel\",\n \"operator\": \"NotIn\",\n \"values\": [\n \"0\",\n \"1\"\n ]\n }\n ]\n}\n\nIf instead you want to only run the policy on any objects whose namespace is associated with the \"environment\" of \"prod\" or \"staging\"; you will set the selector as follows: \"namespaceSelector\": {\n \"matchExpressions\": [\n {\n \"key\": \"environment\",\n \"operator\": \"In\",\n \"values\": [\n \"prod\",\n \"staging\"\n ]\n }\n ]\n}\n\nSee https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ for more examples of label selectors.\n\nDefault to the empty LabelSelector, which matches everything.".to_owned()),
..Default::default()
}));
crate::schemars::schema::Schema::Object(schema_obj)
},
),
(
"objectSelector".to_owned(),
{
let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>().into_object();
schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
description: Some("ObjectSelector decides whether to run the validation based on if the object has matching labels. objectSelector is evaluated against both the oldObject and newObject that would be sent to the cel validation, and is considered to match if either object matches the selector. A null object (oldObject in the case of create, or newObject in the case of delete) or an object that cannot have labels (like a DeploymentRollback or a PodProxyOptions object) is not considered to match. Use the object selector only if the webhook is opt-in, because end users may skip the admission webhook by setting the labels. Default to the empty LabelSelector, which matches everything.".to_owned()),
..Default::default()
}));
crate::schemars::schema::Schema::Object(schema_obj)
},
),
(
"resourceRules".to_owned(),
crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
metadata: Some(Box::new(crate::schemars::schema::Metadata {
description: Some("ResourceRules describes what operations on what resources/subresources the ValidatingAdmissionPolicy matches. The policy cares about an operation if it matches _any_ Rule.".to_owned()),
..Default::default()
})),
instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
array: Some(Box::new(crate::schemars::schema::ArrayValidation {
items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(__gen.subschema_for::<crate::api::admissionregistration::v1beta1::NamedRuleWithOperations>()))),
..Default::default()
})),
..Default::default()
}),
),
].into(),
..Default::default()
})),
..Default::default()
})
}
}