Skip to content

Commit

Permalink
Properly handle files used in configMap generators
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-bergia committed Nov 16, 2022
1 parent 52f98d2 commit ddd3314
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
target = "x86_64-unknown-linux-musl"
86 changes: 77 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
[package]
name = "kree"
version = "0.6.0"
version = "0.7.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "4.0", features = ["derive"] }
env_logger = "0.9.3"
log = "0.4.17"
relative-path = "1.7.2"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.87"
Expand Down
40 changes: 37 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::{
io,
path::PathBuf,
};
use log::debug;


#[derive(Parser)]
Expand All @@ -31,10 +32,19 @@ enum Format {
}


#[derive(Deserialize, PartialEq, Debug)]
#[derive(Default, Deserialize, PartialEq, Debug)]
#[serde(default, rename_all = "camelCase")]
struct Kustomization {
#[serde(default)]
resources: Vec<String>,
config_map_generator: Vec<ConfigMapGenerator>,
}


#[derive(Clone, Default, Deserialize, PartialEq, Debug)]
#[serde(default)]
struct ConfigMapGenerator {
name: String,
files: Vec<String>,
}


Expand Down Expand Up @@ -91,11 +101,33 @@ fn unsupported(resource: &str) -> bool {
}

fn run(path: PathBuf, result: &mut Vec<String>) {
debug!("{:#?}", path.display());

let current_path = normalize(path.clone());
debug!("{:#?}", current_path.display());

result.push(format!("{}", current_path.display()));

let resources: Vec<String> = deserialize(&current_path)
let doc = deserialize(&current_path);
debug!("{:#?}", doc);

doc
.iter()
.map(|doc| doc.config_map_generator.clone())
.flatten()
.map(|c| c.files)
.flatten()
.for_each(|f| {
let file = current_path
.parent()
.unwrap()
.join(f);

result.push(format!("{}", file.display()));
});


let resources: Vec<String> = doc
.iter()
.map(|doc| doc.resources.clone())
.flatten()
Expand All @@ -117,6 +149,8 @@ fn run(path: PathBuf, result: &mut Vec<String>) {


fn main() {
env_logger::init();

let args = Args::parse();
let root = current_dir().unwrap();
let mut result = Vec::new();
Expand Down

0 comments on commit ddd3314

Please sign in to comment.