Skip to content

Commit

Permalink
Resetore RequiredLabels
Browse files Browse the repository at this point in the history
  • Loading branch information
gnieto committed Sep 9, 2019
1 parent f9e1596 commit 349f4f9
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 25 deletions.
4 changes: 2 additions & 2 deletions korrecte-autogen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ use kube::client::APIClient;
use kube::Result;
{}
use serde::de::DeserializeOwned;
use super::{{ObjectRepository, Identifier}};
use super::Identifier;
use crate::linters::KubeObjectType;
use crate::kube::NewObjectRepository;
Expand Down Expand Up @@ -144,7 +144,7 @@ impl NewObjectRepository for FrozenObjectRepository {{
&self.objects
}}
fn find(&self, id: &Identifier) -> Option<&KubeObjectType> {{
fn find(&self, _id: &Identifier) -> Option<&KubeObjectType> {{
unimplemented!()
}}
}}
Expand Down
6 changes: 3 additions & 3 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use serde::Deserialize;
//use crate::linters::lints::required_labels::Config as RequiredLabelsConfig;
use crate::linters::lints::required_labels::Config as RequiredLabelsConfig;
use crate::linters::lints::environment_passwords::Config as EnvironmentPasswordsConfig;

#[derive(Default, Deserialize, Debug)]
pub struct Config {
// #[serde(default)]
// pub(crate) required_labels: RequiredLabelsConfig,
#[serde(default)]
pub(crate) required_labels: RequiredLabelsConfig,
#[serde(default)]
pub(crate) environment_passwords: EnvironmentPasswordsConfig,
}
4 changes: 2 additions & 2 deletions src/kube/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use k8s_openapi::api::apps;


use serde::de::DeserializeOwned;
use super::{ObjectRepository, Identifier};
use super::Identifier;
use crate::linters::KubeObjectType;
use crate::kube::NewObjectRepository;

Expand Down Expand Up @@ -102,7 +102,7 @@ impl NewObjectRepository for FrozenObjectRepository {
&self.objects
}

fn find(&self, id: &Identifier) -> Option<&KubeObjectType> {
fn find(&self, _id: &Identifier) -> Option<&KubeObjectType> {
unimplemented!()
}
}
16 changes: 4 additions & 12 deletions src/linters/lints/environment_passwords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,8 @@ mod tests {
use crate::linters::lints::environment_passwords::{EnvironmentPasswords, Config};
use crate::linters::Lint;
use kube::api::{Object};
use crate::reporting::{SingleThreadedReporter, Reporter};
use k8s_openapi::api::core::v1::{PodSpec, PodStatus};
use serde_json::Value;
use k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta;
use crate::linters::WithSpec;

#[test]
fn it_finds_passwords_on_pods() {
Expand All @@ -130,11 +127,9 @@ mod tests {
}
]);
let pod = get_pod_with_environment_vars(envvars);
let reporter = SingleThreadedReporter::default();

let linter = EnvironmentPasswords::new(Config::default());

let findings = linter.v1_pod(&pod.spec, &ObjectMeta::default()).unwrap();
let findings = linter.v1_pod(&pod);
assert_eq!(1, findings.len());
let finding= &findings[0];
assert_eq!(finding.spec(), &linter.spec());
Expand All @@ -155,11 +150,10 @@ mod tests {
}
]);
let pod = get_pod_with_environment_vars(envvars);
let reporter = SingleThreadedReporter::default();

let linter = EnvironmentPasswords::new(Config::default());

let lints = linter.v1_pod(&pod.spec, &ObjectMeta::default()).unwrap();
let lints = linter.v1_pod(&pod);
assert_eq!(0, lints.len());
}

Expand All @@ -172,11 +166,10 @@ mod tests {
}
]);
let pod = get_pod_with_environment_vars(envvars);
let reporter = SingleThreadedReporter::default();

let linter = EnvironmentPasswords::new(Config::default());

let lints = linter.v1_pod(&pod.spec, &ObjectMeta::default()).unwrap();
let lints = linter.v1_pod(&pod);
assert_eq!(1, lints.len());
let finding= &lints[0];
assert_eq!(finding.spec(), &linter.spec());
Expand All @@ -200,12 +193,11 @@ mod tests {
}
]);
let pod = get_pod_with_environment_vars(envvars);
let reporter = SingleThreadedReporter::default();

let config = Config::new(vec!["SUSPICIOUS".to_string(), "ANOTHER_KEY".to_string()]);
let linter = EnvironmentPasswords::new(config);

let lints = linter.v1_pod(&pod.spec, &ObjectMeta::default()).unwrap();
let lints = linter.v1_pod(&pod);

assert_eq!(2, lints.len());
let finding= &lints[0];
Expand Down
2 changes: 1 addition & 1 deletion src/linters/lints/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//pub(crate) mod required_labels;
pub(crate) mod required_labels;
//pub(crate) mod overlapping_probes;
//pub(crate) mod never_restart_with_liveness_probe;
//pub(crate) mod service_without_matching_labels;
Expand Down
10 changes: 7 additions & 3 deletions src/linters/lints/required_labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::linters::{Lint, LintSpec, Group};
use kube::api::Object;
use k8s_openapi::api::core::v1::{PodSpec, PodStatus};
use serde::Deserialize;
use crate::reporting::{Reporter, Finding};
use crate::reporting::Finding;
use std::collections::HashMap;

/// **What it does:** Checks for missing required labels
Expand Down Expand Up @@ -35,7 +35,9 @@ impl Lint for RequiredLabels {
}
}

fn pod(&self, pod: &Object<PodSpec, PodStatus>, reporter: &dyn Reporter) {
fn v1_pod(&self, pod: &Object<PodSpec, PodStatus>) -> Vec<Finding> {
let mut findings = Vec::new();

let current_labels: Vec<String> = pod.metadata
.labels
.keys()
Expand All @@ -54,8 +56,10 @@ impl Lint for RequiredLabels {
let finding = Finding::new(self.spec().clone(), pod.metadata.clone())
.with_metadata(metadata);

reporter.report(finding);
findings.push(finding);
}

findings
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/linters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ pub struct LintCollection;

impl LintCollection {
pub fn all<'a>(cfg: Config, object_repository: &'a Box<dyn NewObjectRepository>) -> LintList<'a> {
// let required = linters::lints::required_labels::RequiredLabels::new(cfg.required_labels.clone());
let required = linters::lints::required_labels::RequiredLabels::new(cfg.required_labels.clone());
//let overlapping = linters::lints::overlapping_probes::OverlappingProbes::default();
//let never = linters::lints::never_restart_with_liveness_probe::NeverRestartWithLivenessProbe::default();
//let service_labels = linters::lints::service_without_matching_labels::ServiceWithoutMatchingLabels::new(&object_repository);
let passwords = linters::lints::environment_passwords::EnvironmentPasswords::new(cfg.environment_passwords.clone());
//let pdb_min = linters::lints::pdb_min_replicas::PdbMinReplicas::new(object_repository);

vec![
// Box::new(required),
Box::new(required),
// Box::new(overlapping),
//Box::new(never),
//Box::new(service_labels),
Expand Down

0 comments on commit 349f4f9

Please sign in to comment.