Skip to content

Commit ac5b9cb

Browse files
committed
refactor(operator): Adjust oneshot channel handling
1 parent bbf49f5 commit ac5b9cb

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

crates/stackable-operator/src/crd/maintainer.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub struct CustomResourceDefinitionMaintainer {
4141
definitions: Vec<CustomResourceDefinition>,
4242
options: CustomResourceDefinitionMaintainerOptions,
4343

44-
initial_reconcile_tx: Option<oneshot::Sender<()>>,
44+
initial_reconcile_tx: oneshot::Sender<()>,
4545
}
4646

4747
impl CustomResourceDefinitionMaintainer {
@@ -120,7 +120,6 @@ impl CustomResourceDefinitionMaintainer {
120120
options: CustomResourceDefinitionMaintainerOptions,
121121
) -> (Self, oneshot::Receiver<()>) {
122122
let (initial_reconcile_tx, initial_reconcile_rx) = oneshot::channel();
123-
let initial_reconcile_tx = Some(initial_reconcile_tx);
124123

125124
let maintainer = Self {
126125
definitions: definitions.into_iter().collect(),
@@ -153,6 +152,11 @@ impl CustomResourceDefinitionMaintainer {
153152
return Ok(());
154153
}
155154

155+
// This channel can only be used exactly once. The sender's send method consumes self, and
156+
// as such, the sender is wrapped in an Option to be able to call take to consume the inner
157+
// value.
158+
let mut initial_reconcile_tx = Some(self.initial_reconcile_tx);
159+
156160
// This get's polled by the async runtime on a regular basis (or when woken up). Once we
157161
// receive a message containing the newly generated TLS certificate for the conversion
158162
// webhook, we need to update the caBundle in the CRD.
@@ -214,10 +218,8 @@ impl CustomResourceDefinitionMaintainer {
214218
}
215219

216220
// After the reconciliation of the CRDs, the initial reconcile heartbeat is sent out
217-
// via the oneshot channel. This channel can only be used exactly once. The sender's
218-
// send method consumes self, and as such, the sender is wrapped in an Option to be
219-
// able to call take to consume the inner value.
220-
if let Some(initial_reconcile_tx) = self.initial_reconcile_tx.take() {
221+
// via the oneshot channel.
222+
if let Some(initial_reconcile_tx) = initial_reconcile_tx.take() {
221223
match initial_reconcile_tx.send(()) {
222224
Ok(_) => {}
223225
Err(_) => return SendInitialReconcileHeartbeatSnafu.fail(),

0 commit comments

Comments
 (0)