Skip to content

Commit

Permalink
indexers: better loop
Browse files Browse the repository at this point in the history
Signed-off-by: Hank Donnay <[email protected]>
  • Loading branch information
hdonnay committed Oct 10, 2023
1 parent 29c7e50 commit c6a2b5c
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions controller/src/indexers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,8 @@ async fn check_service(
.unwrap();
let api = Api::<core::v1::Service>::default_namespaced(ctx.client.clone());

let mut ct = 0;
while ct < 3 {
ct += 1;
let mut ok = false;
for ct in 0..3 {
trace!(ct, "reconcile attempt");
let mut entry = api
.entry(&name)
Expand All @@ -507,7 +506,10 @@ async fn check_service(

next.add_ref(entry.get());
match entry.commit(&CREATE_PARAMS).await {
Ok(()) => break,
Ok(()) => {
ok = true;
break;
}
Err(err) => {
trace!(error = ?err, "commit error");
match err {
Expand All @@ -519,8 +521,8 @@ async fn check_service(
}
};
}
trace!(ct, "reconciled");
Ok(ct != 3)
trace!("reconciled");
Ok(ok)
}

#[instrument(skip_all)]
Expand Down Expand Up @@ -559,10 +561,9 @@ async fn check_hpa(
let api =
Api::<autoscaling::v2::HorizontalPodAutoscaler>::default_namespaced(ctx.client.clone());

let mut ct = 0;
while ct < 3 {
ct += 1;
trace!(ct, "reconcile attempt");
let mut ok = false;
for n in 0..3 {
trace!(n, "reconcile attempt");
let mut entry = api
.entry(&name)
.await?
Expand All @@ -581,7 +582,10 @@ async fn check_hpa(

next.add_ref(entry.get());
match entry.commit(&CREATE_PARAMS).await {
Ok(()) => break,
Ok(()) => {
ok = true;
break;
}
Err(err) => {
trace!(error = ?err, "commit error");
match err {
Expand All @@ -593,8 +597,8 @@ async fn check_hpa(
}
};
}
trace!(ct, "reconciled");
Ok(ct != 3)
trace!("reconciled");
Ok(ok)
}

#[instrument(skip_all)]
Expand Down

0 comments on commit c6a2b5c

Please sign in to comment.