Skip to content

Commit 2606dac

Browse files
committed
chore: Use delayed controllers
1 parent b3db371 commit 2606dac

File tree

6 files changed

+61
-29
lines changed

6 files changed

+61
-29
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.nix

Lines changed: 24 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ regex = "1.11"
2020
rstest = "0.26"
2121
serde = { version = "1.0", features = ["derive"] }
2222
serde_json = "1.0"
23-
snafu = "0.9"
23+
snafu = { version = "0.9", features = ["futures"] }
2424
strum = { version = "0.28", features = ["derive"] }
2525
tokio = { version = "1.47", features = ["full"] }
2626
tracing = "0.1"

crate-hashes.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deploy/helm/opensearch-operator/templates/roles.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ rules:
8282
{{- if .Values.maintenance.customResourceDefinitions.maintain }}
8383
- create
8484
- patch
85+
# Required for startup condition
86+
- list
87+
- watch
8588
{{- end }}
8689
- apiGroups:
8790
- listeners.stackable.tech

rust/operator-binary/src/main.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use clap::Parser as _;
77
use crd::{OpenSearchCluster, OpenSearchClusterVersion, v1alpha1};
88
use framework::types::operator::OperatorName;
99
use futures::{FutureExt, StreamExt};
10-
use snafu::{ResultExt as _, Snafu};
10+
use snafu::{ResultExt as _, Snafu, futures::TryFutureExt};
1111
use stackable_operator::{
1212
YamlSchema as _,
1313
cli::{Command, RunArguments},
@@ -20,6 +20,7 @@ use stackable_operator::{
2020
rbac::v1::RoleBinding,
2121
},
2222
kube::{
23+
CustomResourceExt as _,
2324
core::DeserializeGuard,
2425
runtime::{
2526
Controller,
@@ -30,7 +31,7 @@ use stackable_operator::{
3031
logging::controller::report_controller_reconciled,
3132
shared::yaml::SerializeOptions,
3233
telemetry::Tracing,
33-
utils::signal::SignalWatcher,
34+
utils::signal::{self, SignalWatcher},
3435
};
3536
use strum::{EnumDiscriminants, IntoStaticStr};
3637

@@ -82,14 +83,16 @@ pub enum Error {
8283
#[snafu(display("failed to create webhook server"))]
8384
CreateWebhook { source: webhooks::conversion::Error },
8485

85-
// No context selector is being generated here so that we can run the webhook
86-
// as is, without the need to map the error to this variant. The ? operator
87-
// used after the futures::try_join function automatically converts the
88-
// underlying error to this variant.
89-
#[snafu(display("failed to run webhook server"), context(false))]
86+
#[snafu(display("failed to run webhook server"))]
9087
RunWebhook {
9188
source: stackable_operator::webhook::WebhookServerError,
9289
},
90+
91+
#[snafu(display("failed to establish if CRD {crd_name:?} is available"))]
92+
EstablishCrd {
93+
crd_name: String,
94+
source: stackable_operator::utils::signal::CrdEstablishedError,
95+
},
9396
}
9497

9598
#[derive(clap::Parser)]
@@ -159,7 +162,9 @@ async fn main() -> Result<()> {
159162
.await
160163
.context(CreateWebhookSnafu)?;
161164

162-
let webhook_server = webhook_server.run(sigterm_watcher.handle());
165+
let webhook_server = webhook_server
166+
.run(sigterm_watcher.handle())
167+
.context(RunWebhookSnafu);
163168

164169
let controller_context = controller::Context::new(client.clone(), operator_name);
165170
let full_controller_name = controller_context.full_controller_name();
@@ -229,7 +234,15 @@ async fn main() -> Result<()> {
229234
)
230235
.map(Ok);
231236

232-
futures::try_join!(controller, eos_checker, webhook_server)?;
237+
let delayed_controller = async {
238+
let crd_name = v1alpha1::OpenSearchCluster::crd_name();
239+
signal::crd_established(&client, crd_name, None)
240+
.await
241+
.context(EstablishCrdSnafu { crd_name })?;
242+
controller.await
243+
};
244+
245+
futures::try_join!(delayed_controller, eos_checker, webhook_server)?;
233246
}
234247
}
235248

0 commit comments

Comments
 (0)