@@ -24,6 +24,7 @@ import (
24
24
providertypes "github.com/openfaas/faas-provider/types"
25
25
kubeinformers "k8s.io/client-go/informers"
26
26
"k8s.io/client-go/kubernetes"
27
+ "k8s.io/client-go/tools/cache"
27
28
"k8s.io/client-go/tools/clientcmd"
28
29
glog "k8s.io/klog"
29
30
@@ -158,14 +159,22 @@ func runController(setup serverSetup) {
158
159
deploymentLister := kubeInformerFactory .Apps ().V1 ().
159
160
Deployments ().Lister ()
160
161
161
- log .Println ("Waiting for openfaas CRD cache sync" )
162
- faasInformerFactory .WaitForCacheSync (stopCh )
163
- setup .profileInformerFactory .WaitForCacheSync (stopCh )
164
- log .Println ("Cache sync complete" )
165
162
go faasInformerFactory .Start (stopCh )
166
163
go kubeInformerFactory .Start (stopCh )
167
164
go setup .profileInformerFactory .Start (stopCh )
168
165
166
+ // Any "Wait" calls need to be made, after the informers have been started
167
+ start := time .Now ()
168
+ glog .Infof ("Waiting for cache sync in main" )
169
+ kubeInformerFactory .WaitForCacheSync (stopCh )
170
+ setup .profileInformerFactory .WaitForCacheSync (stopCh )
171
+
172
+ // Block and wait for the endpoints to become synchronised
173
+ cache .WaitForCacheSync (stopCh , endpointsInformer .Informer ().HasSynced )
174
+
175
+ glog .Infof ("Cache sync done in: %fs" , time .Since (start ).Seconds ())
176
+ glog .Infof ("Endpoints synced? %v" , endpointsInformer .Informer ().HasSynced ())
177
+
169
178
lister := endpointsInformer .Lister ()
170
179
functionLookup := k8s .NewFunctionLookup (config .DefaultFunctionNamespace , lister )
171
180
@@ -208,11 +217,6 @@ func runOperator(setup serverSetup, cfg config.BootstrapConfig) {
208
217
endpointsInformer := kubeInformerFactory .Core ().V1 ().Endpoints ()
209
218
deploymentInformer := kubeInformerFactory .Apps ().V1 ().Deployments ()
210
219
211
- glog .Infof ("Waiting for cache sync in main" )
212
- kubeInformerFactory .WaitForCacheSync (stopCh )
213
- setup .profileInformerFactory .WaitForCacheSync (stopCh )
214
- glog .Infof ("Cache sync done" )
215
-
216
220
ctrl := controller .NewController (
217
221
kubeClient ,
218
222
faasClient ,
@@ -227,6 +231,18 @@ func runOperator(setup serverSetup, cfg config.BootstrapConfig) {
227
231
go kubeInformerFactory .Start (stopCh )
228
232
go setup .profileInformerFactory .Start (stopCh )
229
233
234
+ // Any "Wait" calls need to be made, after the informers have been started
235
+ start := time .Now ()
236
+ glog .Infof ("Waiting for cache sync in main" )
237
+ kubeInformerFactory .WaitForCacheSync (stopCh )
238
+ setup .profileInformerFactory .WaitForCacheSync (stopCh )
239
+
240
+ // Block and wait for the endpoints to become synchronised
241
+ cache .WaitForCacheSync (stopCh , endpointsInformer .Informer ().HasSynced )
242
+
243
+ glog .Infof ("Cache sync done in: %fs" , time .Since (start ).Seconds ())
244
+ glog .Infof ("Endpoints synced? %v" , endpointsInformer .Informer ().HasSynced ())
245
+
230
246
go srv .Start ()
231
247
if err := ctrl .Run (1 , stopCh ); err != nil {
232
248
glog .Fatalf ("Error running controller: %s" , err .Error ())
0 commit comments