syncable_cli/analyzer/kubelint/objectkinds/
mod.rs

1//! Object kind definitions and matching.
2//!
3//! Defines groups of Kubernetes object kinds that checks can target.
4
5use crate::analyzer::kubelint::types::ObjectKind;
6
7/// Check if an object kind matches a kind specifier.
8///
9/// Supports both specific kinds (e.g., "Deployment") and group specifiers
10/// (e.g., "DeploymentLike").
11pub fn matches_kind(specifier: &str, kind: &ObjectKind) -> bool {
12    match specifier {
13        "DeploymentLike" => kind.is_deployment_like(),
14        "JobLike" => kind.is_job_like(),
15        "Any" => true,
16        _ => specifier == kind.as_str(),
17    }
18}
19
20/// Get all object kinds that match a specifier.
21pub fn expand_kind_specifier(specifier: &str) -> Vec<ObjectKind> {
22    match specifier {
23        "DeploymentLike" => vec![
24            ObjectKind::Deployment,
25            ObjectKind::StatefulSet,
26            ObjectKind::DaemonSet,
27            ObjectKind::ReplicaSet,
28            ObjectKind::Pod,
29            ObjectKind::Job,
30            ObjectKind::CronJob,
31            ObjectKind::DeploymentConfig,
32        ],
33        "JobLike" => vec![ObjectKind::Job, ObjectKind::CronJob],
34        "Any" => vec![
35            ObjectKind::Deployment,
36            ObjectKind::StatefulSet,
37            ObjectKind::DaemonSet,
38            ObjectKind::ReplicaSet,
39            ObjectKind::Pod,
40            ObjectKind::Job,
41            ObjectKind::CronJob,
42            ObjectKind::Service,
43            ObjectKind::Ingress,
44            ObjectKind::NetworkPolicy,
45            ObjectKind::Role,
46            ObjectKind::ClusterRole,
47            ObjectKind::RoleBinding,
48            ObjectKind::ClusterRoleBinding,
49            ObjectKind::ServiceAccount,
50            ObjectKind::HorizontalPodAutoscaler,
51            ObjectKind::PodDisruptionBudget,
52        ],
53        _ => ObjectKind::from_kind(specifier)
54            .map(|k| vec![k])
55            .unwrap_or_default(),
56    }
57}