Skip to content

Commit d3a783b

Browse files
committed
clippy fixes
1 parent 86d9da6 commit d3a783b

4 files changed

Lines changed: 15 additions & 21 deletions

File tree

src/bin/gen-crds.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ fn main() {
55
let replica_crd = serde_json::to_value(PostgresPhysicalReplica::crd()).unwrap();
66
let restore_crd = serde_json::to_value(PostgresPhysicalRestore::crd()).unwrap();
77

8-
let docs = vec![replica_crd, restore_crd];
8+
let docs = [replica_crd, restore_crd];
99
for (i, doc) in docs.iter().enumerate() {
1010
if i > 0 {
11-
print!("---\n");
11+
println!("---");
1212
}
1313
print!("{}", serde_yaml::to_string(doc).unwrap());
1414
}

src/controllers/replica.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -222,16 +222,16 @@ pub async fn reconcile(replica: Arc<PostgresPhysicalReplica>, ctx: Arc<Context>)
222222
&ctx.http_client,
223223
&namespace,
224224
&replica,
225-
&switching,
225+
switching,
226226
&conn_info,
227227
&creds_secret_name,
228228
&ctx.metrics,
229229
)
230230
.await;
231231

232232
// Recompute next scheduled restore in case schedule changed while restore was in flight
233-
if let Some(schedule) = &replica.spec.schedule {
234-
if let Some(next) = compute_next_scheduled_restore(schedule) {
233+
if let Some(schedule) = &replica.spec.schedule
234+
&& let Some(next) = compute_next_scheduled_restore(schedule) {
235235
update_replica_status_field(
236236
client,
237237
&namespace,
@@ -241,7 +241,6 @@ pub async fn reconcile(replica: Arc<PostgresPhysicalReplica>, ctx: Arc<Context>)
241241
)
242242
.await?;
243243
}
244-
}
245244

246245
return Ok(Action::requeue(Duration::from_secs(10)));
247246
}
@@ -413,8 +412,8 @@ pub async fn reconcile(replica: Arc<PostgresPhysicalReplica>, ctx: Arc<Context>)
413412

414413
// Whether a restore was created or skipped, advance nextScheduledRestore
415414
// so we don't re-trigger on the next reconciliation.
416-
if let Some(schedule) = &replica.spec.schedule {
417-
if let Some(next) = compute_next_scheduled_restore(schedule) {
415+
if let Some(schedule) = &replica.spec.schedule
416+
&& let Some(next) = compute_next_scheduled_restore(schedule) {
418417
update_replica_status_field(
419418
client,
420419
&namespace,
@@ -424,7 +423,6 @@ pub async fn reconcile(replica: Arc<PostgresPhysicalReplica>, ctx: Arc<Context>)
424423
)
425424
.await?;
426425
}
427-
}
428426
}
429427

430428
// Update phase based on current state
@@ -693,16 +691,15 @@ fn should_trigger_scheduled_restore(replica: &PostgresPhysicalReplica) -> bool {
693691
let status = replica.status.as_ref();
694692

695693
// Check minimumTTL
696-
if let Some(last_completed) = status.and_then(|s| s.last_restore_completed_at.as_ref()) {
697-
if let Ok(last_completed) = last_completed.parse::<chrono::DateTime<Utc>>() {
694+
if let Some(last_completed) = status.and_then(|s| s.last_restore_completed_at.as_ref())
695+
&& let Ok(last_completed) = last_completed.parse::<chrono::DateTime<Utc>>() {
698696
let minimum_ttl =
699697
parse_duration(&replica.spec.minimum_ttl).unwrap_or(Duration::from_secs(6 * 3600));
700698
let elapsed = Utc::now().signed_duration_since(last_completed);
701699
if elapsed.to_std().unwrap_or_default() < minimum_ttl {
702700
return false;
703701
}
704702
}
705-
}
706703

707704
// Check cron schedule
708705
let Ok(cron_schedule) = schedule.parse::<cron::Schedule>() else {
@@ -717,13 +714,12 @@ fn should_trigger_scheduled_restore(replica: &PostgresPhysicalReplica) -> bool {
717714

718715
let now = Utc::now();
719716

720-
if let Some(next_scheduled) = status.and_then(|s| s.next_scheduled_restore.as_ref()) {
721-
if let Ok(next) = next_scheduled.parse::<chrono::DateTime<Utc>>() {
717+
if let Some(next_scheduled) = status.and_then(|s| s.next_scheduled_restore.as_ref())
718+
&& let Ok(next) = next_scheduled.parse::<chrono::DateTime<Utc>>() {
722719
// Add jitter to the scheduled time
723720
let trigger_at = next + chrono::Duration::from_std(jitter).unwrap_or_default();
724721
return now >= trigger_at;
725722
}
726-
}
727723

728724
// Initial seed: nextScheduledRestore not yet set (first reconciliation or field was cleared).
729725
// Fall back to checking whether a cron occurrence falls within a 24h lookback window.

src/controllers/restore.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ async fn reconcile_ready(
349349
}
350350

351351
// Check for timeout (10 minutes)
352-
if let Some(created_at) = restore.status.as_ref().and_then(|s| s.restored_at.as_ref()) {
353-
if let Ok(created) = created_at.parse::<chrono::DateTime<Utc>>() {
352+
if let Some(created_at) = restore.status.as_ref().and_then(|s| s.restored_at.as_ref())
353+
&& let Ok(created) = created_at.parse::<chrono::DateTime<Utc>>() {
354354
let elapsed = Utc::now().signed_duration_since(created);
355355
if elapsed > chrono::Duration::minutes(10) {
356356
warn!(
@@ -383,7 +383,6 @@ async fn reconcile_ready(
383383
return Ok(Action::requeue(Duration::from_secs(300)));
384384
}
385385
}
386-
}
387386

388387
return Ok(Action::requeue(Duration::from_secs(10)));
389388
}

src/kopia.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,10 @@ pub fn filter_snapshots(snapshots: &[Snapshot], filter: Option<&SnapshotFilter>)
110110
}
111111

112112
// Host pattern filtering
113-
if let Some(pattern) = &filter.host_pattern {
114-
if !glob_matches(pattern, &snap.hostname) {
113+
if let Some(pattern) = &filter.host_pattern
114+
&& !glob_matches(pattern, &snap.hostname) {
115115
return false;
116116
}
117-
}
118117

119118
true
120119
})

0 commit comments

Comments
 (0)