Skip to content

Commit 3b2b156

Browse files
committed
fix: Delay controller startup to avoid 404 in initial list
1 parent b43207d commit 3b2b156

3 files changed

Lines changed: 46 additions & 23 deletions

File tree

rust/operator-binary/src/main.rs

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -107,35 +107,48 @@ async fn main() -> anyhow::Result<()> {
107107
.await?;
108108

109109
let (ctx, cm_store_tx, secret_store_tx) = create_context(client.clone());
110-
let sts_restart_controller = restart_controller::statefulset::start(
111-
ctx.clone(),
112-
cm_store_tx,
113-
secret_store_tx,
114-
&watch_namespace,
115-
sigterm_watcher.handle(),
116-
)
117-
.map(anyhow::Ok);
118110

119-
let pod_restart_controller =
120-
restart_controller::pod::start(&client, &watch_namespace, sigterm_watcher.handle())
121-
.map(anyhow::Ok);
122-
123-
let webhook_server = create_webhook_server(
124-
ctx,
111+
let (webhook_server, initial_reconcile_rx) = create_webhook_server(
112+
ctx.clone(),
125113
&operator_environment,
126114
disable_restarter_mutating_webhook,
127115
maintenance.disable_crd_maintenance,
128116
client.as_kube_client(),
129117
)
130118
.await?;
131119

120+
// Multiply initial reconcile signal for the STS and pod restart controllers.
121+
let initial_reconcile_signal = SignalWatcher::new(initial_reconcile_rx.map(|_| ()));
122+
123+
let delayed_sts_restart_controller = async {
124+
initial_reconcile_signal.handle().await;
125+
126+
restart_controller::statefulset::start(
127+
ctx,
128+
cm_store_tx,
129+
secret_store_tx,
130+
&watch_namespace,
131+
sigterm_watcher.handle(),
132+
)
133+
.await
134+
}
135+
.map(anyhow::Ok);
136+
137+
let delayed_pod_restart_controller = async {
138+
initial_reconcile_signal.handle().await;
139+
140+
restart_controller::pod::start(&client, &watch_namespace, sigterm_watcher.handle())
141+
.await
142+
}
143+
.map(anyhow::Ok);
144+
132145
let webhook_server = webhook_server
133146
.run(sigterm_watcher.handle())
134147
.map_err(|err| anyhow!(err).context("failed to run webhook"));
135148

136149
futures::try_join!(
137-
sts_restart_controller,
138-
pod_restart_controller,
150+
delayed_sts_restart_controller,
151+
delayed_pod_restart_controller,
139152
webhook_server,
140153
eos_checker,
141154
)?;

rust/operator-binary/src/webhooks/conversion.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ use stackable_operator::{
66
kube::Client,
77
webhook::webhooks::{ConversionWebhook, ConversionWebhookOptions, Webhook},
88
};
9+
use tokio::sync::oneshot;
910

1011
use crate::FIELD_MANAGER;
1112

12-
pub fn create_webhook(disable_crd_maintenance: bool, client: Client) -> Box<impl Webhook> {
13+
pub fn create_webhook(
14+
disable_crd_maintenance: bool,
15+
client: Client,
16+
) -> (Box<impl Webhook>, oneshot::Receiver<()>) {
1317
let crds_and_handlers = vec![
1418
(
1519
AuthenticationClass::merged_crd(AuthenticationClassVersion::V1Alpha1).unwrap(),
@@ -30,8 +34,8 @@ pub fn create_webhook(disable_crd_maintenance: bool, client: Client) -> Box<impl
3034
field_manager: FIELD_MANAGER.to_owned(),
3135
};
3236

33-
let (conversion_webhook, _initial_reconcile_rx) =
37+
let (conversion_webhook, initial_reconcile_rx) =
3438
ConversionWebhook::new(crds_and_handlers, client, conversion_webhook_options);
3539

36-
Box::new(conversion_webhook)
40+
(Box::new(conversion_webhook), initial_reconcile_rx)
3741
}

rust/operator-binary/src/webhooks/mod.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use stackable_operator::{
66
kube::Client,
77
webhook::{WebhookServer, WebhookServerError, WebhookServerOptions, webhooks::Webhook},
88
};
9+
use tokio::sync::oneshot;
910

1011
use crate::restart_controller::statefulset::Ctx;
1112

@@ -24,7 +25,7 @@ pub async fn create_webhook_server(
2425
disable_restarter_mutating_webhook: bool,
2526
disable_crd_maintenance: bool,
2627
client: Client,
27-
) -> Result<WebhookServer, Error> {
28+
) -> Result<(WebhookServer, oneshot::Receiver<()>), Error> {
2829
let mut webhooks: Vec<Box<dyn Webhook>> = vec![];
2930

3031
if let Some(webhook) = restarter_mutate_sts::create_webhook(
@@ -37,14 +38,19 @@ pub async fn create_webhook_server(
3738

3839
// TODO (@Techassi): The conversion webhook should also allow to be disabled, rework the
3940
// granularity of these options.
40-
webhooks.push(conversion::create_webhook(disable_crd_maintenance, client));
41+
let (webhook, initial_reconcile_rx) =
42+
conversion::create_webhook(disable_crd_maintenance, client);
43+
webhooks.push(webhook);
4144

4245
let webhook_options = WebhookServerOptions {
4346
socket_addr: WebhookServer::DEFAULT_SOCKET_ADDRESS,
4447
webhook_namespace: operator_environment.operator_namespace.to_owned(),
4548
webhook_service_name: operator_environment.operator_service_name.to_owned(),
4649
};
47-
WebhookServer::new(webhooks, webhook_options)
50+
51+
let webhook_server = WebhookServer::new(webhooks, webhook_options)
4852
.await
49-
.context(CreateWebhookServerSnafu)
53+
.context(CreateWebhookServerSnafu)?;
54+
55+
Ok((webhook_server, initial_reconcile_rx))
5056
}

0 commit comments

Comments
 (0)