@@ -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"
@@ -157,18 +159,16 @@ func main() {
157
159
certsReady := make (chan struct {})
158
160
exitOnError (setupCertManagement (mgr , namespace , certsReady ), "unable to setup cert-controller" )
159
161
160
- OpenShift := isOpenShift (ctx , kubeClient .DiscoveryClient )
162
+ go setupControllers ( mgr , kubeClient , cfg , isOpenShift (ctx , kubeClient .DiscoveryClient ), certsReady )
161
163
162
- go setupControllers (mgr , kubeClient , cfg , OpenShift , certsReady )
163
-
164
- exitOnError (mgr .AddHealthzCheck (cfg .Health .LivenessEndpointName , healthz .Ping ), "unable to set up health check" )
165
- exitOnError (mgr .AddReadyzCheck (cfg .Health .ReadinessEndpointName , healthz .Ping ), "unable to set up ready check" )
164
+ setupLog .Info ("setting up health endpoints" )
165
+ exitOnError (setupProbeEndpoints (mgr , cfg , certsReady ), "unable to set up health check" )
166
166
167
167
setupLog .Info ("starting manager" )
168
168
exitOnError (mgr .Start (ctx ), "error running manager" )
169
169
}
170
170
171
- func setupControllers (mgr ctrl.Manager , dc discovery.DiscoveryInterface , cfg * config.CodeFlareOperatorConfiguration , OpenShift bool , certsReady chan struct {}) {
171
+ func setupControllers (mgr ctrl.Manager , dc discovery.DiscoveryInterface , cfg * config.CodeFlareOperatorConfiguration , isOpenShift bool , certsReady chan struct {}) {
172
172
setupLog .Info ("Waiting for certificate generation to complete" )
173
173
<- certsReady
174
174
setupLog .Info ("Certs ready" )
@@ -181,7 +181,7 @@ func setupControllers(mgr ctrl.Manager, dc discovery.DiscoveryInterface, cfg *co
181
181
Client : mgr .GetClient (),
182
182
Scheme : mgr .GetScheme (),
183
183
Config : cfg .KubeRay ,
184
- IsOpenShift : OpenShift ,
184
+ IsOpenShift : isOpenShift ,
185
185
}
186
186
exitOnError (rayClusterController .SetupWithManager (mgr ), "Error setting up RayCluster controller" )
187
187
} else if err != nil {
@@ -220,6 +220,22 @@ func setupCertManagement(mgr ctrl.Manager, namespace string, certsReady chan str
220
220
})
221
221
}
222
222
223
+ func setupProbeEndpoints (mgr ctrl.Manager , cfg * config.CodeFlareOperatorConfiguration , certsReady chan struct {}) error {
224
+ err := mgr .AddHealthzCheck (cfg .Health .LivenessEndpointName , healthz .Ping )
225
+ if err != nil {
226
+ return err
227
+ }
228
+
229
+ return mgr .AddReadyzCheck (cfg .Health .ReadinessEndpointName , func (req * http.Request ) error {
230
+ select {
231
+ case <- certsReady :
232
+ return mgr .GetWebhookServer ().StartedChecker ()(req )
233
+ default :
234
+ return errors .New ("certificates are not ready" )
235
+ }
236
+ })
237
+ }
238
+
223
239
func loadIntoOrCreate (ctx context.Context , client kubernetes.Interface , ns , name string , cfg * config.CodeFlareOperatorConfiguration ) error {
224
240
configMap , err := client .CoreV1 ().ConfigMaps (ns ).Get (ctx , name , metav1.GetOptions {})
225
241
if apierrors .IsNotFound (err ) {
0 commit comments