Skip to content

Commit

Permalink
fix duplicate finalizers race condition (#965)
Browse files Browse the repository at this point in the history
* fix duplicate finalizers race condition

#964

Signed-off-by: Alex Hunt <[email protected]>

* Add comment about why we test finalizers haven't changed

Co-authored-by: Teo Klestrup Röijezon <[email protected]>
Signed-off-by: alex-hunt-materialize <[email protected]>

* just fmt

Signed-off-by: Alex Hunt <[email protected]>

Co-authored-by: Teo Klestrup Röijezon <[email protected]>
  • Loading branch information
alex-hunt-materialize and nightkr authored Jul 28, 2022
1 parent b6cc8f9 commit 3cab178
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions kube-runtime/src/finalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,19 @@ where
}),
]
} else {
vec![PatchOperation::Add(AddOperation {
path: "/metadata/finalizers/-".to_string(),
value: finalizer_name.into(),
})]
vec![
// Kubernetes doesn't automatically deduplicate finalizers (see
// https://github.com/kube-rs/kube-rs/issues/964#issuecomment-1197311254),
// so we need to fail and retry if anyone else has added the finalizer in the meantime
PatchOperation::Test(TestOperation {
path: "/metadata/finalizers".to_string(),
value: obj.finalizers().into(),
}),
PatchOperation::Add(AddOperation {
path: "/metadata/finalizers/-".to_string(),
value: finalizer_name.into(),
}),
]
});
api.patch::<K>(
obj.meta().name.as_deref().ok_or(Error::UnnamedObject)?,
Expand Down

0 comments on commit 3cab178

Please sign in to comment.