@@ -18,8 +18,10 @@ package main
1818
1919import (
2020 "context"
21+ "errors"
2122 "flag"
2223 "fmt"
24+ "net/http"
2325 "os"
2426 "strings"
2527 "time"
@@ -153,18 +155,16 @@ func main() {
153155 certsReady := make (chan struct {})
154156 exitOnError (setupCertManagement (mgr , namespace , certsReady ), "unable to setup cert-controller" )
155157
156- OpenShift := isOpenShift (ctx , kubeClient .DiscoveryClient )
158+ go setupControllers ( mgr , kubeClient , cfg , isOpenShift (ctx , kubeClient .DiscoveryClient ), certsReady )
157159
158- go setupControllers (mgr , kubeClient , cfg , OpenShift , certsReady )
159-
160- exitOnError (mgr .AddHealthzCheck (cfg .Health .LivenessEndpointName , healthz .Ping ), "unable to set up health check" )
161- exitOnError (mgr .AddReadyzCheck (cfg .Health .ReadinessEndpointName , healthz .Ping ), "unable to set up ready check" )
160+ setupLog .Info ("setting up health endpoints" )
161+ exitOnError (setupProbeEndpoints (mgr , cfg , certsReady ), "unable to set up health check" )
162162
163163 setupLog .Info ("starting manager" )
164164 exitOnError (mgr .Start (ctx ), "error running manager" )
165165}
166166
167- func setupControllers (mgr ctrl.Manager , dc discovery.DiscoveryInterface , cfg * config.CodeFlareOperatorConfiguration , OpenShift bool , certsReady chan struct {}) {
167+ func setupControllers (mgr ctrl.Manager , dc discovery.DiscoveryInterface , cfg * config.CodeFlareOperatorConfiguration , isOpenShift bool , certsReady chan struct {}) {
168168 setupLog .Info ("Waiting for certificate generation to complete" )
169169 <- certsReady
170170 setupLog .Info ("Certs ready" )
@@ -177,7 +177,7 @@ func setupControllers(mgr ctrl.Manager, dc discovery.DiscoveryInterface, cfg *co
177177 Client : mgr .GetClient (),
178178 Scheme : mgr .GetScheme (),
179179 Config : cfg .KubeRay ,
180- IsOpenShift : OpenShift ,
180+ IsOpenShift : isOpenShift ,
181181 }
182182 exitOnError (rayClusterController .SetupWithManager (mgr ), "Error setting up RayCluster controller" )
183183 } else if err != nil {
@@ -216,6 +216,22 @@ func setupCertManagement(mgr ctrl.Manager, namespace string, certsReady chan str
216216 })
217217}
218218
219+ func setupProbeEndpoints (mgr ctrl.Manager , cfg * config.CodeFlareOperatorConfiguration , certsReady chan struct {}) error {
220+ err := mgr .AddHealthzCheck (cfg .Health .LivenessEndpointName , healthz .Ping )
221+ if err != nil {
222+ return err
223+ }
224+
225+ return mgr .AddReadyzCheck (cfg .Health .ReadinessEndpointName , func (req * http.Request ) error {
226+ select {
227+ case <- certsReady :
228+ return mgr .GetWebhookServer ().StartedChecker ()(req )
229+ default :
230+ return errors .New ("certificates are not ready" )
231+ }
232+ })
233+ }
234+
219235func loadIntoOrCreate (ctx context.Context , client kubernetes.Interface , ns , name string , cfg * config.CodeFlareOperatorConfiguration ) error {
220236 configMap , err := client .CoreV1 ().ConfigMaps (ns ).Get (ctx , name , metav1.GetOptions {})
221237 if apierrors .IsNotFound (err ) {
0 commit comments