Skip to content

Commit

Permalink
split out path for top of git repo and subpath for applying files
Browse files Browse the repository at this point in the history
  • Loading branch information
jrcichra committed Dec 25, 2023
1 parent c80d2a5 commit a5ec346
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ Usage: kapplier [OPTIONS]
Options:
--user-agent <USER_AGENT> [default: kapplier]
--path <PATH> [default: content]
--path <PATH> [default: repo]
--subpath <SUBPATH> [default: dist]
--ignore-hidden-directories
--supported-extensions <SUPPORTED_EXTENSIONS> [default: yml yaml]
--full-run-interval-seconds <FULL_RUN_INTERVAL_SECONDS> [default: 300]
Expand Down
29 changes: 17 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ use anyhow::{Context, Result};
use clap::Parser;
use kube::{Client, Discovery};
use log::{info, trace};
use std::{
path::{Path, PathBuf},
process, thread,
time::Duration,
};
use std::{path::Path, process, thread, time::Duration};
use walkdir::WalkDir;
pub mod kubeclient;

Expand All @@ -15,8 +11,10 @@ pub mod kubeclient;
struct Args {
#[clap(long, default_value = "kapplier")]
user_agent: String,
#[clap(long, default_value = "content")]
#[clap(long, default_value = "repo")]
path: String,
#[clap(long, default_value = "dist")]
subpath: String,
#[clap(long, default_value = "true")]
ignore_hidden_directories: bool,
#[clap(long, default_values = ["yml", "yaml"])]
Expand All @@ -32,6 +30,7 @@ async fn main() -> Result<()> {
let args = Args::parse();
let full_run_args = args.clone();
let reconcile_args: Args = args.clone();
let full_path = format!("{}/{}", &args.path, &args.subpath);

// handle control c
ctrlc::set_handler(move || {
Expand All @@ -41,19 +40,20 @@ async fn main() -> Result<()> {
})?;

// wait for directory to exist
info!("waiting for path to exist: {}...", &args.path);
while !Path::new(&args.path).exists() {
info!("waiting for path to exist: {}...", &full_path);
while !Path::new(&full_path).exists() {
thread::sleep(Duration::from_secs(1));
}

let full_path_clone = full_path.clone();
let full_run_task = tokio::spawn(async move {
let args = full_run_args;
// TODO: proper error handling
let client = Client::try_default().await.unwrap();
let discovery = Discovery::new(client.clone()).run().await.unwrap();
loop {
info!("starting full run");
let walker = WalkDir::new(&args.path).into_iter();
let walker = WalkDir::new(&full_path_clone).into_iter();
// go through all files in the path
for entry in walker {
let entry = entry.unwrap();
Expand Down Expand Up @@ -84,7 +84,7 @@ async fn main() -> Result<()> {
loop {
let current_git_link = tokio::fs::read_link(&args.path).await.unwrap();
if last_git_link != current_git_link {
match reconcile(&args, &client, &discovery).await {
match reconcile(&args, &full_path, &client, &discovery).await {
Err(e) => {
info!("reconcile error: {:?}", e);
}
Expand All @@ -104,8 +104,13 @@ async fn main() -> Result<()> {
Ok(())
}

async fn reconcile(args: &Args, client: &Client, discovery: &Discovery) -> Result<()> {
let walker = WalkDir::new(&args.path).into_iter();
async fn reconcile(
args: &Args,
full_path: &str,
client: &Client,
discovery: &Discovery,
) -> Result<()> {
let walker = WalkDir::new(full_path).into_iter();
for path in walker {
let path = path.context("could not unwrap path")?;
if should_be_applied(path.path(), args) {
Expand Down

0 comments on commit a5ec346

Please sign in to comment.