Skip to content

Commit

Permalink
check if the worktree link changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jrcichra committed Dec 25, 2023
1 parent bb28471 commit c80d2a5
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ use anyhow::{Context, Result};
use clap::Parser;
use kube::{Client, Discovery};
use log::{info, trace};
use std::{path::Path, process, thread, time::Duration};
use std::{
path::{Path, PathBuf},

Check warning on line 6 in src/main.rs

View workflow job for this annotation

GitHub Actions / build

unused import: `PathBuf`

Check warning on line 6 in src/main.rs

View workflow job for this annotation

GitHub Actions / build

unused import: `PathBuf`
process, thread,
time::Duration,
};
use walkdir::WalkDir;
pub mod kubeclient;

Expand Down Expand Up @@ -36,10 +40,6 @@ async fn main() -> Result<()> {
process::exit(0);
})?;

// build client
let client = Client::try_default().await?;
let discovery = Discovery::new(client.clone()).run().await?;

// wait for directory to exist
info!("waiting for path to exist: {}...", &args.path);
while !Path::new(&args.path).exists() {
Expand All @@ -48,7 +48,6 @@ async fn main() -> Result<()> {

let full_run_task = tokio::spawn(async move {
let args = full_run_args;
// TODO: use one client for both threads
// TODO: proper error handling
let client = Client::try_default().await.unwrap();
let discovery = Discovery::new(client.clone()).run().await.unwrap();
Expand Down Expand Up @@ -78,21 +77,21 @@ async fn main() -> Result<()> {

let reconcile_task = tokio::spawn(async move {
let args = reconcile_args;
let mut last_git_content = "".to_string();
// TODO: proper error handling
let client = Client::try_default().await.unwrap();
let discovery = Discovery::new(client.clone()).run().await.unwrap();
let mut last_git_link = tokio::fs::read_link(&args.path).await.unwrap();
loop {
let current_git_contents =
tokio::fs::read_to_string(Path::new(&args.path).join(".git"))
.await
.unwrap();
if current_git_contents != last_git_content {
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 {
Err(e) => {
info!("reconcile error: {:?}", e);
}
Ok(_) => {}
};
}
last_git_content = current_git_contents;
last_git_link = current_git_link;
// check if the file contents match every second
tokio::time::sleep(Duration::from_secs(1)).await;
}
Expand Down

0 comments on commit c80d2a5

Please sign in to comment.