@@ -178,7 +178,7 @@ func main() {
178178 exitOnError (setupProbeEndpoints (mgr , cfg , certsReady ), "unable to set up health check" )
179179
180180 setupLog .Info ("setting up RayCluster controller" )
181- exitOnError ( waitForRayClusterAPIandSetupController (ctx , mgr , cfg , isOpenShift (ctx , kubeClient .DiscoveryClient ), certsReady ), "unable to setup RayCluster controller" )
181+ go waitForRayClusterAPIandSetupController (ctx , mgr , cfg , isOpenShift (ctx , kubeClient .DiscoveryClient ), certsReady )
182182
183183 setupLog .Info ("starting manager" )
184184 exitOnError (mgr .Start (ctx ), "error running manager" )
@@ -205,19 +205,17 @@ func setupRayClusterController(mgr ctrl.Manager, cfg *config.CodeFlareOperatorCo
205205
206206// +kubebuilder:rbac:groups="apiextensions.k8s.io",resources=customresourcedefinitions,verbs=get;list;watch
207207
208- func waitForRayClusterAPIandSetupController (ctx context.Context , mgr ctrl.Manager , cfg * config.CodeFlareOperatorConfiguration , isOpenShift bool , certsReady chan struct {}) error {
208+ func waitForRayClusterAPIandSetupController (ctx context.Context , mgr ctrl.Manager , cfg * config.CodeFlareOperatorConfiguration , isOpenShift bool , certsReady chan struct {}) {
209209 crdClient , err := apiextensionsclientset .NewForConfig (mgr .GetConfig ())
210- if err != nil {
211- return err
212- }
210+ exitOnError (err , "unable to create CRD client" )
211+
213212 crdList , err := crdClient .ApiextensionsV1 ().CustomResourceDefinitions ().List (ctx , metav1.ListOptions {})
214- if err != nil {
215- return err
216- }
213+ exitOnError (err , "unable to list CRDs" )
214+
217215 if slices .ContainsFunc (crdList .Items , func (crd apiextensionsv1.CustomResourceDefinition ) bool {
218216 return crd .Name == "rayclusters.ray.io"
219217 }) {
220- return setupRayClusterController (mgr , cfg , isOpenShift , certsReady )
218+ exitOnError ( setupRayClusterController (mgr , cfg , isOpenShift , certsReady ), "unable to setup RayCluster controller" )
221219 }
222220
223221 retryWatcher , err := retrywatch .NewRetryWatcher (crdList .ResourceVersion , & cache.ListWatch {
@@ -228,31 +226,25 @@ func waitForRayClusterAPIandSetupController(ctx context.Context, mgr ctrl.Manage
228226 return crdClient .ApiextensionsV1 ().CustomResourceDefinitions ().Watch (ctx , metav1.ListOptions {})
229227 },
230228 })
231- if err != nil {
232- return err
233- }
229+ exitOnError (err , "unable to create retry watcher" )
234230
235- go func () {
236- defer retryWatcher .Stop ()
237- for {
238- select {
239- case <- ctx .Done ():
231+ defer retryWatcher .Stop ()
232+ for {
233+ select {
234+ case <- ctx .Done ():
235+ return
236+ case event := <- retryWatcher .ResultChan ():
237+ switch event .Type {
238+ case watch .Error :
239+ exitOnError (apierrors .FromObject (event .Object ), "error watching for RayCluster API" )
240+
241+ case watch .Added :
242+ setupLog .Info ("RayCluster API installed, setting up controller" )
243+ exitOnError (setupRayClusterController (mgr , cfg , isOpenShift , certsReady ), "unable to setup RayCluster controller" )
240244 return
241- case event := <- retryWatcher .ResultChan ():
242- switch event .Type {
243- case watch .Error :
244- exitOnError (apierrors .FromObject (event .Object ), "error watching for RayCluster API" )
245-
246- case watch .Added :
247- setupLog .Info ("RayCluster API installed, setting up controller" )
248- exitOnError (setupRayClusterController (mgr , cfg , isOpenShift , certsReady ), "unable to setup RayCluster controller" )
249- return
250- }
251245 }
252246 }
253- }()
254-
255- return nil
247+ }
256248}
257249
258250// +kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch;update
0 commit comments