@@ -7,7 +7,7 @@ use clap::Parser as _;
77use crd:: { OpenSearchCluster , OpenSearchClusterVersion , v1alpha1} ;
88use framework:: types:: operator:: OperatorName ;
99use futures:: { FutureExt , StreamExt } ;
10- use snafu:: { ResultExt as _, Snafu } ;
10+ use snafu:: { ResultExt as _, Snafu , futures :: TryFutureExt } ;
1111use 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} ;
3536use 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