@@ -18,8 +18,10 @@ package main
18
18
19
19
import (
20
20
"context"
21
+ "errors"
21
22
"flag"
22
23
"fmt"
24
+ "net/http"
23
25
"os"
24
26
"strings"
25
27
"time"
@@ -153,18 +155,16 @@ func main() {
153
155
certsReady := make (chan struct {})
154
156
exitOnError (setupCertManagement (mgr , namespace , certsReady ), "unable to setup cert-controller" )
155
157
156
- OpenShift := isOpenShift (ctx , kubeClient .DiscoveryClient )
158
+ go setupControllers ( mgr , kubeClient , cfg , isOpenShift (ctx , kubeClient .DiscoveryClient ), certsReady )
157
159
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" )
162
162
163
163
setupLog .Info ("starting manager" )
164
164
exitOnError (mgr .Start (ctx ), "error running manager" )
165
165
}
166
166
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 {}) {
168
168
setupLog .Info ("Waiting for certificate generation to complete" )
169
169
<- certsReady
170
170
setupLog .Info ("Certs ready" )
@@ -177,7 +177,7 @@ func setupControllers(mgr ctrl.Manager, dc discovery.DiscoveryInterface, cfg *co
177
177
Client : mgr .GetClient (),
178
178
Scheme : mgr .GetScheme (),
179
179
Config : cfg .KubeRay ,
180
- IsOpenShift : OpenShift ,
180
+ IsOpenShift : isOpenShift ,
181
181
}
182
182
exitOnError (rayClusterController .SetupWithManager (mgr ), "Error setting up RayCluster controller" )
183
183
} else if err != nil {
@@ -216,6 +216,22 @@ func setupCertManagement(mgr ctrl.Manager, namespace string, certsReady chan str
216
216
})
217
217
}
218
218
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
+
219
235
func loadIntoOrCreate (ctx context.Context , client kubernetes.Interface , ns , name string , cfg * config.CodeFlareOperatorConfiguration ) error {
220
236
configMap , err := client .CoreV1 ().ConfigMaps (ns ).Get (ctx , name , metav1.GetOptions {})
221
237
if apierrors .IsNotFound (err ) {
0 commit comments