@@ -18,6 +18,7 @@ import (
18
18
"context"
19
19
"crypto/tls"
20
20
"fmt"
21
+ "net/http"
21
22
"os"
22
23
23
24
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
@@ -136,13 +137,14 @@ func main() {
136
137
}
137
138
138
139
boostMgr := boost .NewManager (mgr .GetClient ())
139
- go setupControllers (mgr , boostMgr , cfg , podLevelResourcesEnabled , versionInfo , certsReady )
140
-
140
+ controllersReady := make (chan struct {})
141
+ go setupControllers (mgr , boostMgr , cfg , podLevelResourcesEnabled , versionInfo , certsReady ,
142
+ controllersReady )
141
143
if err := mgr .AddHealthzCheck ("healthz" , healthz .Ping ); err != nil {
142
144
setupLog .Error (err , "unable to set up health check" )
143
145
os .Exit (1 )
144
146
}
145
- if err := mgr . AddReadyzCheck ( "readyz" , healthz . Ping ); err != nil {
147
+ if err := setupReadyzCheck ( mgr , boostMgr , controllersReady ); err != nil {
146
148
setupLog .Error (err , "unable to set up ready check" )
147
149
os .Exit (1 )
148
150
}
@@ -157,7 +159,9 @@ func main() {
157
159
}
158
160
159
161
func setupControllers (mgr ctrl.Manager , boostMgr boost.Manager , cfg * config.Config ,
160
- podLevelResourcesEnabled bool , serverVersion * version.Info , certsReady chan struct {}) {
162
+ podLevelResourcesEnabled bool , serverVersion * version.Info , certsReady chan struct {},
163
+ controllersReady chan struct {}) {
164
+ defer close (controllersReady )
161
165
setupLog .Info ("Waiting for certificate generation to complete" )
162
166
<- certsReady
163
167
setupLog .Info ("Certificate generation has completed" )
@@ -183,6 +187,29 @@ func setupControllers(mgr ctrl.Manager, boostMgr boost.Manager, cfg *config.Conf
183
187
//+kubebuilder:scaffold:builder
184
188
}
185
189
190
+ func setupReadyzCheck (mgr ctrl.Manager , boostMgr boost.Manager ,
191
+ controllersReadyChan chan struct {}) error {
192
+ if err := mgr .AddReadyzCheck ("readyz" , func (req * http.Request ) error {
193
+ controllersReady := false
194
+ select {
195
+ case <- controllersReadyChan :
196
+ controllersReady = true
197
+ default :
198
+ }
199
+ if ! controllersReady {
200
+ return fmt .Errorf ("controllers are not ready" )
201
+ }
202
+ if ! boostMgr .IsRunning (req .Context ()) {
203
+ return fmt .Errorf ("boost manager is not running" )
204
+ }
205
+ return nil
206
+ }); err != nil {
207
+ setupLog .Error (err , "unable to set up ready check" )
208
+ os .Exit (1 )
209
+ }
210
+ return nil
211
+ }
212
+
186
213
func getFeatureGates (clusterInfo util.ClusterInfo ) (util.FeatureGates , error ) {
187
214
setupLog .Info ("fetching cluster feature gates" )
188
215
return clusterInfo .GetFeatureGates ()
0 commit comments