@@ -11,6 +11,7 @@ use stackable_operator::{
1111 core:: v1:: { ConfigMap , Service } ,
1212 } ,
1313 kube:: {
14+ core:: DeserializeGuard ,
1415 runtime:: { reflector:: ObjectRef , watcher, Controller } ,
1516 ResourceExt ,
1617 } ,
@@ -86,28 +87,28 @@ async fn main() -> anyhow::Result<()> {
8687 . await ?;
8788
8889 let superset_controller_builder = Controller :: new (
89- watch_namespace. get_api :: < SupersetCluster > ( & client) ,
90+ watch_namespace. get_api :: < DeserializeGuard < SupersetCluster > > ( & client) ,
9091 watcher:: Config :: default ( ) ,
9192 ) ;
9293 let superset_store_1 = superset_controller_builder. store ( ) ;
9394 let superset_controller = superset_controller_builder
9495 . owns (
95- watch_namespace. get_api :: < Service > ( & client) ,
96+ watch_namespace. get_api :: < DeserializeGuard < Service > > ( & client) ,
9697 watcher:: Config :: default ( ) ,
9798 )
9899 . owns (
99- watch_namespace. get_api :: < StatefulSet > ( & client) ,
100+ watch_namespace. get_api :: < DeserializeGuard < StatefulSet > > ( & client) ,
100101 watcher:: Config :: default ( ) ,
101102 )
102103 . shutdown_on_signal ( )
103104 . watches (
104- client. get_api :: < AuthenticationClass > ( & ( ) ) ,
105+ client. get_api :: < DeserializeGuard < AuthenticationClass > > ( & ( ) ) ,
105106 watcher:: Config :: default ( ) ,
106107 move |authentication_class| {
107108 superset_store_1
108109 . state ( )
109110 . into_iter ( )
110- . filter ( move |superset : & Arc < SupersetCluster > | {
111+ . filter ( move |superset| {
111112 references_authentication_class ( superset, & authentication_class)
112113 } )
113114 . map ( |superset| ObjectRef :: from_obj ( & * superset) )
@@ -130,7 +131,7 @@ async fn main() -> anyhow::Result<()> {
130131 } ) ;
131132
132133 let druid_connection_controller_builder = Controller :: new (
133- watch_namespace. get_api :: < DruidConnection > ( & client) ,
134+ watch_namespace. get_api :: < DeserializeGuard < DruidConnection > > ( & client) ,
134135 watcher:: Config :: default ( ) ,
135136 ) ;
136137 let druid_connection_store_1 = druid_connection_controller_builder. store ( ) ;
@@ -139,46 +140,38 @@ async fn main() -> anyhow::Result<()> {
139140 let druid_connection_controller = druid_connection_controller_builder
140141 . shutdown_on_signal ( )
141142 . watches (
142- watch_namespace. get_api :: < SupersetCluster > ( & client) ,
143+ watch_namespace. get_api :: < DeserializeGuard < SupersetCluster > > ( & client) ,
143144 watcher:: Config :: default ( ) ,
144145 move |superset_cluster| {
145146 druid_connection_store_1
146147 . state ( )
147148 . into_iter ( )
148149 . filter ( move |druid_connection| {
149- druid_connection. superset_name ( ) == superset_cluster. name_any ( )
150- && druid_connection. superset_namespace ( ) . ok ( )
151- == superset_cluster. namespace ( )
150+ valid_druid_connection ( & superset_cluster, druid_connection)
152151 } )
153152 . map ( |druid_connection| ObjectRef :: from_obj ( & * druid_connection) )
154153 } ,
155154 )
156155 . watches (
157- watch_namespace. get_api :: < Job > ( & client) ,
156+ watch_namespace. get_api :: < DeserializeGuard < Job > > ( & client) ,
158157 watcher:: Config :: default ( ) ,
159158 move |job| {
160159 druid_connection_store_2
161160 . state ( )
162161 . into_iter ( )
163- . filter ( move |druid_connection| {
164- druid_connection. metadata . namespace == job. metadata . namespace
165- && Some ( druid_connection. job_name ( ) ) == job. metadata . name
166- } )
162+ . filter ( move |druid_connection| valid_druid_job ( druid_connection, & job) )
167163 . map ( |druid_connection| ObjectRef :: from_obj ( & * druid_connection) )
168164 } ,
169165 )
170166 . watches (
171- watch_namespace. get_api :: < ConfigMap > ( & client) ,
167+ watch_namespace. get_api :: < DeserializeGuard < ConfigMap > > ( & client) ,
172168 watcher:: Config :: default ( ) ,
173169 move |config_map| {
174170 druid_connection_store_3
175171 . state ( )
176172 . into_iter ( )
177173 . filter ( move |druid_connection| {
178- druid_connection. druid_namespace ( ) . ok ( )
179- == config_map. metadata . namespace
180- && Some ( druid_connection. druid_name ( ) )
181- == config_map. metadata . name
174+ valid_druid_connection_namespace ( druid_connection, & config_map)
182175 } )
183176 . map ( |druid_connection| ObjectRef :: from_obj ( & * druid_connection) )
184177 } ,
@@ -208,9 +201,13 @@ async fn main() -> anyhow::Result<()> {
208201}
209202
210203fn references_authentication_class (
211- superset : & SupersetCluster ,
212- authentication_class : & AuthenticationClass ,
204+ superset : & DeserializeGuard < SupersetCluster > ,
205+ authentication_class : & DeserializeGuard < AuthenticationClass > ,
213206) -> bool {
207+ let Ok ( superset) = & superset. 0 else {
208+ return false ;
209+ } ;
210+
214211 let authentication_class_name = authentication_class. name_any ( ) ;
215212 superset
216213 . spec
@@ -219,3 +216,36 @@ fn references_authentication_class(
219216 . iter ( )
220217 . any ( |c| c. common . authentication_class_name ( ) == & authentication_class_name)
221218}
219+
220+ fn valid_druid_connection (
221+ superset_cluster : & DeserializeGuard < SupersetCluster > ,
222+ druid_connection : & DeserializeGuard < DruidConnection > ,
223+ ) -> bool {
224+ let Ok ( druid_connection) = & druid_connection. 0 else {
225+ return false ;
226+ } ;
227+ druid_connection. superset_name ( ) == superset_cluster. name_any ( )
228+ && druid_connection. superset_namespace ( ) . ok ( ) == superset_cluster. namespace ( )
229+ }
230+
231+ fn valid_druid_connection_namespace (
232+ druid_connection : & DeserializeGuard < DruidConnection > ,
233+ config_map : & DeserializeGuard < ConfigMap > ,
234+ ) -> bool {
235+ let Ok ( druid_connection) = & druid_connection. 0 else {
236+ return false ;
237+ } ;
238+ druid_connection. druid_namespace ( ) . ok ( ) == config_map. meta ( ) . namespace
239+ && Some ( druid_connection. druid_name ( ) ) == config_map. meta ( ) . name
240+ }
241+
242+ fn valid_druid_job (
243+ druid_connection : & DeserializeGuard < DruidConnection > ,
244+ job : & DeserializeGuard < Job > ,
245+ ) -> bool {
246+ let Ok ( druid_connection) = & druid_connection. 0 else {
247+ return false ;
248+ } ;
249+ druid_connection. metadata . namespace == job. meta ( ) . namespace
250+ && Some ( druid_connection. job_name ( ) ) == job. meta ( ) . name
251+ }
0 commit comments